← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~xnox/launchpad:drop-i18n-index into launchpad:master

 

Dimitri John Ledkov has proposed merging ~xnox/launchpad:drop-i18n-index into launchpad:master.

Commit message:
Add a new option to turn off i18n/Index file publishing

It is not signed, it contains SHA-1 hashes which apt doesn't trust anymore, and it is believed to be unused by apt, as it finds the underlying translation files from the the InRelease file.

Intention is to turn publishing i18n index file off during 24.04 release development

Requested reviews:
  Ubuntu Package Archive Administrators (ubuntu-archive)
  Julian Andres Klode (juliank)
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~xnox/launchpad/+git/launchpad/+merge/453586
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~xnox/launchpad:drop-i18n-index into launchpad:master.
diff --git a/lib/lp/archivepublisher/publishing.py b/lib/lp/archivepublisher/publishing.py
index 0bb7985..b033d1a 100644
--- a/lib/lp/archivepublisher/publishing.py
+++ b/lib/lp/archivepublisher/publishing.py
@@ -1682,11 +1682,12 @@ class Publisher:
             # Schedule i18n files for inclusion in the Release file.
             all_series_files.add(os.path.join(i18n_subpath, i18n_file))
 
-        with open(os.path.join(i18n_dir, "Index"), "wb") as f:
-            i18n_index.dump(f, "utf-8")
+        if distroseries.publish_i18n_index:
+            with open(os.path.join(i18n_dir, "Index"), "wb") as f:
+                i18n_index.dump(f, "utf-8")
 
