def get_submodules(url): """Download and parse .gitmodules from git repository using http""" content = http_get(url) if content: parser = SubModulesParser(content) return parser.modules else: return []
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 get_mod_index(url, wiki): index = {} content = http_get(url) if content: data = get_page_content_from_json(json.loads(content)) for row in MOD_TABLE_ITEM.finditer(data): repo = row.group('code') if repo.endswith('/'): repo = repo[:-1] item = { 'name': row.group('name'), 'title': row.group('title') or row.group('name'), 'description': row.group('description'), 'categories': row.group('topics'), 'author': row.group('authors'), 'repo': repo, 'flag': row.group('flag') } icon = row.group('icon') if icon: item['icon'] = wiki + '/Special:Redirect/file/' + icon.replace( ' ', '_') index[repo] = item return index
def installMacro(self, pkg): result = InstallResult() url = self.getWikiPageUrlJson("Macro_{0}".format(quote(pkg.name))) content = http_get(url) # Manage mediawiki redirects m = REDIRECT.search(content) max_redirects = 3 while m: url = self.getWikiPageUrlJson("{0}".format(quote(m.group('link')))) content = http_get(url) m = REDIRECT.search(content) max_redirects -= 1 if max_redirects <= 0: break if not content: result.message = tr( """This macro contains invalid content, it cannot be installed directly by the Extension Manager""") else: wikitext = get_page_content_from_json(json.loads(content)) # Try {{MacroCode ...}} m = MACRO_CODE.search(wikitext) if not m: # Try <pre> ... </pre> m = LEGACY_MACRO_CODE.search(wikitext) # Code in wiki if m: try: f = open(pkg.installFile, 'w', encoding='utf-8') except IOError as ex: result.message = str(ex) else: with f: try: f.write(m.group('code')) result.ok = True except: result.message = tr( """This macro contains invalid content, it cannot be installed directly by the Extension Manager""" ) # Try external source else: m = MACRO_CODE_EXTLINK.search(wikitext) if m: pre = tr("This macro must be downloaded from this link") pos = tr( """Copy the link, download it and install it manually or follow instructions from the external resource""") result.message = """{0}: <textarea class="form-control" style="min-height: 100px; margin: 5px;" readonly>{1} </textarea> {2}""".format(pre, m.group('link'), pos) return result
def getRawFile(self, path): url = self.getRawFileUrl(path) return http_get(url)