예제 #1
0
    def setUp(self, reset=False):
        import tempfile
        self.dir = tempfile.mkdtemp('debian-live')
        os.makedirs(os.path.join(self.dir, 'config'))

        self.filename = os.path.join(self.dir, 'config', self.name)
        f = open(self.filename, 'w+')
        f.write(self.initial)
        f.close()

        self.key_var = KeyVar(self.dir, self.name, self.spec)
예제 #2
0
class TestSimple(TestKeyVar):
    def testSetAndGetOption(self):
        self.key_var['LH_SPAM'] = 'eggs'
        self.assertEqual(self.key_var['LH_SPAM'], 'eggs')

    def testSetAndGetOptionSpecifyFilename(self):
        self.key_var = KeyVar('/', 'dummy', self.spec, filename=self.filename)
        self.key_var['LH_SPAM'] = 'eggs'
        self.assertEqual(self.key_var['LH_SPAM'], 'eggs')

    def testSaveKnownOption(self):
        self.key_var['LH_SPAM'] = 'new value'
        self.key_var.save()
        self.assert_('LH_SPAM="new value"' in self.f_c())

    def testSaveKnownOptionNoChange(self):
        before = self.f_c()
        self.key_var['LH_SPAM'] = 'eggs'
        self.key_var.save()
        self.assertEqual(before, self.f_c())

    def testSaveUnknownOption(self):
        """
        Unknown configuration keys should be added to the file.
        """
        self.key_var['LH_UNKNOWN_OPTION'] = 'spam'
        self.key_var.save()
        self.assert_('LH_UNKNOWN_OPTION="spam"' in self.f_c())

    def testSaveUnknownOptionNewSize(self):
        len_before = len(self.f_c())
        self.key_var['LH_UKNOWN_OPTION'] = 'new value'
        self.key_var.save()
        self.assert_(len(self.f_c()) > len_before)

    def testSaveNoChanges(self):
        self.key_var.save()
예제 #3
0
class TestSimple(TestKeyVar):
    def testSetAndGetOption(self):
        self.key_var['LB_SPAM'] = 'eggs'
        self.assertEqual(self.key_var['LB_SPAM'], 'eggs')

    def testSetAndGetOptionSpecifyFilename(self):
        self.key_var = KeyVar('/', 'dummy', self.spec, filename=self.filename)
        self.key_var['LB_SPAM'] = 'eggs'
        self.assertEqual(self.key_var['LB_SPAM'], 'eggs')

    def testSaveKnownOption(self):
        self.key_var['LB_SPAM'] = 'new value'
        self.key_var.save()
        self.assert_('LB_SPAM="new value"' in self.f_c())

    def testSaveKnownOptionNoChange(self):
        before = self.f_c()
        self.key_var['LB_SPAM'] = 'eggs'
        self.key_var.save()
        self.assertEqual(before, self.f_c())

    def testSaveUnknownOption(self):
        """
        Unknown configuration keys should be added to the file.
        """
        self.key_var['LB_UNKNOWN_OPTION'] = 'spam'
        self.key_var.save()
        self.assert_('LB_UNKNOWN_OPTION="spam"' in self.f_c())

    def testSaveUnknownOptionNewSize(self):
        len_before = len(self.f_c())
        self.key_var['LB_UKNOWN_OPTION'] = 'new value'
        self.key_var.save()
        self.assert_(len(self.f_c()) > len_before)

    def testSaveNoChanges(self):
        self.key_var.save()
예제 #4
0
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():
                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
예제 #5
0
 def testSetAndGetOptionSpecifyFilename(self):
     self.key_var = KeyVar('/', 'dummy', self.spec, filename=self.filename)
     self.key_var['LH_SPAM'] = 'eggs'
     self.assertEqual(self.key_var['LH_SPAM'], 'eggs')
