diff -Nru curtin-21.2-958-g9c5acef6/curtin/commands/apt_config.py curtin-21.2-959-g02037187/curtin/commands/apt_config.py --- curtin-21.2-958-g9c5acef6/curtin/commands/apt_config.py 2021-09-20 21:04:33.000000000 +0000 +++ curtin-21.2-959-g02037187/curtin/commands/apt_config.py 2021-09-22 18:03:39.000000000 +0000 @@ -260,11 +260,17 @@ return util.render_string(template_suite, {'RELEASE': release}) -def disable_suites(disabled, src, release): +def commentify(entry): + # handle commenting ourselves - it handles lines with + # options better + return SourceEntry('# ' + str(entry)) + + +def disable_suites(disabled, entries, release): """reads the config for suites to be disabled and removes those from the template""" if not disabled: - return src + return entries suites_to_disable = [] for suite in disabled: @@ -273,15 +279,35 @@ suites_to_disable.append(release_suite) output = [] - for entry in src: - if entry.dist in suites_to_disable and not entry.disabled: - # handle commenting ourselves - it handles lines with - # options better - entry = SourceEntry('# ' + str(entry)) + for entry in entries: + if not entry.disabled and entry.dist in suites_to_disable: + entry = commentify(entry) output.append(entry) return output +def disable_components(disabled, entries): + """reads the config for components to be disabled and remove those + from the entries""" + if not disabled: + return entries + + # purposefully skip disabling the main component + comps_to_disable = {comp for comp in disabled if comp != 'main'} + + output = [] + for entry in entries: + if not entry.disabled and comps_to_disable.intersection(entry.comps): + output.append(commentify(entry)) + entry.comps = [comp for comp in entry.comps + if comp not in comps_to_disable] + if entry.comps: + output.append(entry) + else: + output.append(entry) + return output + + def update_dist(entries, release): for entry in entries: entry.dist = util.render_string(entry.dist, {'RELEASE': release}) @@ -316,6 +342,7 @@ entries = update_mirrors(entries, mirrors) entries = update_dist(entries, release) entries = disable_suites(cfg.get('disable_suites'), entries, release) + entries = disable_components(cfg.get('disable_components'), entries) output = entries_to_str(entries) orig = paths.target_path(target, aptsrc) diff -Nru curtin-21.2-958-g9c5acef6/debian/changelog curtin-21.2-959-g02037187/debian/changelog --- curtin-21.2-958-g9c5acef6/debian/changelog 2021-09-20 21:04:35.000000000 +0000 +++ curtin-21.2-959-g02037187/debian/changelog 2021-09-22 18:03:42.000000000 +0000 @@ -1,8 +1,8 @@ -curtin (21.2-958-g9c5acef6-0ubuntu1+307~trunk~ubuntu20.04.1) focal; urgency=low +curtin (21.2-959-g02037187-0ubuntu1+307~trunk~ubuntu20.04.1) focal; urgency=low * Auto build. - -- curtin developers Mon, 20 Sep 2021 21:04:35 +0000 + -- curtin developers Wed, 22 Sep 2021 18:03:42 +0000 curtin (21.2-0ubuntu1~20.04.1) focal; urgency=medium diff -Nru curtin-21.2-958-g9c5acef6/debian/git-build-recipe.manifest curtin-21.2-959-g02037187/debian/git-build-recipe.manifest --- curtin-21.2-958-g9c5acef6/debian/git-build-recipe.manifest 2021-09-20 21:04:35.000000000 +0000 +++ curtin-21.2-959-g02037187/debian/git-build-recipe.manifest 2021-09-22 18:03:42.000000000 +0000 @@ -1,3 +1,3 @@ -# git-build-recipe format 0.4 deb-version 21.2-958-g9c5acef6-0ubuntu1+307~trunk -lp:curtin git-commit:9c5acef61027d9f1d938cb1895338cf66bf08a63 +# git-build-recipe format 0.4 deb-version 21.2-959-g02037187-0ubuntu1+307~trunk +lp:curtin git-commit:02037187c142b41f9e993eefde615794827fd271 merge ubuntu-pkg lp:curtin git-commit:26e70f7aa312d512904e03f7b8eecd594f070b8d diff -Nru curtin-21.2-958-g9c5acef6/doc/topics/apt_source.rst curtin-21.2-959-g02037187/doc/topics/apt_source.rst --- curtin-21.2-958-g9c5acef6/doc/topics/apt_source.rst 2021-09-20 21:04:33.000000000 +0000 +++ curtin-21.2-959-g02037187/doc/topics/apt_source.rst 2021-09-22 18:03:39.000000000 +0000 @@ -35,6 +35,8 @@ - disabling suites (=pockets) + - disabling components (multiverse, universe, restricted) + - per architecture mirror definition diff -Nru curtin-21.2-958-g9c5acef6/examples/apt-source.yaml curtin-21.2-959-g02037187/examples/apt-source.yaml --- curtin-21.2-958-g9c5acef6/examples/apt-source.yaml 2021-09-20 21:04:33.000000000 +0000 +++ curtin-21.2-959-g02037187/examples/apt-source.yaml 2021-09-22 18:03:39.000000000 +0000 @@ -27,8 +27,8 @@ # # This is an empty list by default, so nothing is disabled. # - # If given, those suites are removed from sources.list after all other - # modifications have been made. + # If given, those suites are removed from sources.list after most other + # modifications have been made, but before component removal. # Suites are even disabled if no other modification was made, # but not if is preserve_sources_list is active. # There is a special alias “$RELEASE” as in the sources that will be replace @@ -45,12 +45,28 @@ # There is no harm in specifying a suite to be disabled that is not found in # the source.list file (just a no-op then) # - # Note: Lines don’t get deleted, but disabled by being converted to a comment. # The following example disables all usual defaults except $RELEASE-security. # On top it disables a custom suite called "mysuite" disable_suites: [$RELEASE-updates, backports, $RELEASE, mysuite] - # 1.3 primary/security + # 1.3 disable_components + # + # This is an empty list by default, so nothing is disabled. + # + # If given, those components are removed from sources.list after all other + # modifications have been made. + # Components are even disabled if no other modification was made, + # but not if is preserve_sources_list is active. + # The 'main' component is never disabled. Should that be desired, this can + # be achieved by way of a sources_list template. + # + # There is no harm in specifying a component to be disabled that is not found + # in the source.list file (just a no-op then) + # + # The following example disables all usual default components except main. + disable_components: [restricted, universe, multiverse] + + # 1.4 primary/security # # define a custom (e.g. localized) mirror that will be used in sources.list # and any custom sources entries for deb / deb-src lines. @@ -90,7 +106,7 @@ # primary: http://archive.ubuntu.com/ubuntu # security: http://security.ubuntu.com/ubuntu - # 1.4 sources_list + # 1.5 sources_list # # Provide a custom template for rendering sources.list # without one provided curtin will try to modify the sources.list it finds @@ -105,7 +121,7 @@ deb $PRIMARY $RELEASE universe restricted deb $SECURITY $RELEASE-security multiverse - # 1.5 conf + # 1.6 conf # # Any apt config string that will be made available to apt # see the APT.CONF(5) man page for details what can be specified @@ -117,7 +133,7 @@ }; }; - # 1.6 (http_|ftp_|https_)proxy + # 1.7 (http_|ftp_|https_)proxy # # Proxies are the most common apt.conf option, so that for simplified use # there is a shortcut for those. Those get automatically translated into the @@ -129,7 +145,7 @@ ftp_proxy: ftp://[[user][:pass]@]host[:port]/ https_proxy: https://[[user][:pass]@]host[:port]/ - # 1.7 add_apt_repo_match + # 1.8 add_apt_repo_match # # 'source' entries in apt-sources that match this python regex # expression will be passed to add-apt-repository diff -Nru curtin-21.2-958-g9c5acef6/tests/unittests/test_apt_source.py curtin-21.2-959-g02037187/tests/unittests/test_apt_source.py --- curtin-21.2-958-g9c5acef6/tests/unittests/test_apt_source.py 2021-09-20 21:04:33.000000000 +0000 +++ curtin-21.2-959-g02037187/tests/unittests/test_apt_source.py 2021-09-22 18:03:39.000000000 +0000 @@ -955,6 +955,99 @@ result = apt_config.disable_suites(disabled, entryify(orig), rel) self.assertEqual(expect, lineify(result)) + def test_disable_components(self): + orig = """\ +deb http://ubuntu.com/ubuntu xenial main restricted universe multiverse +deb http://ubuntu.com/ubuntu xenial-updates main restricted universe multiverse +deb http://ubuntu.com/ubuntu xenial-security \ +main restricted universe multiverse +deb-src http://ubuntu.com/ubuntu xenial main restricted universe multiverse +deb http://ubuntu.com/ubuntu/ xenial-proposed \ +main restricted universe multiverse""" + expect = orig + + # no-op + disabled = [] + result = apt_config.disable_components(disabled, entryify(orig)) + self.assertEqual(expect, lineify(result)) + + # no-op 2 + disabled = None + result = apt_config.disable_components(disabled, entryify(orig)) + self.assertEqual(expect, lineify(result)) + + # we don't disable main + disabled = ('main', ) + result = apt_config.disable_components(disabled, entryify(orig)) + self.assertEqual(expect, lineify(result)) + + # nonsense + disabled = ('asdf', ) + result = apt_config.disable_components(disabled, entryify(orig)) + self.assertEqual(expect, lineify(result)) + + # free-only + expect = """\ +# deb http://ubuntu.com/ubuntu xenial main restricted universe multiverse +deb http://ubuntu.com/ubuntu xenial main universe +# deb http://ubuntu.com/ubuntu xenial-updates main restricted \ +universe multiverse +deb http://ubuntu.com/ubuntu xenial-updates main universe +# deb http://ubuntu.com/ubuntu xenial-security main restricted \ +universe multiverse +deb http://ubuntu.com/ubuntu xenial-security main universe +# deb-src http://ubuntu.com/ubuntu xenial main restricted universe multiverse +deb-src http://ubuntu.com/ubuntu xenial main universe +# deb http://ubuntu.com/ubuntu/ xenial-proposed main restricted \ +universe multiverse +deb http://ubuntu.com/ubuntu/ xenial-proposed main universe""" + disabled = ('restricted', 'multiverse') + result = apt_config.disable_components(disabled, entryify(orig)) + self.assertEqual(expect, lineify(result)) + + # skip line when this component is the last + orig = """\ +deb http://ubuntu.com/ubuntu xenial main universe multiverse +deb http://ubuntu.com/ubuntu xenial-updates universe +deb http://ubuntu.com/ubuntu xenial-security universe multiverse""" + expect = """\ +# deb http://ubuntu.com/ubuntu xenial main universe multiverse +deb http://ubuntu.com/ubuntu xenial main +# deb http://ubuntu.com/ubuntu xenial-updates universe +# deb http://ubuntu.com/ubuntu xenial-security universe multiverse""" + disabled = ('universe', 'multiverse') + result = apt_config.disable_components(disabled, entryify(orig)) + self.assertEqual(expect, lineify(result)) + + # comment everything + orig = """\ +deb http://ubuntu.com/ubuntu xenial-security universe multiverse""" + expect = """\ +# deb http://ubuntu.com/ubuntu xenial-security universe multiverse""" + disabled = ('universe', 'multiverse') + result = apt_config.disable_components(disabled, entryify(orig)) + self.assertEqual(expect, lineify(result)) + + # double-hash comment + orig = """\ + +## Major bug fix updates produced after the final release of the +## distribution. + +deb http://archive.ubuntu.com/ubuntu/ impish-updates main restricted +# deb http://archive.ubuntu.com/ubuntu/ impish-updates main restricted""" + expect = """\ + +## Major bug fix updates produced after the final release of the +## distribution. + +# deb http://archive.ubuntu.com/ubuntu/ impish-updates main restricted +deb http://archive.ubuntu.com/ubuntu/ impish-updates main +# deb http://archive.ubuntu.com/ubuntu/ impish-updates main restricted""" + disabled = ('restricted', ) + result = apt_config.disable_components(disabled, entryify(orig)) + self.assertEqual(expect, lineify(result)) + @mock.patch("curtin.util.write_file") @mock.patch("curtin.distro.get_architecture") def test_generate_with_options(self, get_arch, write_file):