[SCM] GUI front-end for Debian Live. branch, master, updated. d6ae12437ff380db2b87363283adc42142dc4637
Chris Lamb
chris at chris-lamb.co.uk
Fri Apr 11 02:13:59 UTC 2008
The following commit has been merged in the master branch:
commit dedbf21f7e25f9c3ff631ec20d7150952231ea09
Author: Chris Lamb <chris at chris-lamb.co.uk>
Date: Fri Apr 11 01:18:56 2008 +0100
sources_list.py: Improve error handling and tests
Signed-off-by: Chris Lamb <chris at chris-lamb.co.uk>
diff --git a/DebianLive/utils/sources_list.py b/DebianLive/utils/sources_list.py
index a84f00d..4f7193a 100644
--- a/DebianLive/utils/sources_list.py
+++ b/DebianLive/utils/sources_list.py
@@ -13,20 +13,15 @@ class SourcesList(object):
re.compile(r'security\.'),
)
- def __init__(self, filename=None):
- if filename is None:
- filename = r'/etc/apt/sources.list'
-
+ def __init__(self, filename='/etc/apt/sources.list'):
self.filename = filename
- def get_mirror(self, fallback=None):
- if fallback is not None:
- fallback = 'http://www.us.debian.org/'
-
+ def get_mirror(self, fallback='http://www.us.debian.org/'):
result = fallback
- f = open(self.filename, 'r')
try:
+ f = open(self.filename, 'r')
+
try:
for line in f.readlines():
if self.comments.match(line):
diff --git a/tests/test_sources_list.py b/tests/test_sources_list.py
index 31fc3cd..eafc076 100755
--- a/tests/test_sources_list.py
+++ b/tests/test_sources_list.py
@@ -16,7 +16,10 @@ class TestSourcesList(unittest.TestCase):
self.s = SourcesList(self.filename)
def tearDown(self):
- os.unlink(self.filename)
+ try:
+ os.unlink(self.filename)
+ except OSError:
+ pass
def f_w(self, contents):
f = open(self.filename, 'w+')
@@ -45,12 +48,21 @@ class TestNoMatch(TestSourcesList):
self.f_w(line)
self.failIf(self.s.get_mirror(None))
+ def testComments(self):
+ self.assertNoMatchLine('# comment')
+
def testSecurity(self):
self.assertNoMatchLine('deb http://security.debian.org/debian stable main')
def testBackports(self):
self.assertNoMatchLine('deb http://backports.debian.org/debian stable main')
+class TestErrors(TestSourcesList):
+ def testFileNotFound(self):
+ self.filename = '/proc/invisible-file'
+ self.s = SourcesList(self.filename)
+ self.failIf(self.s.get_mirror(None))
+
"""
# Not implemented yet
--
GUI front-end for Debian Live.
More information about the debian-live-changes
mailing list