summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Heinlein <sebi@sebi-laptop>2007-01-03 12:44:10 +0100
committerSebastian Heinlein <sebi@sebi-laptop>2007-01-03 12:44:10 +0100
commitb32668ac3191a5758fa0f546ce91e1f9604ba2b9 (patch)
treeb6787ba11ba0521a363319c27acb8ea5d7a4229b
parent66487b73b1418975bc018d97e0a7c407ebcf03b8 (diff)
downloadpython-apt-b32668ac3191a5758fa0f546ce91e1f9604ba2b9.tar.gz
* add support for mirror locations
* rename CountryInformation.country_code to .code
-rw-r--r--AptSources/DistInfo.py32
-rw-r--r--AptSources/aptsources.py4
2 files changed, 25 insertions, 11 deletions
diff --git a/AptSources/DistInfo.py b/AptSources/DistInfo.py
index 48f098dd..aa345dff 100644
--- a/AptSources/DistInfo.py
+++ b/AptSources/DistInfo.py
@@ -86,10 +86,11 @@ class Component:
class Mirror:
''' Storage for mirror related information '''
- def __init__(self, data):
- proto, self.hostname, dir = data
+ def __init__(self, proto, hostname, dir, location=None):
+ self.hostname = hostname
self.repositories = []
self.add_repository(proto, dir)
+ self.location = location
def add_repository(self, proto, dir):
self.repositories.append(Repository(proto, dir))
def get_repositories_for_proto(self, proto):
@@ -99,6 +100,10 @@ class Mirror:
self.repositories)) > 0
def get_repo_urls(self):
return map(lambda r: r.get_url(self.hostname), self.repositories)
+ def get_location(self):
+ return self.location
+ def set_location(self, location):
+ self.location = location
class Repository:
def __init__(self, proto, dir):
@@ -120,6 +125,11 @@ class DistInfo:
self.metarelease_uri = ''
self.suites = []
+ location = None
+ match_loc = re.compile(r"^#LOC:(.+)$")
+ match_mirror_line = re.compile(r"^(#LOC:.+)|(((http)|(ftp)|(rsync)|(file)|(https))://[A-Za-z/\.:\-_]+)$")
+ #match_mirror_line = re.compile(r".+")
+
if not dist:
pipe = os.popen("lsb_release -i -s")
dist = pipe.read().strip()
@@ -184,18 +194,20 @@ class DistInfo:
if not map_mirror_sets.has_key(value):
mirror_set = {}
try:
- mirrors = map(split_url,
- filter(lambda s: s != "" and
- not s.startswith("#"),
- map(string.strip, open(value))))
+ mirror_data = filter(match_mirror_line.match,
+ map(string.strip, open(value)))
except:
print "ERROR: Failed to read mirror file"
mirrors = []
- for m in mirrors:
- if mirror_set.has_key(m[1]):
- mirror_set[m[1]].add_repository(m[0],m[2])
+ for line in mirror_data:
+ if line.startswith("#LOC:"):
+ location = match_loc.sub(r"\1", line)
+ continue
+ (proto, hostname, dir) = split_url(line)
+ if mirror_set.has_key(hostname):
+ mirror_set[hostname].add_repository(proto, dir)
else:
- mirror_set[m[1]] = Mirror(m)
+ mirror_set[hostname] = Mirror(proto, hostname, dir, location)
map_mirror_sets[value] = mirror_set
suite.mirror_set = map_mirror_sets[value]
elif field == 'Description':
diff --git a/AptSources/aptsources.py b/AptSources/aptsources.py
index 2b1b70e9..457e13f2 100644
--- a/AptSources/aptsources.py
+++ b/AptSources/aptsources.py
@@ -713,7 +713,7 @@ class UbuntuDistribution(Distribution):
lines = f.readlines()
for line in lines:
parts = line.split("\t")
- self.countries[parts[0].lower()] = parts[1]
+ self.countries[parts[0].lower()] = parts[1].strip()
except:
print "could not open file '%s'" % file
else:
@@ -721,6 +721,7 @@ class UbuntuDistribution(Distribution):
# try to guess the nearest mirror from the locale
self.country = None
+ self.country_code = None
locale = os.getenv("LANG", default="en.UK")
a = locale.find("_")
z = locale.find(".")
@@ -731,6 +732,7 @@ class UbuntuDistribution(Distribution):
country_code
if self.countries.has_key(country_code):
self.country = self.countries[country_code]
+ self.country_code = country_code
def get_server_list(self):
''' Return a list of used and suggested servers '''