summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rwxr-xr-xutils/get_ubuntu_mirrors_from_lp.py72
1 files changed, 14 insertions, 58 deletions
diff --git a/utils/get_ubuntu_mirrors_from_lp.py b/utils/get_ubuntu_mirrors_from_lp.py
index b912f28d..3c183b6d 100755
--- a/utils/get_ubuntu_mirrors_from_lp.py
+++ b/utils/get_ubuntu_mirrors_from_lp.py
@@ -24,68 +24,24 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
-import urllib2
-import re
+import feedparser
import sys
-# the list of official Ubuntu servers
-mirrors = []
-# path to the local mirror list
-list_path = "../data/templates/Ubuntu.mirrors"
-
-
-try:
- f = open("/usr/share/iso-codes/iso_3166.tab", "r")
- lines = f.readlines()
- f.close()
-except:
- print "Could not read country information"
- sys.exit(1)
+d = feedparser.parse("https://launchpad.net/ubuntu/+archivemirrors-rss")
+#d = feedparser.parse(open("+archivemirrors-rss"))
countries = {}
-for line in lines:
- parts = line.split("\t")
- countries[parts[1].strip()] = parts[0].lower()
-
-req = urllib2.Request("https://launchpad.net/ubuntu/+archivemirrors")
-print "Downloading mirrors list from Launchpad..."
-try:
- uri=urllib2.urlopen(req)
- content = uri.read()
- uri.close()
-except:
- print "Failed to download or extract the mirrors list!"
- sys.exit(1)
-
-content = content.replace("\n", "")
-
-content_splits = re.split(r'<tr class="highlighted"',
- re.findall(r'<table class="listing" '
- 'id="mirrors_list">.+?</table>',
- content)[0])
-lines=[]
-
-
-def find(split):
- country = re.search(r"<strong>(.+?)</strong>", split)
- if not country:
- return
- if country.group(1) in countries:
- lines.append("#LOC:%s" % countries[country.group(1)].upper())
- else:
- lines.append("#LOC:%s" % country.group(1))
- # FIXME: currently the protocols are hardcoded: ftp http
- urls = re.findall(r'<a href="(?![a-zA-Z:/_\-]+launchpad.+?">)'
- '(((http)|(ftp)).+?)">',
- split)
- map(lambda u: lines.append(u[0]), urls)
+for entry in d.entries:
+ countrycode = entry.mirror_countrycode
+ if not countrycode in countries:
+ countries[countrycode] = set()
+ for link in entry.links:
+ countries[countrycode].add(link.href)
-map(find, content_splits)
-print "Writing local mirrors list: %s" % list_path
-list = open(list_path, "w")
-for line in lines:
- list.write("%s\n" % line)
-list.close()
-print "Done."
+keys = countries.keys()
+keys.sort()
+for country in keys:
+ print "#LOC:%s" % country
+ print "\n".join(countries[country])