예제 #6
0
    def __init__(self):
        self.asst = gtk.Assistant()
        self.asst.set_title(_('Debian Live Magic'))
        self.asst.set_default_size(640, 480)
        self.asst.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
        self.asst.set_position(gtk.WIN_POS_CENTER)

        self.asst.connect('apply', self.controller.on_wizard_apply)
        self.asst.connect('cancel', self.controller.on_wizard_cancel)

        def add_about_button():
            label = gtk.Label(_('About'))
            label.show()

            image = gtk.Image()
            image.set_from_stock(gtk.STOCK_ABOUT, gtk.ICON_SIZE_BUTTON)
            image.show()

            vbox = gtk.HBox(spacing=4)
            vbox.add(label)
            vbox.add(image)
            vbox.show()

            btn = gtk.Button()
            btn.add(vbox)
            btn.connect('clicked', self.controller.on_about_request)
            btn.show()

            self.asst.add_action_widget(btn)
        add_about_button()

        # Load paages from Glade resource file.
        notebook = self['notebook_wizard']
        page_types = [gtk.ASSISTANT_PAGE_INTRO] + \
            [gtk.ASSISTANT_PAGE_CONTENT] * (notebook.get_n_pages() - 2) + \
            [gtk.ASSISTANT_PAGE_CONFIRM]

        hide_distribution = False
        try:
            f = open('/etc/debian_version')
            if f.read(3) == "5.0":
                hide_distribution = True
            f.close()
        except:
            pass

        for i in range(notebook.get_n_pages()):
            if i == 2 and hide_distribution:
                # Hide distribution when running Lenny as stable.
                continue

            if i == 5 and self.controller.get_host_architecture() != 'amd64':
                # Only show architecture page if using amd64
                continue

            page = notebook.get_nth_page(i)
            page.unparent()
            self.asst.append_page(page)
            self.asst.set_page_complete(page, True)
            self.asst.set_page_type(page, page_types[i])

            self.asst.set_page_title(page, notebook.get_tab_label_text(page))

        c = self['combobox_mirror']
        c.prepend_text(get_mirror())
        c.set_active(0)

        c = self['combo_net_root_filesystem']
        c.append_text('NFS')
        c.append_text('CIFS')
        c.set_active(0)

        c = self['combo_locale']
        c.set_active(0)
        match = os.environ.get('LANG', 'en_US.UTF-8')
        found = False
        for idx, locale in enumerate(self.controller.get_locales()):
            c.append_text(locale)

            if found:
                continue

            if locale.replace('-', '_') == match.replace('-', '_'):
                c.set_active(idx)
                found = True
            elif match.startswith(locale):
                c.set_active(idx)

        c = self['combo_keyboard']
        match = None

        try:
            kv = KeyVar('/etc/default', 'console-setup', {}, filename='/etc/default/console-setup')
            match = kv.get('XKBLAYOUT')
        except IOError:
            pass

        pat = re.compile(r'\s*Option\s*"XkbLayout"\s*"([^"]+)"')
        try:
            xorgconf = file('/etc/X11/xorg.conf')
            for line in xorgconf:
                m = pat.match(line)
                if m:
                    match = m.group(1)
        except IOError:
            pass

        if match is None:
            match = "us"
        elif match == 'gb':
            match = 'uk'

        for idx, layout in enumerate(self.controller.get_keyboard_layouts()):
            code, name = layout
            c.append_text('%s (%s)' % (name, code.upper()))
            if code == match:
                c.set_active(idx)

        server = '192.168.1.1'
        path = '/srv/debian-live'
        try:
            kv = KeyVar('/etc/live', 'build.conf', {}, filename='/etc/live/build.conf')
            server = kv.get('LB_NET_ROOT_SERVER', server)
            path = kv.get('LB_NET_ROOT_PATH', path)
        except IOError:
            pass
        self['entry_net_root_server'].set_text(server)
        self['entry_net_root_path'].set_text(path)

        f = self['filechooser_build_directory']
        f.set_uri(self.controller.get_homedir())
