launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #29832
[Merge] ~cjwatson/launchpad:remove-cache-country-mirrors into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:remove-cache-country-mirrors into launchpad:master.
Commit message:
Remove cache-country-mirrors script
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/440027
The mirrors index is now published using https://git.launchpad.net/ubuntu-mirrors instead, which fetches the same information from the webservice API using `Distribution.getBestMirrorsForCountry`.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:remove-cache-country-mirrors into launchpad:master.
diff --git a/lib/lp/registry/doc/cache-country-mirrors.rst b/lib/lp/registry/doc/cache-country-mirrors.rst
deleted file mode 100644
index 78dfe6c..0000000
--- a/lib/lp/registry/doc/cache-country-mirrors.rst
+++ /dev/null
@@ -1,63 +0,0 @@
-Caching country mirrors
-=======================
-
-The https://launchpad.net/ubuntu/+countrymirrors-archive page serves the
-list of official Ubuntu mirrors for the country where the request was
-originated. This functionality is provided so that apt can pick the
-mirror which is geographically closer to the box where it's running.
-One problem with that, though, is that there are way too many Ubuntu
-users and most of them will update their systems when security updates
-are available, causing apt to DDoS Launchpad. To avoid that we'll
-periodically generate static versions of these lists and serve them
-through apache.
-
-These static versions are generated by the cache-country-mirrors.py
-script, which takes a single argument -- the directory in which the
-files are saved.
-
- >>> from subprocess import Popen, PIPE
- >>> import tempfile
- >>> directory = tempfile.mkdtemp()
- >>> process = Popen(
- ... "scripts/cache-country-mirrors.py -q %s" % directory,
- ... shell=True,
- ... stdin=PIPE,
- ... stdout=PIPE,
- ... stderr=PIPE,
- ... universal_newlines=True,
- ... )
- >>> (out, err) = process.communicate()
- >>> print(out)
- <BLANKLINE>
- >>> print(err)
- <BLANKLINE>
- >>> process.returncode
- 0
-
-Let's have a look at the files generated by our script to see if they
-look good.
-
- >>> import os
- >>> import stat
-
- >>> files = os.listdir(directory)
- >>> len(files)
- 240
- >>> set(["BR.txt", "AR.txt", "CO.txt", "CL.txt"]).issubset(files)
- True
- >>> fr_txt_path = os.path.join(directory, "FR.txt")
- >>> print("%o" % stat.S_IMODE(os.stat(fr_txt_path).st_mode))
- 644
- >>> with open(fr_txt_path) as fr_txt:
- ... for line in sorted(fr_txt.read().split("\n")):
- ... print(line)
- ...
- http://archive.ubuntu.com/ubuntu/
- http://localhost:11375/archive-mirror/
- http://localhost:11375/valid-mirror/
-
-Cleanup!
-
- >>> import shutil
- >>> shutil.rmtree(directory)
-
diff --git a/scripts/cache-country-mirrors.py b/scripts/cache-country-mirrors.py
deleted file mode 100755
index 177b56a..0000000
--- a/scripts/cache-country-mirrors.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/usr/bin/python3 -S
-#
-# Copyright 2009 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Script to save list of country mirrors for in text files.
-
-For each country in our database, this script will create a text file,
-named like cc.txt (where cc is the two letter country code),
-containing the archive mirrors for that country.
-"""
-
-import _pythonpath # noqa: F401
-
-import os
-import shutil
-import tempfile
-
-from zope.component import getUtility
-
-from lp.app.interfaces.launchpad import ILaunchpadCelebrities
-from lp.registry.interfaces.distributionmirror import MirrorContent
-from lp.services.scripts.base import LaunchpadScript, LaunchpadScriptFailure
-from lp.services.worlddata.interfaces.country import ICountrySet
-
-
-class CacheCountryMirrors(LaunchpadScript):
-
- usage = "%prog <target-directory>"
-
- def main(self):
- if len(self.args) != 1:
- raise LaunchpadScriptFailure(
- "You must specify the full path of the directory where the "
- "files will be stored."
- )
-
- [dir_name] = self.args
- if not os.path.isdir(dir_name):
- raise LaunchpadScriptFailure("'%s' is not a directory." % dir_name)
-
- for country in getUtility(ICountrySet):
- mirrors = getUtility(
- ILaunchpadCelebrities
- ).ubuntu.getBestMirrorsForCountry(country, MirrorContent.ARCHIVE)
- # Write the content to a temporary file first, to avoid problems
- # if the script is killed or something like that.
- fd, tmpfile = tempfile.mkstemp()
- mirrors_file = os.fdopen(fd, "w")
- mirrors_file.write(
- "\n".join(mirror.base_url for mirror in mirrors)
- )
- mirrors_file.close()
- filename = os.path.join(dir_name, "%s.txt" % country.iso3166code2)
- shutil.move(tmpfile, filename)
- os.chmod(filename, 0o644)
-
-
-if __name__ == "__main__":
- CacheCountryMirrors("cache-country-mirrors").lock_and_run()