Пример #1
0
def _write_plugin_download(plugin: Plugin, file: IO[str], limit: int):
    file.write('### {}\n'.format(Text('download')))
    file.write('\n')

    if plugin.release_summary is not None:
        table = Table(Text('file'), Text('version'), Text('upload_time'),
                      Text('size'), Text('download_amount'),
                      Text('operations'))
        for release in plugin.release_summary.releases:
            for asset in release.get_mcdr_assets():
                table.add_row(
                    Link(asset.name, release.url), release.parsed_version,
                    formatted_time(asset.created_at, precision='second'),
                    utils.pretty_file_size(asset.size), asset.download_count,
                    ' '.join(
                        map(str, [
                            Link(Text('operations.download'),
                                 asset.browser_download_url)
                        ])))
                break  # takes the first .mcdr asset
            if table.row_count == limit:
                break
        table.write(file)
    else:
        file.write('*{}*\n'.format(Text('data_fetched_failed')))
        file.write('\n')
Пример #2
0
def write_label_info(file: IO[str]):
    label_set = get_label_set()
    file.write('## {}\n'.format(Text('label_index')))
    file.write('\n')
    for label in label_set.get_label_list():
        file.write('- {}\n'.format(Link(label, get_label_doc_link(label.id))))
    file.write('\n')
Пример #3
0
 def translated_description(self) -> str:
     text = BundledText(self.description).get()
     if text is None:
         text = '*{}*'.format(Text('none'))
     else:
         text = utils.format_markdown(text)
     return text
Пример #4
0
    def load_from_json(self, js: dict):
        self.plugin_json = js

        self.id = js.get('id', None)
        self.repository = js['repository'].rstrip('/')
        if not self.repository.startswith('https://github.com/'):
            raise ValueError(
                'Github repository with https url is required, found: {}'.
                format(self.repository))
        self.branch = js['branch']
        self.related_path = js.get('related_path', '.').strip('/')

        authors = js.get('authors', [])
        self.authors = []
        for item in authors:
            author = Author()
            if isinstance(item, str):
                author.name = item
            else:
                assert isinstance(item, dict)
                author.update_from(item)
            self.authors.append(author)

        # label
        self.labels = []
        for label_key in js['labels']:
            label = get_label_set().get_label(label_key)
            if label is None:
                raise ValueError('Unknown label: {}'.format(label_key))
            else:
                self.labels.append(label)

        # introduction
        external_introduction = js.get('introduction', {})
        introduction_translations = {}
        for lang in LANGUAGES:
            with with_language(lang):
                file_location = external_introduction.get(lang)
                if file_location is not None:
                    try:
                        introduction_translations[lang] = self.get_repos_text(
                            file_location)
                    except:
                        print(
                            'Failed to get custom introduction file from {} in language {} in {}'
                            .format(file_location, lang, self))
                        traceback.print_exc()
                        introduction_translations[lang] = '*{}*'.format(
                            Text('data_fetched_failed'))
                introduction_tr_file_path = os.path.join(
                    self.directory, get_file_name('introduction.md'))
                if os.path.isfile(introduction_tr_file_path):
                    with utils.read_file(
                            introduction_tr_file_path) as file_handler:
                        introduction_translations[lang] = file_handler.read()
        self.introduction = BundledText(introduction_translations)
Пример #5
0
def generate_index(plugin_list: Iterable[Plugin], file: IO[str]):
    plugin_list = list(plugin_list)
    file.write('{}: {}\n'.format(Text('plugin_amount'), len(plugin_list)))
    file.write('\n')
    table = Table(Text('plugin_name'), Text('authors'), Text('description'),
                  Text('last_update'), Text('labels'))
    for plugin in plugin_list:
        try:
            if plugin.is_data_fetched():
                name = plugin.meta_info.name
                translated_description = plugin.meta_info.translated_description
            else:
                name = translated_description = failed()
            release = plugin.release_summary.get_latest_release()
            if release is not None:
                last_update = formatted_time(release.created_at,
                                             precision='day')
            else:
                last_update = 'N/A'
            table.add_row(
                Link(name, get_plugin_detail_link(plugin.id)),
                ', '.join(map(lambda a: a.to_markdown(), plugin.authors)),
                translated_description, last_update,
                get_label_list_markdown(plugin))
        except:
            print('Failed to write plugin index of {}'.format(plugin))
            raise
    table.write(file)
Пример #6
0
def write_translation_nav(file_name: str, file: IO[str]):
    nav_list = []
    for lang in LANGUAGES:
        with with_language(lang):
            lang_name = Text('_language_name').get()
        if lang == get_language():
            text = '**{}**'.format(lang_name)
        else:
            with with_language(lang):
                text = Link(lang_name, get_file_name(file_name))
        nav_list.append('{}'.format(text))
    file.write('{}\n'.format(' | '.join(nav_list)))
    file.write('\n')
