From fc5cb2e1904fbcae5b70c60dc2ca0e7fb2f9355a Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Thu, 9 Apr 2020 21:22:17 +0200 Subject: [PATCH] pmb.config.pmaports: don't add to args (MR 1912) Do not make the parsed pmaports.cfg from pmaports.git available as args.pmaports anymore. This de-bloats the args variable a bit. First I thought that we didn't even need to cache it, but it was pointed out that later patches do access it frequently to read the current channel from pmaports.cfg. Therefore it is using a cache now. Related: #1879, #1855 --- pmb/config/pmaports.py | 29 ++++++++++++++++++----------- pmb/helpers/args.py | 6 +++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pmb/config/pmaports.py b/pmb/config/pmaports.py index b6aa875f..9ce2350d 100644 --- a/pmb/config/pmaports.py +++ b/pmb/config/pmaports.py @@ -49,9 +49,8 @@ def symlink(args): logging.info("NOTE: pmaports path: " + args.aports) -def check_version_pmaports(args): +def check_version_pmaports(real): # Compare versions - real = args.pmaports["version"] min = pmb.config.pmaports_min_version if pmb.parse.version.compare(real, min) >= 0: return @@ -62,10 +61,9 @@ def check_version_pmaports(args): raise RuntimeError("Run 'pmbootstrap pull' to update your pmaports.") -def check_version_pmbootstrap(args): +def check_version_pmbootstrap(min): # Compare versions real = pmb.config.version - min = args.pmaports["pmbootstrap_min_version"] if pmb.parse.version.compare(real, min) >= 0: return @@ -87,8 +85,13 @@ def check_version_pmbootstrap(args): " of pmbootstrap from git.") -def read_config_into_args(args): - """ Read and verify pmaports.cfg, add the contents to args.pmaports_cfg """ +def read_config(args): + """ Read and verify pmaports.cfg. """ + # Try cache first + cache_key = "pmb.config.pmaports.read_config" + if args.cache[cache_key]: + return args.cache[cache_key] + # Migration message if not os.path.exists(args.aports): raise RuntimeError("We have split the aports repository from the" @@ -101,14 +104,18 @@ def read_config_into_args(args): raise RuntimeError("Invalid pmaports repository, could not find the" " config: " + path_cfg) - # Load the config into args.pmaports + # Load the config cfg = configparser.ConfigParser() cfg.read(path_cfg) - setattr(args, "pmaports", cfg["pmaports"]) + ret = cfg["pmaports"] # Version checks - check_version_pmaports(args) - check_version_pmbootstrap(args) + check_version_pmaports(ret["version"]) + check_version_pmbootstrap(ret["pmbootstrap_min_version"]) + + # Cache and return + args.cache[cache_key] = ret + return ret def init(args): @@ -116,4 +123,4 @@ def init(args): if not os.path.exists(args.aports): clone(args) symlink(args) - read_config_into_args(args) + read_config(args) diff --git a/pmb/helpers/args.py b/pmb/helpers/args.py index 87fc80cf..c4796d22 100644 --- a/pmb/helpers/args.py +++ b/pmb/helpers/args.py @@ -63,7 +63,6 @@ import pmb.helpers.git Examples: args.deviceinfo (e.g. {"name": "Mydevice", "arch": "armhf", ...}) - args.pmaports (e.g. {"version": "1", "branch_alpine": "edge", ...}) """ @@ -133,7 +132,8 @@ def add_cache(args): "pmb.helpers.package.depends_recurse": {}, "pmb.helpers.package.get": {}, "pmb.helpers.repo.update": repo_update, - "pmb.helpers.git.parse_channels_cfg": {}}) + "pmb.helpers.git.parse_channels_cfg": {}, + "pmb.config.pmaports.read_config": None}) def add_deviceinfo(args): @@ -162,7 +162,7 @@ def init(args): check_pmaports_path(args) if args.action not in ["init", "config", "bootimg_analyze", "log", "pull", "shutdown", "zap"]: - pmb.config.pmaports.read_config_into_args(args) + pmb.config.pmaports.read_config(args) add_deviceinfo(args) pmb.helpers.git.parse_channels_cfg(args)