コード例 #1
0
    def prepare(self, unfiltered=False):
        self.preseed('console-setup/ask_detect', 'false')

        # We need to get rid of /etc/default/keyboard, or console-setup will
        # think it's already configured and behave differently. Try to save
        # the old file for interest's sake, but it's not a big deal if we
        # can't.
        with misc.raised_privileges():
            osextras.unlink_force('/etc/default/keyboard.pre-ubiquity')
            try:
                os.rename('/etc/default/keyboard',
                          '/etc/default/keyboard.pre-ubiquity')
            except OSError:
                osextras.unlink_force('/etc/default/keyboard')
        # Make sure debconf doesn't do anything with crazy "preseeded"
        # answers to these questions. If you want to preseed these, use the
        # *code variants.
        self.db.fset('keyboard-configuration/layout', 'seen', 'false')
        self.db.fset('keyboard-configuration/variant', 'seen', 'false')
        self.db.fset('keyboard-configuration/model', 'seen', 'false')
        self.db.fset('console-setup/codeset47', 'seen', 'false')

        # Roughly taken from console-setup's config.proto:
        di_locale = self.db.get('debian-installer/locale')
        ret = di_locale.rsplit('.', 1)[0]
        if not keyboard_names.has_language(ret):
            self.debug("No keyboard layout translations for locale '%s'" % ret)
            ret = ret.rsplit('_', 1)[0]
        if not keyboard_names.has_language(ret):
            self.debug("No keyboard layout translations for locale '%s'" % ret)
            # TODO should this be C.UTF-8?!
            ret = 'C'
        self._locale = ret

        self.has_variants = False

        # Technically we should provide a version as the second argument,
        # but that isn't currently needed and it would require querying
        # apt/dpkg for the current version, which would be slow, so we don't
        # bother for now.
        command = [
            '/usr/lib/ubiquity/console-setup/keyboard-configuration.postinst',
            'configure',
        ]
        questions = [
            '^keyboard-configuration/layout',
            '^keyboard-configuration/variant',
            '^keyboard-configuration/model',
            '^keyboard-configuration/altgr$',
            '^keyboard-configuration/unsupported_',
        ]
        environ = {
            'OVERRIDE_ALLOW_PRESEEDING': '1',
            'OVERRIDE_USE_DEBCONF_LOCALE': '1',
            'LC_ALL': di_locale,
            'PATH': '/usr/lib/ubiquity/console-setup:' + os.environ['PATH'],
            'DPKG_MAINTSCRIPT_NAME': 'postinst',
            'DPKG_MAINTSCRIPT_PACKAGE': 'keyboard-configuration',
        }
        return command, questions, environ
コード例 #2
0
ファイル: ubi-language.py プロジェクト: DirkHaar/ubiquity
    def prepare(self, unfiltered=False):
        self.language_question = None
        self.initial_language = None
        self.db.fset('localechooser/languagelist', 'seen', 'false')
        with misc.raised_privileges():
            osextras.unlink_force('/var/lib/localechooser/preseeded')
            osextras.unlink_force('/var/lib/localechooser/langlevel')
        if self.ui.controller.oem_config:
            try:
                self.ui.set_oem_id(self.db.get('oem-config/id'))
            except debconf.DebconfError:
                pass

        localechooser_script = '/usr/lib/ubiquity/localechooser/localechooser'
        if ('UBIQUITY_FRONTEND' in os.environ
                and os.environ['UBIQUITY_FRONTEND'] == 'debconf_ui'):
            localechooser_script += '-debconf'

        questions = ['localechooser/languagelist']
        environ = {
            'PATH': '/usr/lib/ubiquity/localechooser:' + os.environ['PATH'],
        }
        if ('UBIQUITY_FRONTEND' in os.environ
                and os.environ['UBIQUITY_FRONTEND'] == "debconf_ui"):
            environ['TERM_FRAMEBUFFER'] = '1'
        else:
            environ['OVERRIDE_SHOW_ALL_LANGUAGES'] = '1'
        return localechooser_script, questions, environ
コード例 #3
0
    def __init__(self, distro):
        BaseFrontend.__init__(self, distro)

        with misc.raised_privileges():
            self.console = open('/dev/console', 'w')
        if not self.console:
            self.console = sys.stdout  # better than crashing
        self.installing = False
        self.progress_position = ubiquity.progressposition.ProgressPosition()
        self.progress_val = 0
        self.progress_info = ''
        self.mainloop = GObject.MainLoop()

        self.pages = []
        for mod in self.modules:
            if hasattr(mod.module, 'PageNoninteractive'):
                mod.controller = ubiquity.frontend.base.Controller(self)
                mod.ui_class = mod.module.PageNoninteractive
                mod.ui = mod.ui_class(mod.controller)
                self.pages.append(mod)

        i18n.reset_locale(self)

        if self.oem_config:
            misc.execute_root('apt-install', 'oem-config-gtk')