Пример #7
0
def generate_labels(plugin_list: List[Plugin]):
    label_root = os.path.join(constants.CATALOGUE_FOLDER, 'labels')
    for label in get_label_set().get_label_list():
        with write_nav(
                os.path.join(label_root, label.id,
                             get_file_name('readme.md'))) as file:
            file.write('# {}\n'.format(label))
            file.write('\n')
            file.write('{}\n'.format(
                Text('plugin_index_with_label')).format(label))
            file.write('\n')
            generate_index(
                filter(lambda plg: label in plg.labels, plugin_list), file)
Пример #8
0
def generate_index(plugin_list: Iterable[Plugin], file: IO[str]):
    plugin_list = list(plugin_list)
    file.write('{}: {}\n'.format(Text('plugin_amount'), len(plugin_list)))
    file.write('\n')
    table = Table(Text('plugin_name'), Text('authors'), Text('description'),
                  Text('labels'))
    for plugin in plugin_list:
        try:
            if plugin.is_data_fetched():
                name = plugin.meta_info.name
                translated_description = plugin.meta_info.translated_description
            else:
                name = translated_description = failed()
            table.add_row(
                Link(name, get_plugin_detail_link(plugin.id)),
                ', '.join(map(lambda a: a.to_markdown(),
                              plugin.authors)), translated_description,
                get_label_list_markdown(plugin))
        except:
            print('Failed to write plugin index of {}'.format(plugin))
            raise
    table.write(file)
Пример #9
0
def write_back_to_index_nav(file: IO[str]):
    file.write('{} {}\n'.format(
        utils.format_markdown('>>>'),
        Link(Text('back_to_index'), get_file_name('/readme.md'))))
    file.write('\n')
Пример #10
0
def none() -> str:
    return '*{}*'.format(Text('none'))
Пример #11
0
def failed() -> str:
    return '*{}*'.format(Text('data_fetched_failed'))
Пример #12
0
def _write_plugin(plugin: Plugin, file: IO[str]):
    file.write('## {}\n'.format(plugin.id))
    file.write('\n')

    file.write('### {}\n'.format(Text('basic_info')))
    file.write('\n')

    file.write('- {}: `{}`\n'.format(Text('plugin_id'), plugin.id))
    if plugin.is_data_fetched():
        file.write('- {}: {}\n'.format(Text('plugin_name'),
                                       plugin.meta_info.name))
        file.write('- {}: {}\n'.format(Text('version'), plugin.latest_version))
        file.write('  - {}: {}\n'.format(Text('metadata_version'),
                                         plugin.meta_info.version))
        file.write('  - {}: {}\n'.format(
            Text('release_version'), plugin.release_summary.latest_version))
    else:
        file.write('- {}: {}\n'.format(Text('version'), failed()))

    file.write('- {}: {}\n'.format(
        Text('total_downloads'), plugin.release_summary.get_total_downloads()))
    file.write('- {}: {}\n'.format(
        Text('authors'),
        ', '.join(map(lambda a: a.to_markdown(), plugin.authors))))
    file.write('- {}: {}\n'.format(Text('repository'), plugin.repository))
    file.write('- {}: {}\n'.format(Text('labels'),
                                   get_label_list_markdown(plugin)))
    if plugin.is_data_fetched():
        file.write('- {}: {}\n'.format(
            Text('description'), plugin.meta_info.translated_description))
    else:
        file.write('- {}: {}\n'.format(Text('description'), failed()))
    file.write('\n')

    file.write('### {}\n'.format(Text('dependencies')))
    file.write('\n')
    if plugin.is_data_fetched():
        table = Table(Text('plugin_id'), Text('dependencies.requirement'))
        for pid, req in plugin.meta_info.dependencies.items():
            table.add_row(Link(pid, get_plugin_detail_link(pid)),
                          utils.format_markdown(req))
        table.write(file)
    else:
        file.write('{}\n'.format(failed()))
        file.write('\n')

    file.write('### {}\n'.format(Text('requirements')))
    file.write('\n')
    if plugin.is_data_fetched():
        table = Table(Text('python_package'), Text('requirements.requirement'))
        for line in plugin.meta_info.requirements:
            matched = re.match(r'^[^<>=~^]+', line)
            if matched is None:
                print('Unknown requirement line "{}" in plugin {}'.format(
                    line, plugin))
                continue
            package = matched.group()
            req = utils.remove_prefix(line, package)
            table.add_row(
                Link(package, 'https://pypi.org/project/{}'.format(package)),
                utils.format_markdown(req))
        table.write(file)
    else:
        file.write('{}\n'.format(failed()))
        file.write('\n')

    file.write('### {}\n'.format(Text('introduction')))
    file.write('\n')
    file.write(plugin.introduction.get() or '{}\n'.format(none()))
    file.write('\n')