-        # Schedule this for inclusion in the Release file.
-        all_series_files.add(os.path.join(component, "i18n", "Index"))
+            # Schedule this for inclusion in the Release file.
+            all_series_files.add(os.path.join(component, "i18n", "Index"))
 
     def _readIndexFileHashes(
         self, suite, file_name, subpath=None, real_file_name=None
diff --git a/lib/lp/archivepublisher/tests/test_publisher.py b/lib/lp/archivepublisher/tests/test_publisher.py
index be57298..9e16aea 100644
--- a/lib/lp/archivepublisher/tests/test_publisher.py
+++ b/lib/lp/archivepublisher/tests/test_publisher.py
@@ -2847,6 +2847,29 @@ class TestPublisher(TestPublisherBase):
 
         self.assertFalse(os.path.exists(os.path.join(i18n_root, "Index")))
 
+    def testWriteSuiteI18nPublishI18nFalse(self):
+        """i18n/Index is not generated when publish_i18n_index is False."""
+        publisher = Publisher(
+            self.logger,
+            self.config,
+            self.disk_pool,
+            self.ubuntutest.main_archive,
+        )
+        i18n_root = os.path.join(
+            self.config.distsroot, "breezy-autotest", "main", "i18n"
+        )
+
+        self.ubuntu["breezy-autotest"].publish_i18n_index = False
+
+        publisher._writeSuiteI18n(
+            self.ubuntutest["breezy-autotest"],
+            PackagePublishingPocket.RELEASE,
+            "main",
+            set(),
+        )
+
+        self.assertFalse(os.path.exists(os.path.join(i18n_root, "Index")))
+
     def testReadIndexFileHashesCompression(self):
         """Test compressed file handling in _readIndexFileHashes."""
         publisher = Publisher(
diff --git a/lib/lp/registry/configure.zcml b/lib/lp/registry/configure.zcml
index 5dda9d1..3cf36a8 100644
--- a/lib/lp/registry/configure.zcml
+++ b/lib/lp/registry/configure.zcml
@@ -332,6 +332,7 @@
                 include_long_descriptions
                 index_compressors
                 publish_by_hash
+                publish_i18n_index
                 advertise_by_hash
                 strict_supported_component_dependencies
                 inherit_overrides_from_parents"/>
diff --git a/lib/lp/registry/interfaces/distroseries.py b/lib/lp/registry/interfaces/distroseries.py
index bcb5a24..d27ac20 100644
--- a/lib/lp/registry/interfaces/distroseries.py
+++ b/lib/lp/registry/interfaces/distroseries.py
@@ -585,6 +585,17 @@ class IDistroSeriesPublic(
         as_of="devel",
     )
 
+    publish_i18n_index = exported(
+        Bool(
+            title=_("Publish I18n index"),
+            required=True,
+            description=_(
+                """
+            Publish archive i18n/Index file, which is believed to be used."""
+            ),
+        )
+    )
+
     inherit_overrides_from_parents = Bool(
         title=_("Inherit overrides from parents"),
         readonly=False,
diff --git a/lib/lp/registry/model/distroseries.py b/lib/lp/registry/model/distroseries.py
index 2e19dfb..f67348b 100644
--- a/lib/lp/registry/model/distroseries.py
+++ b/lib/lp/registry/model/distroseries.py
@@ -285,6 +285,7 @@ class DistroSeries(
             "publish_by_hash": False,
             "advertise_by_hash": False,
             "strict_supported_component_dependencies": True,
+            "publish_i18n_index": True,
         }
 
     @property
@@ -969,6 +970,15 @@ class DistroSeries(
             "strict_supported_component_dependencies"
         ] = value
 
+    @property
+    def publish_i18n_index(self):
+        return self.publishing_options.get("publish_i18n_index", True)
+
+    @publish_i18n_index.setter
+    def publish_i18n_index(self, value):
+        assert isinstance(value, bool)
+        self.publishing_options["publish_i18n_index"] = value
+
     def _customizeSearchParams(self, search_params):
         """Customize `search_params` for this distribution series."""
         search_params.setDistroSeries(self)
diff --git a/lib/lp/registry/stories/webservice/xx-distroseries.rst b/lib/lp/registry/stories/webservice/xx-distroseries.rst
index 4fe4c9b..51a089a 100644
--- a/lib/lp/registry/stories/webservice/xx-distroseries.rst
+++ b/lib/lp/registry/stories/webservice/xx-distroseries.rst
@@ -94,6 +94,7 @@ For distroseries we publish a subset of its attributes.
     parent_series_link: 'http://.../ubuntu/warty'
     proposed_not_automatic: False
     publish_by_hash: False
+    publish_i18n_index: True
     registrant_link: 'http://.../~mark'
     resource_type_link: ...
     self_link: 'http://.../ubuntu/hoary'
diff --git a/lib/lp/registry/tests/test_distroseries.py b/lib/lp/registry/tests/test_distroseries.py
index c7e2111..1fe64d4 100644
--- a/lib/lp/registry/tests/test_distroseries.py
+++ b/lib/lp/registry/tests/test_distroseries.py
@@ -448,6 +448,17 @@ class TestDistroSeries(TestCaseWithFactory):
             ]
         )
 
+    def test_publish_i18n_index(self):
+        distroseries = self.factory.makeDistroSeries()
+        self.assertTrue(distroseries.publish_i18n_index)
+        with admin_logged_in():
+            distroseries.publish_i18n_index = False
+        self.assertFalse(distroseries.publish_i18n_index)
+        naked_distroseries = removeSecurityProxy(distroseries)
+        self.assertFalse(
+            naked_distroseries.publishing_options["publish_i18n_index"]
+        )
+
 
 class TestDistroSeriesPackaging(TestCaseWithFactory):
     layer = DatabaseFunctionalLayer
diff --git a/lib/lp/soyuz/scripts/initialize_distroseries.py b/lib/lp/soyuz/scripts/initialize_distroseries.py
index 6a35b71..4097a10 100644
--- a/lib/lp/soyuz/scripts/initialize_distroseries.py
+++ b/lib/lp/soyuz/scripts/initialize_distroseries.py
@@ -454,6 +454,9 @@ class InitializeDistroSeries:
             parent.strict_supported_component_dependencies
             for parent in self.derivation_parents
         )
+        self.distroseries.publish_i18n_index = any(
+            parent.publish_i18n_index for parent in self.derivation_parents
+        )
 
     def _copy_architectures(self):
         log.info("Copying distroarchseries from parents.")
diff --git a/lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py b/lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py
index aee00cb..c0d6b57 100644
--- a/lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py
+++ b/lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py
@@ -96,6 +96,7 @@ class InitializationHelperTestCase(TestCaseWithFactory):
         parent.publish_by_hash = True
         parent.advertise_by_hash = True
         parent.strict_supported_component_dependencies = False
+        parent.publish_i18n_index = False
         self._populate_parent(parent, parent_das, packages, pocket)
         return parent, parent_das
 
@@ -842,6 +843,7 @@ class TestInitializeDistroSeries(InitializationHelperTestCase):
         self.assertTrue(child.publish_by_hash)
         self.assertTrue(child.advertise_by_hash)
         self.assertFalse(child.strict_supported_component_dependencies)
+        self.assertFalse(child.publish_i18n_index)
 
     def test_initialize(self):
         # Test a full initialize with no errors.