예제 #7
0
    def __init__(self):
        self.asst = gtk.Assistant()
        self.asst.set_title(_('Debian Live Magic'))
        self.asst.set_default_size(640, 480)
        self.asst.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
        self.asst.set_position(gtk.WIN_POS_CENTER)

        self.asst.connect('apply', self.controller.on_wizard_apply)
        self.asst.connect('cancel', self.controller.on_wizard_cancel)

        def add_about_button():
            label = gtk.Label(_('About'))
            label.show()

            image = gtk.Image()
            image.set_from_stock(gtk.STOCK_ABOUT, gtk.ICON_SIZE_BUTTON)
            image.show()

            vbox = gtk.HBox(spacing=4)
            vbox.add(label)
            vbox.add(image)
            vbox.show()

            btn = gtk.Button()
            btn.add(vbox)
            btn.connect('clicked', self.controller.on_about_request)
            btn.show()

            self.asst.add_action_widget(btn)

        add_about_button()

        # Load paages from Glade resource file.
        notebook = self['notebook_wizard']
        page_types = [gtk.ASSISTANT_PAGE_INTRO] + \
            [gtk.ASSISTANT_PAGE_CONTENT] * (notebook.get_n_pages() - 2) + \
            [gtk.ASSISTANT_PAGE_CONFIRM]

        hide_distribution = False
        try:
            f = open('/etc/debian_version')
            if f.read(3) == "5.0":
                hide_distribution = True
            f.close()
        except:
            pass

        for i in range(notebook.get_n_pages()):
            if i == 2 and hide_distribution:
                # Hide distribution when running Lenny as stable.
                continue

            if i == 5 and self.controller.get_host_architecture() != 'amd64':
                # Only show architecture page if using amd64
                continue

            page = notebook.get_nth_page(i)
            page.unparent()
            self.asst.append_page(page)
            self.asst.set_page_complete(page, True)
            self.asst.set_page_type(page, page_types[i])

            self.asst.set_page_title(page, notebook.get_tab_label_text(page))

        c = self['combobox_mirror']
        c.prepend_text(get_mirror())
        c.set_active(0)

        c = self['combo_net_root_filesystem']
        c.append_text('NFS')
        c.append_text('CIFS')
        c.set_active(0)

        c = self['combo_locale']
        c.set_active(0)
        match = os.environ.get('LANG', 'en_US.UTF-8')
        found = False
        for idx, locale in enumerate(self.controller.get_locales()):
            c.append_text(locale)

            if found:
                continue

            if locale.replace('-', '_') == match.replace('-', '_'):
                c.set_active(idx)
                found = True
            elif match.startswith(locale):
                c.set_active(idx)

        c = self['combo_keyboard']
        match = None

        try:
            kv = KeyVar('/etc/default',
                        'console-setup', {},
                        filename='/etc/default/console-setup')
            match = kv.get('XKBLAYOUT')
        except IOError:
            pass

        pat = re.compile(r'\s*Option\s*"XkbLayout"\s*"([^"]+)"')
        try:
            xorgconf = file('/etc/X11/xorg.conf')
            for line in xorgconf:
                m = pat.match(line)
                if m:
                    match = m.group(1)
        except IOError:
            pass

        if match is None:
            match = "us"
        elif match == 'gb':
            match = 'uk'

        for idx, layout in enumerate(self.controller.get_keyboard_layouts()):
            code, name = layout
            c.append_text('%s (%s)' % (name, code.upper()))
            if code == match:
                c.set_active(idx)

        server = '192.168.1.1'
        path = '/srv/debian-live'
        try:
            kv = KeyVar('/etc/default',
                        'live-helper', {},
                        filename='/etc/default/live-helper')
            server = kv.get('LH_NET_ROOT_SERVER', server)
            path = kv.get('LH_NET_ROOT_PATH', path)
        except IOError:
            pass
        self['entry_net_root_server'].set_text(server)
        self['entry_net_root_path'].set_text(path)

        f = self['filechooser_build_directory']
        f.set_uri(self.controller.get_homedir())
예제 #8
0
 def testSetAndGetOptionSpecifyFilename(self):
     self.key_var = KeyVar('/', 'dummy', self.spec, filename=self.filename)
     self.key_var['LB_SPAM'] = 'eggs'
     self.assertEqual(self.key_var['LB_SPAM'], 'eggs')