コード例 #1
0
ファイル: slides.py プロジェクト: Acidburn0zzz/archiso-gui
    def manage_events_from_cb_queue(self):
        if self.fatal_error:
            return False

        while self.callback_queue.empty() == False:
            try:
                event = self.callback_queue.get_nowait()
            except queue.Empty:
                return True

            if event[0] == 'percent':
                self.progress_bar.set_fraction(event[1])
            elif event[0] == 'global_percent':
                self.show_global_progress_bar_if_hidden()
                self.global_progress_bar.set_fraction(event[1])
            elif event[0] == 'finished':
                logging.info(event[1])
                self.set_message(self.install_ok)
                response = show.question(self.install_ok)
                if response == Gtk.ResponseType.YES:
                    self.reboot()
                else:
                    tmp_files = [".setup-running", ".km-running", "setup-pacman-running", "setup-mkinitcpio-running", ".tz-running", ".setup", "Cnchi.log"]
                    for t in tmp_files:
                        p = os.path.join("/tmp", t)
                        if os.path.exists(p):
                            # TODO: some of these tmp files are created with sudo privileges
                            # (this should be fixed) meanwhile, we need sudo privileges to remove them
                            with misc.raised_privileges():
                                os.remove(p)
                    while Gtk.events_pending():
                        Gtk.main_iteration()
                    Gtk.main_quit()
                        
                self.exit_button.show()
                return False
            elif event[0] == 'error':
                self.callback_queue.task_done()
                # a fatal error has been issued. We empty the queue
                self.empty_queue()
                self.fatal_error = True
                show.fatal_error(event[1])
                return False
            elif event[0] == 'debug':
                logging.debug(event[1])
            elif event[0] == 'warning':
                logging.warning(event[1])
            else:
                # TODO: Check if logging slows down showing messages
                #       remove logging.info in that case (and at least
                #       use the one at pac.py:queue_event)
                logging.info(event[1])
                self.set_message(event[1])
                            
            self.callback_queue.task_done()
        
        return True
コード例 #2
0
    def manage_events_from_cb_queue(self):
        '''
        try:
            event = self.callback_queue.get_nowait()
        except queue.Empty:
            event = ()
        '''
        event = self.get_newest_event()

        if len(event) > 0:
            if event[0] == "percent":
                self.progress_bar.set_fraction(event[1])
            elif event[0] == "finished":
                log.debug(event[1])
                self.set_message(self.install_ok)
                response = show.question(self.install_ok)
                if response == Gtk.ResponseType.YES:
                    self.reboot()
                else:
                    tmp_files = [
                        ".setup-running", ".km-running",
                        "setup-pacman-running", "setup-mkinitcpio-running",
                        ".tz-running", ".setup", "Cnchi.log"
                    ]
                    for t in tmp_files:
                        p = os.path.join("/tmp", t)
                        if os.path.exists(p):
                            # TODO: some of these tmp files are created with sudo privileges
                            # (this should be fixed) meanwhile, we need sudo privileges to remove them
                            with misc.raised_privileges():
                                os.remove(p)
                    Gtk.main_quit()

                self.exit_button.show()
                return False
            elif event[0] == "error":
                show.fatal_error(event[1])
            else:
                #with self.lock:
                log.debug(event[1])
                self.set_message(event[1])
                # remove old messages from the event queue
                #self.callback_queue.clear()

        return True
コード例 #3
0
ファイル: slides.py プロジェクト: Astalaseven/Cnchi
    def manage_events_from_cb_queue(self):
        '''
        try:
            event = self.callback_queue.get_nowait()
        except queue.Empty:
            event = ()
        '''
        event = self.get_newest_event()

        if len(event) > 0:
            if event[0] == "percent":
                self.progress_bar.set_fraction(event[1])
            elif event[0] == "finished":
                log.debug(event[1])
                self.set_message(self.install_ok)
                response = show.question(self.install_ok)
                if response == Gtk.ResponseType.YES:
                    self.reboot()
                else:
                    tmp_files = [".setup-running", ".km-running", "setup-pacman-running", "setup-mkinitcpio-running", ".tz-running", ".setup", "Cnchi.log"]
                    for t in tmp_files:
                        p = os.path.join("/tmp", t)
                        if os.path.exists(p):
                            # TODO: some of these tmp files are created with sudo privileges
                            # (this should be fixed) meanwhile, we need sudo privileges to remove them
                            with misc.raised_privileges():
                                os.remove(p)
                    Gtk.main_quit()
                        
                self.exit_button.show()
                return False
            elif event[0] == "error":
                show.fatal_error(event[1])
            else:
                #with self.lock:
                log.debug(event[1])
                self.set_message(event[1])
                # remove old messages from the event queue 
                #self.callback_queue.clear()
                
        return True
コード例 #4
0
ファイル: slides.py プロジェクト: prodigeni/Cnchi
    def manage_events_from_cb_queue(self):
        try:
            event = self.callback_queue.get_nowait()
        except queue.Empty:
            event = ()

        if len(event) > 0:
            if event[0] == "percent":
                self.progress_bar.set_fraction(event[1])
            elif event[0] == "finished":
                log.debug(event[1])
                self.set_message(self.install_ok)
                response = show.message(self.install_ok)
                if response == Gtk.ResponseType.YES:
                    # TODO: This needs testing
                    #subp = subprocess.Popen(['reboot'], stdout=subprocess.PIPE)
                    with misc.raised_privileges():
                        subp = subprocess.Popen(['shutdown', '-r', 'now'])
                else:
                    tmp_files = [".setup-running", ".km-running", "setup-pacman-running", "setup-mkinitcpio-running", ".tz-running", ".setup" ]
                    for t in tmp_files:
                        p = os.path.join("/tmp", t)
                        if os.path.exists(p):
                            os.remove(p)
                    Gtk.main_quit()
                        
                self.exit_button.show()
                return False
            elif event[0] == "error":
                show.fatal_error(event[1])
            else:
                log.debug(event[1])
                self.set_message(event[1])
                # remove old messages from the event queue 
                with self.callback_queue.mutex:
                    self.callback_queue.queue.clear()

        return True
コード例 #5
0
ファイル: i18n.py プロジェクト: Astalaseven/Cnchi
def get_languages(language_list="data/languagelist.data.gz", 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(language_list)
    language_display_map = {}
    i = 0
    for line in languagelist:
        line = 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

    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
コード例 #6
0
def get_languages(language_list="data/languagelist.data.gz",
                  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(language_list)
    language_display_map = {}
    i = 0
    for line in languagelist:
        line = 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

    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