The default path of the telemetry alias file
was at the top level of the home directory.

Load aliases from the DPDK configuration directory instead,
using $XDG_CONFIG_HOME/dpdk/telemetry_aliases
or $HOME/.config/dpdk/telemetry_aliases.

Keep --alias-file for users who want to provide an explicit path.

Fixes: 410d498412e4 ("usertools/telemetry: support aliases for long commands")

Signed-off-by: Thomas Monjalon <[email protected]>
---
 doc/guides/howto/telemetry.rst |  6 ++++--
 usertools/dpdk-telemetry.py    | 23 +++++++++++++++++------
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/doc/guides/howto/telemetry.rst b/doc/guides/howto/telemetry.rst
index b3f25c1113..fdaede1987 100644
--- a/doc/guides/howto/telemetry.rst
+++ b/doc/guides/howto/telemetry.rst
@@ -154,9 +154,11 @@ and query information using the telemetry client python 
script.
 
      The telemetry script can load aliases at startup from::
 
-        $HOME/.dpdk_telemetry_aliases
+        $XDG_CONFIG_HOME/dpdk/telemetry_aliases
+
+     If ``XDG_CONFIG_HOME`` is not set, 
``$HOME/.config/dpdk/telemetry_aliases`` is used.
+     A custom path can also be provided via the ``--alias-file`` script flag.
 
-     or from a custom path provided via the ``--alias-file`` script flag.
      Each alias entry must be in ``alias=command`` format.
      Empty lines and lines starting with ``#`` are ignored.
 
diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index 20627b596b..e575f269cb 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -22,7 +22,7 @@
 DEFAULT_PREFIX = "rte"
 CMDS = []
 ALIASES = {}
-ALIAS_FILE = ".dpdk_telemetry_aliases"
+ALIAS_FILE = "telemetry_aliases"
 MAX_ALIAS_EXPANSIONS = 32
 
 BASIC_HELP_TEXT = """Basic usage:
@@ -46,19 +46,30 @@
 """
 
 
+def get_default_alias_path():
+    config_home = os.environ.get("XDG_CONFIG_HOME")
+    if config_home:
+        return os.path.join(config_home, "dpdk", ALIAS_FILE)
+
+    home = os.environ.get("HOME")
+    if not home:
+        return None
+
+    return os.path.join(home, ".config", "dpdk", ALIAS_FILE)
+
+
 def load_aliases(alias_path=None):
-    """Load aliases from $HOME/.dpdk_telemetry_aliases or a custom path if 
provided"""
+    """Load aliases from the config directory or a custom path if provided"""
     aliases = {}
     if alias_path and not os.path.isfile(alias_path):
         print("Warning: alias file {} not found, skipping".format(alias_path), 
file=sys.stderr)
         return aliases
 
     if not alias_path:
-        home = os.environ.get("HOME")
-        if not home:
+        alias_path = get_default_alias_path()
+        if not alias_path:
             return aliases
 
-        alias_path = os.path.join(home, ALIAS_FILE)
         if not os.path.isfile(alias_path):
             return aliases
 
@@ -434,7 +445,7 @@ def readline_complete(text, state):
 )
 parser.add_argument(
     "--alias-file",
-    help=f"Provide a custom alias file instead of $HOME/{ALIAS_FILE}",
+    help="Provide a custom alias file instead of the default config path",
 )
 parser.add_argument(
     "-i", "--instance", default="0", type=int, help="Provide instance number 
for DPDK application"
-- 
2.54.0

Reply via email to