コード例 #4
0
    def save_to(self, path):
        pb = self.selected_image.get_pixbuf()
        if not pb:
            return False

        d = os.path.dirname(path)
        with misc.raised_privileges():
            if not os.path.exists(d):
                os.makedirs(d)
            pb.savev(path, 'png', [], [])
コード例 #5
0
 def big_enough(self, size):
     with misc.raised_privileges():
         proc = subprocess.Popen(['parted_devices'], stdout=subprocess.PIPE)
         devices = proc.communicate()[0].rstrip('\n').split('\n')
         ret = False
         for device in devices:
             if device and int(device.split('\t')[1]) > size:
                 ret = True
                 break
     return ret
コード例 #6
0
 def free_space(self):
     biggest = 0
     with misc.raised_privileges():
         proc = subprocess.Popen(
             ['parted_devices'],
             stdout=subprocess.PIPE, universal_newlines=True)
         devices = proc.communicate()[0].rstrip('\n').split('\n')
         for device in devices:
             if device and int(device.split('\t')[1]) > biggest:
                 biggest = int(device.split('\t')[1])
     return biggest
コード例 #7
0
ファイル: ubi-prepare.py プロジェクト: pombreda/OnionScraper
 def ok_handler(self):
     download_updates = self.ui.get_download_updates()
     use_nonfree = self.ui.get_use_nonfree()
     self.preseed_bool('ubiquity/use_nonfree', use_nonfree)
     self.preseed_bool('ubiquity/download_updates', download_updates)
     if use_nonfree:
         with misc.raised_privileges():
             # Install ubuntu-restricted-addons.
             self.preseed_bool('apt-setup/universe', True)
             self.preseed_bool('apt-setup/multiverse', True)
             if self.db.fget('ubiquity/nonfree_package', 'seen') != 'true':
                 self.preseed('ubiquity/nonfree_package',
                              self.ui.restricted_package_name)
     plugin.Plugin.ok_handler(self)
コード例 #8
0
ファイル: ubi-prepare.py プロジェクト: DirkHaar/ubiquity
 def ok_handler(self):
     download_updates = False
     minimal_install = self.ui.get_minimal_install()
     use_nonfree = self.ui.get_use_nonfree()
     secureboot_key = self.ui.get_secureboot_key()
     self.preseed_bool('ubiquity/use_nonfree', use_nonfree)
     self.preseed_bool('ubiquity/download_updates', download_updates)
     self.preseed_bool('ubiquity/minimal_install', minimal_install)
     if self.ui.using_secureboot and secureboot_key:
         self.preseed('ubiquity/secureboot_key', secureboot_key, seen=True)
     if use_nonfree:
         with misc.raised_privileges():
             # Install ubuntu-restricted-addons.
             self.preseed_bool('apt-setup/universe', True)
             self.preseed_bool('apt-setup/multiverse', True)
             if self.db.fget('ubiquity/nonfree_package', 'seen') != 'true':
                 self.preseed('ubiquity/nonfree_package',
                              self.ui.restricted_package_name)
     plugin.Plugin.ok_handler(self)
コード例 #9
0
    def __init__(self, controller, *args, **kwargs):
        self.controller = controller
        rpart = magic.find_partition()
        dvd, usb = magic.find_burners()
        oem = 'UBIQUITY_OEM_USER_CONFIG' in os.environ
        with misc.raised_privileges():
            self.genuine = magic.check_vendor()
        if oem and (dvd or usb) and (rpart or not self.genuine):
            try:
                gi.require_version('Gtk', '3.0')
                from gi.repository import Gtk
                builder = Gtk.Builder()
                builder.add_from_file(
                    '/usr/share/ubiquity/gtk/stepRecoveryMedia.ui')
                builder.connect_signals(self)
                self.controller.add_builder(builder)
                self.plugin_widgets = builder.get_object('stepRecoveryMedia')
                self.usb_media = builder.get_object('save_to_usb')
                self.dvd_media = builder.get_object('save_to_dvd')
                self.none_media = builder.get_object('save_to_none')
                self.grub_menu_98 = builder.get_object('98_grub_menu')
                self.grub_menu_99 = builder.get_object('99_grub_menu')
                if not dvd:
                    builder.get_object('dvd_box').hide()
                if not usb:
                    builder.get_object('usb_box').hide()
                if not self.genuine:
                    builder.get_object('usb_box').hide()
                    builder.get_object('dvd_box').hide()
                    builder.get_object('none_box').hide()
                    builder.get_object('genuine_box').show()
            except Exception as err:
                syslog.syslog('Could not create Dell Recovery page: %s', err)
                self.plugin_widgets = None
        else:
            if not oem:
                pass
            elif not rpart:
                syslog.syslog('%s: partition problems with  rp[%s]' %
                              (NAME, rpart))
            self.plugin_widgets = None

        PluginUI.__init__(self, controller, *args, **kwargs)
