~mvo/python-apt/debian-sid-mirror

0.15.5 by Sebastian Heinlein
* add a script that downloads and extracts the mirrors list from the Ubuntu wiki
1
#!/usr/bin/env python
2
#
0.15.6 by Sebastian Heinlein
* rename mirrors get script: it is Ubuntu specific
3
#  get_ubuntu_mirrors.py
0.15.5 by Sebastian Heinlein
* add a script that downloads and extracts the mirrors list from the Ubuntu wiki
4
#
5
#  Download the latest list with available mirrors from the Ubuntu
6
#  wiki and extract the hosts from the raw page
7
#
8
#  Copyright (c) 2006 Free Software Foundation Europe
9
#
10
#  Author: Sebastian Heinlein <glatzor@ubuntu.com>
196.1.1 by Ben Finney
Remove trailing whitespace.
11
#
12
#  This program is free software; you can redistribute it and/or
13
#  modify it under the terms of the GNU General Public License as
0.15.5 by Sebastian Heinlein
* add a script that downloads and extracts the mirrors list from the Ubuntu wiki
14
#  published by the Free Software Foundation; either version 2 of the
15
#  License, or (at your option) any later version.
196.1.1 by Ben Finney
Remove trailing whitespace.
16
#
0.15.5 by Sebastian Heinlein
* add a script that downloads and extracts the mirrors list from the Ubuntu wiki
17
#  This program is distributed in the hope that it will be useful,
18
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
19
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
#  GNU General Public License for more details.
196.1.1 by Ben Finney
Remove trailing whitespace.
21
#
0.15.5 by Sebastian Heinlein
* add a script that downloads and extracts the mirrors list from the Ubuntu wiki
22
#  You should have received a copy of the GNU General Public License
23
#  along with this program; if not, write to the Free Software
24
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25
#  USA
26
27
import urllib2
28
import re
29
import os
30
import commands
31
import sys
32
33
# the list of official Ubuntu servers
34
mirrors = []
35
# path to the local mirror list
0.15.6 by Sebastian Heinlein
* rename mirrors get script: it is Ubuntu specific
36
list_path = "../data/templates/Ubuntu.mirrors"
0.15.5 by Sebastian Heinlein
* add a script that downloads and extracts the mirrors list from the Ubuntu wiki
37
38
req = urllib2.Request("https://wiki.ubuntu.com/Archive?action=raw")
39
40
try:
41
    print "Downloading mirrors list from the Ubuntu wiki..."
42
    uri=urllib2.urlopen(req)
43
    p = re.compile('^.*((http|ftp):\/\/[A-Za-z0-9-.:\/_]+).*\n*$')
44
    for line in uri.readlines():
196.1.4 by Ben Finney
Fix code indentation to 4 spaces, to conform with PEP 8.
45
        if r"[[Anchor(dvd-images)]]" in line:
46
            break
47
        if "http://" in line or "ftp://" in line:
48
            mirrors.append(p.sub(r"\1", line))
0.15.5 by Sebastian Heinlein
* add a script that downloads and extracts the mirrors list from the Ubuntu wiki
49
    uri.close()
50
except:
51
    print "Failed to download or extract the mirrors list!"
52
    sys.exit(1)
53
54
print "Writing local mirrors list: %s" % list_path
55
list = open(list_path, "w")
56
for mirror in mirrors:
57
    list.write("%s\n" % mirror)
58
list.close()
59
print "Done."