Beispiel #1
0
    def getMacroList(self):

        macros = []
        install_dir = get_macro_path()
        default_icon = utils.path_to_url(
            get_resource_path('html', 'img', 'package_macro.svg'))

        try:
            content = http_get(self.url, timeout=45)
            if content:
                data = json.loads(content)
                wiki = get_page_content_from_json(data)

                for m_link in MACRO_LINK.finditer(wiki):

                    name = m_link.group('name').replace(' ', '_')
                    label = m_link.group('label')
                    description = m_link.group('description')

                    icon = m_link.group('icon')
                    if icon:
                        icon = self.wiki + '/Special:Redirect/file/' + icon.replace(
                            ' ', '_')
                    else:
                        icon = default_icon

                    pkg = PackageInfo(
                        key=name,
                        installDir=install_dir,
                        installFile=Path(install_dir, name + '.FCMacro'),
                        name=name,
                        title=label,
                        description=description,
                        icon=icon,
                        isCore=False,
                        type='Macro',
                        isGit=False,
                        isWiki=True,
                        markedAsSafe=False,
                        categories=[tr('Uncategorized')],
                        date=None,
                        version=None,
                        readmeUrl='{0}/Macro_{1}?origin=*'.format(
                            self.wiki, name),
                        readmeFormat='html')
                    flags.apply_predefined_flags(pkg)
                    macros.append(pkg)

        except:
            traceback.print_exc(file=sys.stderr)

        return macros
 def importMod(self, path, installDir, isCore):
     pdir = installDir.name
     if installDir.is_dir():
         wbKey = utils.get_workbench_key(pdir)
         wb = self.workbenches.get(wbKey)
         pkg = PackageInfo(key=wbKey,
                           type='Workbench' if wb else 'Mod',
                           name=pdir,
                           isCore=isCore,
                           installDir=installDir,
                           icon=self.getModIcon(pdir, installDir, wbKey,
                                                wb),
                           title=wb.MenuText if wb else pdir,
                           description=wb.ToolTip if wb else pdir,
                           categories=utils.get_workbench_categories(wb),
                           isGit=Path(installDir, '.git').is_dir())
         flags.apply_predefined_flags(pkg)
         analyseInstalledMod(pkg)
         return pkg
Beispiel #3
0
def build_macro_package(path,
                        macro_name,
                        is_core=False,
                        is_git=False,
                        is_wiki=False,
                        install_path=None,
                        base_path=""):

    with open(path, 'r', encoding='utf-8') as f:

        try:
            tags = get_macro_tags(f.read(), path)
        except:  # !TODO: Handle encoding problems in old windows platforms
            tags = {k: None for k in MACRO_TAG_FILTER}
            log_err(tr('Macro {0} contains invalid characters').format(path))

        install_dir = get_macro_path()
        base = dict(key=str(install_path) if install_path else str(path),
                    type='Macro',
                    isCore=is_core,
                    installDir=install_dir,
                    installFile=Path(install_dir, path.name),
                    isGit=is_git,
                    isWiki=is_wiki,
                    basePath=base_path)
        tags.update(base)

        if not tags['title']:
            tags['title'] = tags['name'] or macro_name

        tags['name'] = macro_name  # Always override name with actual file name

        if not tags['icon']:
            tags['icon'] = get_resource_path('html', 'img',
                                             'package_macro.svg')

        try:
            if not Path(tags['icon']).exists():
                tags['icon'] = get_resource_path('html', 'img',
                                                 'package_macro.svg')
        except:
            tags['icon'] = get_resource_path('html', 'img',
                                             'package_macro.svg')

        tags['icon'] = utils.path_to_url(tags['icon'])

        if tags['comment']:
            tags['description'] = tags['comment']

        if not tags['description']:
            tags['description'] = tr('Warning! No description')

        if tags['categories']:
            cats = COMMA_SEP_LIST_PATTERN.split(tags['categories'])
            tags['categories'] = [tr(c) for c in cats]
        else:
            tags['categories'] = [tr('Uncategorized')]

        if tags['files']:
            tags['files'] = COMMA_SEP_LIST_PATTERN.split(tags['files'])

        if tags['readme']:
            tags['readmeUrl'] = tags['readme']
            tags['readmeFormat'] = 'html'
        elif tags['wiki']:
            tags['readmeUrl'] = tags['wiki']
            tags['readmeFormat'] = 'html'
        elif tags['web']:
            tags['readmeUrl'] = tags['web']
            tags['readmeFormat'] = 'html'

        return PackageInfo(**tags)
Beispiel #4
0
    def modFromSubModule(self,
                         mod,
                         index,
                         syncManifest=False,
                         syncReadme=False):

        repo = self.RepoImpl(mod['url'])

        if syncManifest:
            repo.syncManifestHttp()

        if syncReadme:
            repo.syncReadmeHttp()

        icon_path = "Resources/icons/{0}.svg".format(mod['name'])

        index_key = mod['url']
        if index_key.endswith('.git'):
            index_key = index_key[:-4]

        indexed = index.get(index_key)
        if indexed:
            icon_path = indexed.get('icon', icon_path)

        if repo.manifest:
            general = repo.manifest.general
            if general and general.iconPath:
                icon_path = repo.manifest.iconPath

        install_dir = Path(get_mod_path(), mod['name'])

        icon_sources = utils.get_workbench_icon_candidates(
            mod['name'], repo.getRawFileUrl(), icon_path, install_dir)

        pkg_info = {
            'name': mod['name'],
            'title': mod['name'],
            'description': None,
            'categories': None,
            'iconSources': icon_sources,
            'readmeUrl': repo.getReadmeUrl(),
            'readmeFormat': repo.getReadmeFormat()
        }

        # Copy data from index
        if indexed:
            pkg_info['title'] = indexed.get('title', pkg_info['title'])
            pkg_info['description'] = indexed.get('description',
                                                  pkg_info['description'])
            pkg_info['categories'] = indexed.get('categories',
                                                 pkg_info['categories'])
            pkg_info['author'] = indexed.get('author')
            flag = indexed.get('flag')
            if flag:
                iflags = pkg_info.get('flags', {})
                iflags['obsolete'] = True
                pkg_info['flags'] = iflags

        # Copy all manifest attributes
        if repo.manifest:
            repo.manifest.getData(pkg_info)

        # Override some things
        pkg_info.update(
            dict(key=mod['name'],
                 type='Workbench',
                 isCore=False,
                 installDir=install_dir,
                 icon=icon_sources[0],
                 categories=utils.get_workbench_categories_from_string(
                     mod['name'], pkg_info['categories']),
                 isGit=True,
                 git=mod['url']))

        pkg = PackageInfo(**pkg_info)
        flags.apply_predefined_flags(pkg)
        return pkg