From 23df933db4d8074d9119c6749db05a334b313ad7 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Mon, 17 Dec 2018 07:58:27 +0100 Subject: [PATCH] Run os.path.expanduser() on all args paths (!1731) Properly replace ~ with $HOME in all paths. Fix tab completion when passing a path starting with ~ to pmaports: $ pmbootstrap --aports ~/src/pmaports/ build linux- --- pmb/helpers/args.py | 16 ++++++++++++---- pmb/parse/arguments.py | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pmb/helpers/args.py b/pmb/helpers/args.py index a7cbd6e4..ea3dd667 100644 --- a/pmb/helpers/args.py +++ b/pmb/helpers/args.py @@ -111,9 +111,12 @@ def check_pmaports_path(args): " not exist: " + args.aports) -def replace_variables(args): - """ Replace $WORK in variables from any config (user's config file, default - config settings or config parameters specified on commandline) """ +def replace_placeholders(args): + """ Replace $WORK and ~ (for path variables) in variables from any config + (user's config file, default config settings or config parameters + specified on commandline) """ + + # Replace $WORK for key, value in pmb.config.defaults.items(): if key not in args: continue @@ -121,6 +124,11 @@ def replace_variables(args): if isinstance(old, str): setattr(args, key, old.replace("$WORK", args.work)) + # Replace ~ (path variables only) + for key in ["aports", "config", "log", "work"]: + if key in args: + setattr(args, key, os.path.expanduser(getattr(args, key))) + def add_shortcuts(args): """ Add convenience shortcuts """ @@ -157,7 +165,7 @@ def init(args): # Basic initialization fix_mirrors_postmarketos(args) pmb.config.merge_with_args(args) - replace_variables(args) + replace_placeholders(args) add_shortcuts(args) add_cache(args) diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index cccb6057..f53c00c6 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -252,7 +252,7 @@ def arguments_repo_missing(subparser): def packagecompleter(prefix, action, parser, parsed_args): args = parsed_args pmb.config.merge_with_args(args) - pmb.helpers.args.replace_variables(args) + pmb.helpers.args.replace_placeholders(args) packages = set(pmb.helpers.pmaports.get_list(args)) return packages