[SCM] GUI front-end for Debian Live. branch, master, updated. f258fc784ecaebf66921d8ec77d7bc46a74e9506
Chris Lamb
chris at chris-lamb.co.uk
Thu Jul 10 23:52:35 UTC 2008
The following commit has been merged in the master branch:
commit b4c7b7e4aac97fed48154ab66f0acce9f0017e29
Author: Chris Lamb <chris at chris-lamb.co.uk>
Date: Thu Jul 10 22:27:38 2008 +0100
Read default mirror from /etc/default/live-helper if it exists.
Signed-off-by: Chris Lamb <chris at chris-lamb.co.uk>
diff --git a/DebianLive/elements/key_var.py b/DebianLive/elements/key_var.py
index 5e155ad..5ecd65d 100644
--- a/DebianLive/elements/key_var.py
+++ b/DebianLive/elements/key_var.py
@@ -21,12 +21,16 @@ class KeyVar(dict):
def __new__(cls, *args, **kwargs):
return dict.__new__(cls, *args, **kwargs)
- def __init__(self, dir, name, spec):
- self.filename = os.path.join(dir, 'config', name)
-
+ def __init__(self, dir, name, spec, filename=None):
self.line_numbers = {}
self.stale = set()
+ if filename is None:
+ self.filename = os.path.join(dir, 'config', name)
+ else:
+ self.filename = filename
+
+
f = open(self.filename, 'r')
try:
line_no = 0
diff --git a/DebianLive/utils/__init__.py b/DebianLive/utils/__init__.py
index 71d5b3e..bcaf45c 100644
--- a/DebianLive/utils/__init__.py
+++ b/DebianLive/utils/__init__.py
@@ -1,2 +1,2 @@
-from sources_list import get_mirror
from list_observer import ListObserver
+from sources_list import get_mirror
diff --git a/DebianLive/utils/sources_list.py b/DebianLive/utils/sources_list.py
index e71ecaf..069f325 100644
--- a/DebianLive/utils/sources_list.py
+++ b/DebianLive/utils/sources_list.py
@@ -1,6 +1,8 @@
import os
import re
+from DebianLive.elements import KeyVar
+
__all__ = ['get_mirror']
COMMENTS = re.compile(r'\s*#')
@@ -14,35 +16,45 @@ REJECT_PATTERNS = (
re.compile(r'security\.'),
)
-def get_mirror(fallback='http://www.us.debian.org/', sources_list='/etc/apt/sources.list'):
+def get_mirror(fallback='http://www.us.debian.org/', sources_list='/etc/apt/sources.list', defaults='/etc/default/live-helper'):
result = fallback
+ def filter_mirror(line):
+ if COMMENTS.match(line):
+ return False
+
+ for pat in REJECT_PATTERNS:
+ m = pat.search(line)
+ if m:
+ return False
+
+ for pat in PATTERNS:
+ m = pat.search(line)
+ if m:
+ return m.group(0)
+
+ return False
+
try:
f = open(sources_list, 'r')
-
try:
for line in f.readlines():
- if COMMENTS.match(line):
- continue
-
- flag = False
- for pat in REJECT_PATTERNS:
- m = pat.search(line)
- if m:
- flag = True
- break
- if flag:
- continue
-
- for pat in PATTERNS:
- m = pat.search(line)
- if not m:
- continue
-
- result = m.group(0)
+ mirror = filter_mirror(line)
+ if mirror:
+ result = mirror
+ break
finally:
f.close()
except IOError:
pass
+ if defaults:
+ try:
+ kv = KeyVar('/etc/default', 'live-helper', {}, filename=defaults)
+ kv_mirror = filter_mirror(kv['LH_MIRROR_BOOTSTRAP'])
+ if kv_mirror:
+ return kv_mirror
+ except:
+ pass
+
return result
diff --git a/tests/test_sources_list.py b/tests/test_sources_list.py
index fb7b84c..cc4070e 100755
--- a/tests/test_sources_list.py
+++ b/tests/test_sources_list.py
@@ -28,7 +28,7 @@ class TestSourcesList(unittest.TestCase):
class TestMatch(TestSourcesList):
def assertMatchLine(self, line):
self.f_w(line)
- self.assert_(get_mirror(None, sources_list=self.filename))
+ self.assert_(get_mirror(None, sources_list=self.filename, defaults=None))
def testCountryDebianMirror(self):
self.assertMatchLine('deb http://ftp.uk.debian.org/debian stable main')
@@ -45,7 +45,7 @@ class TestMatch(TestSourcesList):
class TestNoMatch(TestSourcesList):
def assertNoMatchLine(self, line):
self.f_w(line)
- self.failIf(get_mirror(None, sources_list=self.filename))
+ self.failIf(get_mirror(None, sources_list=self.filename, defaults=None))
def testComments(self):
self.assertNoMatchLine('# comment')
@@ -58,7 +58,7 @@ class TestNoMatch(TestSourcesList):
class TestErrors(TestSourcesList):
def testFileNotFound(self):
- self.failIf(get_mirror(None, sources_list='/proc/invisible-file'))
+ self.failIf(get_mirror(None, sources_list='/proc/invisible-file', defaults=None))
"""
# Not implemented yet
--
GUI front-end for Debian Live.
More information about the debian-live-changes
mailing list