From 19986cf1b142b42027d3ec392d1df9245298f893 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Mon, 10 Jan 2022 07:23:37 +0100 Subject: [PATCH] chore: exclude packages sections using tools/packages.py (#1499) * feat: exclude packages sections using tools/packages.py * chore: group apache deps packages in a section This allow one to exlude the entire section and install nginx for example. --- legacy/packages.ini | 10 ++++++---- tools/packages.py | 17 +++++++++++++---- tools/packages_test.py | 2 ++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/legacy/packages.ini b/legacy/packages.ini index 778f8d173..175304d55 100644 --- a/legacy/packages.ini +++ b/legacy/packages.ini @@ -1,14 +1,18 @@ # This file contains a list of package dependencies. [common] -apache2 = buster, bullseye, bionic, focal # The php-pear package depends on php-(cli|common|xml), be sure to # install the dependencies with the right php version. php-pear = buster, bullseye, bionic, focal php-amqplib = buster, bullseye, bionic, focal +[apache] +apache2 = buster, bullseye, bionic, focal +libapache2-mod-php7.2 = bionic +libapache2-mod-php7.3 = buster +libapache2-mod-php7.4 = bullseye, focal + # Bionic [php7.2] -libapache2-mod-php7.2 = bionic php7.2 = bionic php7.2-apcu = bionic # Bionic does not have php7.2-apcu-bc, use php-apcu-bc instead @@ -25,7 +29,6 @@ php7.2-xml = bionic # Buster [php7.3] -libapache2-mod-php7.3 = buster php7.3 = buster php7.3-apcu = buster php7.3-apcu-bc = buster @@ -41,7 +44,6 @@ php7.3-xml = buster # Bullseye, Focal [php7.4] -libapache2-mod-php7.4 = bullseye, focal php7.4 = bullseye, focal php7.4-apcu = bullseye, focal php7.4-apcu-bc = bullseye, focal diff --git a/tools/packages.py b/tools/packages.py index f2f9f1b9c..4e5004bda 100755 --- a/tools/packages.py +++ b/tools/packages.py @@ -4,7 +4,7 @@ from argparse import ArgumentParser from configparser import ConfigParser from os import PathLike from pathlib import Path -from typing import Iterator, List, Set +from typing import Iterator, List, Optional, Set DEFAULT_PACKAGES_FILENAME = "packages.ini" FORMATS = ("list", "line") @@ -18,6 +18,7 @@ def load_packages( raw: str, distribution: str, development: bool = False, + exclude: Optional[List[str]] = None, ) -> Set[str]: if distribution not in DISTRIBUTIONS: raise ValueError(f"Invalid distribution '{distribution}'") @@ -26,8 +27,9 @@ def load_packages( manager.read_string(raw) packages = set() + exclude = set(exclude or []) for section, entries in manager.items(): - if not development and section == DEVELOPMENT_SECTION: + if not development and section == DEVELOPMENT_SECTION or section in exclude: continue for package, distributions in entries.items(): @@ -56,11 +58,12 @@ def list_packages( paths: List[PathLike], distribution: str, development: bool = False, + exclude: Optional[List[str]] = None, ) -> Set[str]: packages = set() for package_file in list_packages_files(paths): raw = package_file.read_text() - packages.update(load_packages(raw, distribution, development)) + packages.update(load_packages(raw, distribution, development, exclude)) return set(sorted(packages)) @@ -80,6 +83,12 @@ def run(): help="include development packages.", action="store_true", ) + parser.add_argument( + "-e", + "--exclude", + nargs="+", + help="exclude packages sections.", + ) parser.add_argument( "distribution", choices=DISTRIBUTIONS, @@ -92,7 +101,7 @@ def run(): ) args = parser.parse_args() - packages = list_packages(args.path, args.distribution, args.dev) + packages = list_packages(args.path, args.distribution, args.dev, args.exclude) if args.format == "list": print("\n".join(packages)) diff --git a/tools/packages_test.py b/tools/packages_test.py index b28fed5da..d98a6aa77 100644 --- a/tools/packages_test.py +++ b/tools/packages_test.py @@ -18,12 +18,14 @@ ffmpeg = buster, bionic, focal result_buster = {"curl", "postgresql"} result_bionic = {"apache2", "curl", "ffmpeg"} result_focal = {"postgresql", "apache2", "ffmpeg"} +result_exclude = {"postgresql", "ffmpeg"} def test_load_packages(): assert load_packages(PACKAGE_INI, "buster", False) == result_buster assert load_packages(PACKAGE_INI, "bionic", True) == result_bionic assert load_packages(PACKAGE_INI, "focal", True) == result_focal + assert load_packages(PACKAGE_INI, "focal", True, ["legacy"]) == result_exclude def test_list_packages(tmp_path: Path):