[SCM] GUI front-end for Debian Live. branch, master, updated. f258fc784ecaebf66921d8ec77d7bc46a74e9506
Chris Lamb
chris at chris-lamb.co.uk
Thu Jul 10 23:52:34 UTC 2008
The following commit has been merged in the master branch:
commit d48dd6e46006e077c708e1ea44319938b7cad7a2
Author: Chris Lamb <chris at chris-lamb.co.uk>
Date: Thu Jul 10 22:54:49 2008 +0100
Don't wrap sources_list in a stateful object.
Signed-off-by: Chris Lamb <chris at chris-lamb.co.uk>
diff --git a/DebianLive/utils/__init__.py b/DebianLive/utils/__init__.py
index 764dfe2..71d5b3e 100644
--- a/DebianLive/utils/__init__.py
+++ b/DebianLive/utils/__init__.py
@@ -1,2 +1,2 @@
-from sources_list import SourcesList
+from sources_list import get_mirror
from list_observer import ListObserver
diff --git a/DebianLive/utils/sources_list.py b/DebianLive/utils/sources_list.py
index 4f7193a..e71ecaf 100644
--- a/DebianLive/utils/sources_list.py
+++ b/DebianLive/utils/sources_list.py
@@ -1,50 +1,48 @@
import os
import re
-class SourcesList(object):
- comments = re.compile(r'\s*#')
- patterns = (
- re.compile(r'http://ftp.?\..{2}\.debian\.org[^\s]*'),
- re.compile(r'http://(localhost|127\.0\.0\.1)[^\s]*'),
- re.compile(r'http://[^\s]*'),
- )
- reject_patterns = (
- re.compile(r'backports\.'),
- re.compile(r'security\.'),
- )
-
- def __init__(self, filename='/etc/apt/sources.list'):
- self.filename = filename
-
- def get_mirror(self, fallback='http://www.us.debian.org/'):
- result = fallback
+__all__ = ['get_mirror']
- try:
- f = open(self.filename, 'r')
+COMMENTS = re.compile(r'\s*#')
+PATTERNS = (
+ re.compile(r'http://ftp.?\..{2}\.debian\.org[^\s]*'),
+ re.compile(r'http://(localhost|127\.0\.0\.1)[^\s]*'),
+ re.compile(r'http://[^\s]*'),
+)
+REJECT_PATTERNS = (
+ re.compile(r'backports\.'),
+ re.compile(r'security\.'),
+)
- try:
- for line in f.readlines():
- if self.comments.match(line):
- continue
+def get_mirror(fallback='http://www.us.debian.org/', sources_list='/etc/apt/sources.list'):
+ result = fallback
- flag = False
- for pat in self.reject_patterns:
- m = pat.search(line)
- if m:
- flag = True
- break
- if flag:
- continue
+ try:
+ f = open(sources_list, 'r')
- for pat in self.patterns:
- m = pat.search(line)
- if not m:
- continue
+ 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)
- finally:
- f.close()
- except IOError:
- pass
+ result = m.group(0)
+ finally:
+ f.close()
+ except IOError:
+ pass
- return result
+ return result
diff --git a/LiveMagic/controllers/wizard.py b/LiveMagic/controllers/wizard.py
index 7f15764..a56a189 100644
--- a/LiveMagic/controllers/wizard.py
+++ b/LiveMagic/controllers/wizard.py
@@ -9,7 +9,6 @@ import subprocess
from LiveMagic import utils
from DebianLive import Config
-from DebianLive.utils import SourcesList
class WizardController(object):
def on_wizard_apply(self, _):
@@ -74,9 +73,6 @@ class WizardController(object):
threading.Thread(target=gain_superuser).start()
- def get_suggested_mirror(self):
- return SourcesList().get_mirror()
-
def on_wizard_cancel(self, *args):
if self.view.do_show_wizard_cancel_confirm_window():
gtk.main_quit()
diff --git a/LiveMagic/views/wizard.py b/LiveMagic/views/wizard.py
index bf66d50..bce05ca 100644
--- a/LiveMagic/views/wizard.py
+++ b/LiveMagic/views/wizard.py
@@ -1,5 +1,7 @@
import gtk
+from DebianLive.utils import get_mirror
+
class WizardView(object):
def __init__(self):
self.asst = gtk.Assistant()
@@ -53,7 +55,7 @@ class WizardView(object):
self.asst.set_page_title(page, notebook.get_tab_label_text(page))
c = self['combobox_mirror']
- c.prepend_text(self.controller.get_suggested_mirror())
+ c.prepend_text(get_mirror())
c.set_active(0)
f = self['filechooser_build_directory']
diff --git a/tests/test_sources_list.py b/tests/test_sources_list.py
index eafc076..fb7b84c 100755
--- a/tests/test_sources_list.py
+++ b/tests/test_sources_list.py
@@ -6,14 +6,13 @@ import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-from DebianLive.utils import SourcesList
+from DebianLive.utils import get_mirror
class TestSourcesList(unittest.TestCase):
def setUp(self):
import tempfile
fd, self.filename = tempfile.mkstemp('live-magic')
os.close(fd)
- self.s = SourcesList(self.filename)
def tearDown(self):
try:
@@ -29,7 +28,7 @@ class TestSourcesList(unittest.TestCase):
class TestMatch(TestSourcesList):
def assertMatchLine(self, line):
self.f_w(line)
- self.assert_(self.s.get_mirror(None))
+ self.assert_(get_mirror(None, sources_list=self.filename))
def testCountryDebianMirror(self):
self.assertMatchLine('deb http://ftp.uk.debian.org/debian stable main')
@@ -46,7 +45,7 @@ class TestMatch(TestSourcesList):
class TestNoMatch(TestSourcesList):
def assertNoMatchLine(self, line):
self.f_w(line)
- self.failIf(self.s.get_mirror(None))
+ self.failIf(get_mirror(None, sources_list=self.filename))
def testComments(self):
self.assertNoMatchLine('# comment')
@@ -59,9 +58,7 @@ class TestNoMatch(TestSourcesList):
class TestErrors(TestSourcesList):
def testFileNotFound(self):
- self.filename = '/proc/invisible-file'
- self.s = SourcesList(self.filename)
- self.failIf(self.s.get_mirror(None))
+ self.failIf(get_mirror(None, sources_list='/proc/invisible-file'))
"""
# Not implemented yet
--
GUI front-end for Debian Live.
More information about the debian-live-changes
mailing list