コード例 #10
0
 def ok_handler(self):
     download_updates = self.ui.get_download_updates()
     use_nonfree = self.ui.get_use_nonfree()
     self.preseed_bool('ubiquity/use_nonfree', use_nonfree)
     self.preseed_bool('ubiquity/download_updates', download_updates)
     if use_nonfree:
         with misc.raised_privileges():
             # Install ubuntu-restricted-addons.
             self.preseed_bool('apt-setup/universe', True)
             self.preseed_bool('apt-setup/multiverse', True)
             if self.db.fget('ubiquity/nonfree_package', 'seen') != 'true':
                 self.preseed('ubiquity/nonfree_package',
                              self.ui.restricted_package_name)
             bus = dbus.SystemBus()
             obj = bus.get_object(JOCKEY, JOCKEY_PATH)
             i = dbus.Interface(obj, JOCKEY)
             i.shutdown(timeout=MAX_DBUS_TIMEOUT)
             env = os.environ.copy()
             env['DEBCONF_DB_REPLACE'] = 'configdb'
             env['DEBCONF_DB_OVERRIDE'] = 'Pipe{infd:none outfd:none}'
             subprocess.Popen(
                 ['/usr/share/jockey/jockey-backend', '--timeout=120'],
                 env=env)
     plugin.Plugin.ok_handler(self)
コード例 #11
0
def get_languages(current_language_index=-1, only_installable=False):
    import gzip
    import icu

    current_language = "English"

    if only_installable:
        from apt.cache import Cache
        # workaround for an issue where euid != uid and the
        # apt cache has not yet been loaded causing a SystemError
        # when libapt-pkg tries to load the Cache the first time.
        with misc.raised_privileges():
            cache = Cache()

    languagelist = gzip.open(
        '/usr/lib/ubiquity/localechooser/languagelist.data.gz')
    language_display_map = {}
    i = 0
    for line in languagelist:
        line = misc.utf8(line)
        if line == '' or line == '\n':
            continue
        code, name, trans = line.strip('\n').split(':')[1:]
        if code in ('C', 'dz', 'km'):
            i += 1
            continue
        # KDE fails to round-trip strings containing U+FEFF ZERO WIDTH
        # NO-BREAK SPACE, and we don't care about the NBSP anyway, so strip
        # it.
        #   https://bugs.launchpad.net/bugs/1001542
        #   (comment # 5 and on)
        trans = trans.strip(" \ufeff")

        if only_installable:
            pkg_name = 'language-pack-%s' % code
            # special case these
            if pkg_name.endswith('_CN'):
                pkg_name = 'language-pack-zh-hans'
            elif pkg_name.endswith('_TW'):
                pkg_name = 'language-pack-zh-hant'
            elif pkg_name.endswith('_NO'):
                pkg_name = pkg_name.split('_NO')[0]
            elif pkg_name.endswith('_BR'):
                pkg_name = pkg_name.split('_BR')[0]
            try:
                pkg = cache[pkg_name]
                if not (pkg.installed or pkg.candidate):
                    i += 1
                    continue
            except KeyError:
                i += 1
                continue

        language_display_map[trans] = (name, code)
        if i == current_language_index:
            current_language = trans
        i += 1
    languagelist.close()

    if only_installable:
        del cache

    try:
        # Note that we always collate with the 'C' locale.  This is far
        # from ideal.  But proper collation always requires a specific
        # language for its collation rules (languages frequently have
        # custom sorting).  This at least gives us common sorting rules,
        # like stripping accents.
        collator = icu.Collator.createInstance(icu.Locale('C'))
    except:
        collator = None

    def compare_choice(x):
        if language_display_map[x][1] == 'C':
            return None  # place C first
        if collator:
            try:
                return collator.getCollationKey(x).getByteArray()
            except:
                pass
        # Else sort by unicode code point, which isn't ideal either,
        # but also has the virtue of sorting like-glyphs together
        return x

    sorted_choices = sorted(language_display_map, key=compare_choice)

    return current_language, sorted_choices, language_display_map