From 9dfa89c58cfe1ec94320d4eb1a81f00d03de4ff9 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sun, 7 Jul 2024 20:48:57 +0200 Subject: [PATCH] Use pmbootstrap_v3.cfg as config file (MR 2350) Using pmbootstrap v3 with the old config can cause problems, for example when having $WORK in the pmaports dir instead of the actual work path. This is not supported anymore by v3 to reduce complexity. The format of how mirrors are stored in the config also has changed. Use a separate config file, so users can go back from v3 to 2.3.x if they need to (for figuring out a regression) and so users won't run into bugs when moving from 2.3.x to v3. --- README.md | 2 +- helpers/envkernel.sh | 2 +- pmb/config/__init__.py | 3 ++- pmb/config/file.py | 2 +- pmb/config/init.py | 4 ++-- pmb/config/test_config_serde.py | 4 ++-- pmb/config/workdir.py | 2 +- pmb/conftest.py | 6 +++--- pmb/data/tests/{pmbootstrap.cfg => pmbootstrap_v3.cfg} | 0 pmb/helpers/args.py | 2 +- pmb/parse/arguments.py | 2 +- 11 files changed, 15 insertions(+), 14 deletions(-) rename pmb/data/tests/{pmbootstrap.cfg => pmbootstrap_v3.cfg} (100%) diff --git a/README.md b/README.md index 8c46036f..815b5f28 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,7 @@ the `ssh_key_glob` configuration parameter in the pmbootstrap config file to a string containing a glob that is to match the file or files you wish to include. -For example, a `~/.config/pmbootstrap.cfg` may contain: +For example, a `~/.config/pmbootstrap_v3.cfg` may contain: [pmbootstrap] # ... diff --git a/helpers/envkernel.sh b/helpers/envkernel.sh index 5f4a268e..89dc3a31 100644 --- a/helpers/envkernel.sh +++ b/helpers/envkernel.sh @@ -85,7 +85,7 @@ set_alias_pmbootstrap() { return 1 fi - if [ -e "${XDG_CONFIG_HOME:-$HOME/.config}"/pmbootstrap.cfg ]; then + if [ -e "${XDG_CONFIG_HOME:-$HOME/.config}"/pmbootstrap_v3.cfg ]; then "$pmbootstrap" work_migrate else echo "NOTE: First run of pmbootstrap, running 'pmbootstrap init'" diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 62499edc..a22640c4 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -77,7 +77,8 @@ def sudo(cmd: Sequence[PathString]) -> Sequence[PathString]: defaults: dict[str, PathString] = { "cipher": "aes-xts-plain64", "config": Path( - (os.environ.get("XDG_CONFIG_HOME") or os.path.expanduser("~/.config")) + "/pmbootstrap.cfg" + (os.environ.get("XDG_CONFIG_HOME") or os.path.expanduser("~/.config")) + + "/pmbootstrap_v3.cfg" ), # A higher value is typically desired, but this can lead to VERY long open # times on slower devices due to host systems being MUCH faster than the diff --git a/pmb/config/file.py b/pmb/config/file.py index 00713c31..4ef91c7b 100644 --- a/pmb/config/file.py +++ b/pmb/config/file.py @@ -67,7 +67,7 @@ def load(path: Path) -> Config: def serialize(config: Config, skip_defaults=True) -> configparser.ConfigParser: """Serialize the config object into a ConfigParser to write it out - in the pmbootstrap.cfg INI format. + in the pmbootstrap_v3.cfg INI format. :param config: The config object to serialize :param skip_defaults: Skip writing out default values diff --git a/pmb/config/init.py b/pmb/config/init.py index 42a4a98e..3ce8221e 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -135,8 +135,8 @@ def ask_for_channel(config: Config): # Default for first run: "recommended" from channels.cfg # Otherwise, if valid: channel from pmaports.cfg of current branch - # The actual channel name is not saved in pmbootstrap.cfg, because then we - # would need to sync it with what is checked out in pmaports.git. + # The actual channel name is not saved in pmbootstrap_v3.cfg, because then + # we would need to sync it with what is checked out in pmaports.git. default = pmb.config.pmaports.read_config()["channel"] choices = channels_cfg["channels"].keys() if config.is_default_channel or default not in choices: diff --git a/pmb/config/test_config_serde.py b/pmb/config/test_config_serde.py index 00ccefd1..528670d4 100644 --- a/pmb/config/test_config_serde.py +++ b/pmb/config/test_config_serde.py @@ -30,8 +30,8 @@ def test_load(config_file): @pytest.fixture def config_file_2_3_x(tmp_path: Path): - """Fixture to create a temporary pmbootstrap.cfg file with 2.3.x format.""" - file = tmp_path / "pmbootstrap.cfg" + """Fixture to create a temporary pmbootstrap_v3.cfg file with 2.3.x format.""" + file = tmp_path / "pmbootstrap_v3.cfg" contents = """[pmbootstrap] aports = /home/user/.local/var/pmbootstrap/cache_git/pmaports ccache_size = 32G diff --git a/pmb/config/workdir.py b/pmb/config/workdir.py index 76a50ed4..88b79be2 100644 --- a/pmb/config/workdir.py +++ b/pmb/config/workdir.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later """Save, read, verify workdir state related information in $WORK/workdir.cfg, for example the init dates of the chroots. This is not saved in -pmbootstrap.cfg, because pmbootstrap.cfg is not tied to a specific work +pmbootstrap_v3.cfg, because pmbootstrap_v3.cfg is not tied to a specific work dir.""" import configparser diff --git a/pmb/conftest.py b/pmb/conftest.py index 8425ea59..c15d5837 100644 --- a/pmb/conftest.py +++ b/pmb/conftest.py @@ -13,20 +13,20 @@ _testdir = Path(__file__).parent / "data/tests" @pytest.fixture def config_file(tmp_path_factory, request): - """Fixture to create a temporary pmbootstrap.cfg file.""" + """Fixture to create a temporary pmbootstrap_v3.cfg file.""" tmp_path = tmp_path_factory.mktemp("pmbootstrap") flavour = "default" if hasattr(request, "param") and request.param: flavour = request.param - out_file = tmp_path / "pmbootstrap.cfg" + out_file = tmp_path / "pmbootstrap_v3.cfg" workdir = tmp_path / "work" workdir.mkdir() configs = {"default": f"aports = {workdir / 'cache_git' / 'pmaports'}", "no-repos": "aports = "} - file = _testdir / "pmbootstrap.cfg" + file = _testdir / "pmbootstrap_v3.cfg" print(f"CONFIG: {out_file}") cfg = configs[flavour] contents = open(file).read().format(workdir, cfg) diff --git a/pmb/data/tests/pmbootstrap.cfg b/pmb/data/tests/pmbootstrap_v3.cfg similarity index 100% rename from pmb/data/tests/pmbootstrap.cfg rename to pmb/data/tests/pmbootstrap_v3.cfg diff --git a/pmb/helpers/args.py b/pmb/helpers/args.py index 67be2cdf..28a282f8 100644 --- a/pmb/helpers/args.py +++ b/pmb/helpers/args.py @@ -25,7 +25,7 @@ __args: PmbArgs = PmbArgs() ... 2. Argparse merged with others - Variables from the user's config file (~/.config/pmbootstrap.cfg) that + Variables from the user's config file (~/.config/pmbootstrap_v3.cfg) that can be overridden from the command line (pmb/parse/arguments.py) and fall back to the defaults defined in pmb/config/__init__.py (see "defaults = {..."). The user's config file gets generated interactively diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 2f02b2de..a5d29394 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -818,7 +818,7 @@ def get_parser(): dest="config", type=lambda x: Path(x), default=pmb.config.defaults["config"], - help="path to pmbootstrap.cfg file (default in ~/.config/)", + help="path to pmbootstrap_v3.cfg file (default in ~/.config/)", ) parser.add_argument( "-mp",