예제 #1
0
        def cb_success(programs):
            sorted_programs = {}

            for program in programs:
                first_upload = program.cast_custom_option_value('first_upload', int, 0)

                if first_upload in sorted_programs:
                    sorted_programs[first_upload][program.identifier] = program
                else:
                    sorted_programs[first_upload] = {program.identifier: program}

            for first_upload in sorted(sorted_programs.keys()):
                for identifier in sorted(sorted_programs[first_upload].keys()):
                    program  = sorted_programs[first_upload][identifier]
                    language = program.cast_custom_option_value('language', str, '<unknown>')

                    try:
                        language = Constants.get_language_display_name(language)
                    except:
                        pass

                    item = QTreeWidgetItem([program.cast_custom_option_value('name', str, '<unknown>'), identifier, language])

                    self.tree_programs.addTopLevelItem(item)
                    item.setSelected(True)

            self.refresh_in_progress = False
            self.update_ui_state()
            self.tree_programs.setFocus()
        def cb_success(programs):
            sorted_programs = {}

            for program in programs:
                first_upload = program.cast_custom_option_value('first_upload', int, 0)

                if first_upload in sorted_programs:
                    sorted_programs[first_upload][program.identifier] = program
                else:
                    sorted_programs[first_upload] = {program.identifier: program}

            for first_upload in sorted(sorted_programs.keys()):
                for identifier in sorted(sorted_programs[first_upload].keys()):
                    program  = sorted_programs[first_upload][identifier]
                    language = program.cast_custom_option_value('language', str, '<unknown>')

                    try:
                        language = Constants.get_language_display_name(language)
                    except:
                        pass

                    item = QTreeWidgetItem([program.cast_custom_option_value('name', str, '<unknown>'), identifier, language])

                    self.tree_programs.addTopLevelItem(item)
                    item.setSelected(True)

            self.refresh_in_progress = False
            self.update_ui_state()
            self.tree_programs.setFocus()
        def refresh_async():
            try:
                a = tarfile.open(filename, 'r:gz')
            except Exception as e:
                return [], 'Could not open archive:\n\n{0}'.format(e)

            with contextlib.closing(a):
                try:
                    v = a.extractfile('tfrba-version')
                except Exception as e:
                    return [], 'Could not extract tfrba-version:\n\n{0}'.format(e)

                version = v.read()
                v.close()

                if version != b'1':
                    return [], 'Unknown tfrba-version {0}'.format(version)

                programs = {}

                for member in a.getnames():
                    if member.startswith('programs/') and member.endswith('/program.conf'):
                        try:
                            c = a.extractfile(member)
                        except Exception as e:
                            return [], 'Could not extract {0}:\n\n{1}'.format(member, e)

                        conf = list(map(lambda line: line.decode('utf-8'), c.readlines()))
                        c.close()

                        name         = '<unknown>'
                        identifier   = member.split('/')[1]
                        language     = '<unknown>'
                        first_upload = 0

                        for line in conf:
                            if line.startswith('custom.name ='):
                                try:
                                    name = line[len('custom.name ='):].strip().encode('ascii').decode('unicode_escape')
                                except:
                                    pass
                            elif line.startswith('custom.language ='):
                                try:
                                    language = Constants.get_language_display_name(line[len('custom.language ='):].strip().encode('ascii').decode('unicode_escape'))
                                except:
                                    pass
                            elif line.startswith('custom.first_upload ='):
                                try:
                                    first_upload = int(line[len('custom.first_upload ='):].strip())
                                except:
                                    pass

                        programs[identifier] = [name, identifier, language, 'New', first_upload]

                try:
                    existing_programs = get_lite_programs(self.session)
                except Exception as e:
                    return [], 'Could not get existing program list:\n\n{0}'.format(e)

                for existing_program in existing_programs:
                    identifier = existing_program.identifier

                    if identifier in programs:
                        programs[identifier][3] = 'Existing'

                return programs.values(), None
예제 #4
0
        def refresh_async():
            try:
                a = tarfile.open(filename, 'r:gz')
            except Exception as e:
                return [], 'Could not open archive:\n\n{0}'.format(e)

            with contextlib.closing(a):
                try:
                    v = a.extractfile('tfrba-version')
                except Exception as e:
                    return [], 'Could not extract tfrba-version:\n\n{0}'.format(
                        e)

                version = v.read()
                v.close()

                if version != b'1':
                    return [], 'Unknown tfrba-version {0}'.format(version)

                programs = {}

                for member in a.getnames():
                    if member.startswith('programs/') and member.endswith(
                            '/program.conf'):
                        try:
                            c = a.extractfile(member)
                        except Exception as e:
                            return [], 'Could not extract {0}:\n\n{1}'.format(
                                member, e)

                        conf = list(
                            map(lambda line: line.decode('utf-8'),
                                c.readlines()))
                        c.close()

                        name = '<unknown>'
                        identifier = member.split('/')[1]
                        language = '<unknown>'
                        first_upload = 0

                        for line in conf:
                            if line.startswith('custom.name ='):
                                try:
                                    name = line[len('custom.name ='):].strip(
                                    ).encode('ascii').decode('unicode_escape')
                                except:
                                    pass
                            elif line.startswith('custom.language ='):
                                try:
                                    language = Constants.get_language_display_name(
                                        line[len('custom.language ='):].strip(
                                        ).encode('ascii').decode(
                                            'unicode_escape'))
                                except:
                                    pass
                            elif line.startswith('custom.first_upload ='):
                                try:
                                    first_upload = int(
                                        line[len('custom.first_upload ='
                                                 ):].strip())
                                except:
                                    pass

                        programs[identifier] = [
                            name, identifier, language, 'New', first_upload
                        ]

                try:
                    existing_programs = get_lite_programs(self.session)
                except Exception as e:
                    return [], 'Could not get existing program list:\n\n{0}'.format(
                        e)

                for existing_program in existing_programs:
                    identifier = existing_program.identifier

                    if identifier in programs:
                        programs[identifier][3] = 'Existing'

                return programs.values(), None