def __add_to_revdeps(self, package, revdeps): metadata_xml = os.path.join(self.package_path(package), ctx.const.metadata_xml) meta_doc = xmlext.parse(metadata_xml) try: pkg = xmlext.getNode(meta_doc, "Package") except: pkg = None if pkg is None: # If package info is broken or not available, skip it. ctx.ui.warning( _("Installation info for package \"{}\" is broken. " "Reinstall it to fix this problem.").format(package)) del self.installed_db[package] return deps = xmlext.getNode(pkg, 'RuntimeDependencies') if deps: for dep in xmlext.getTagByName(deps, 'Dependency'): revdep = revdeps.setdefault(xmlext.getNodeText(dep), {}) revdep[package] = xmlext.toString(dep) for anydep in xmlext.getTagByName(deps, 'AnyDependency'): for dep in xmlext.getTagByName(anydep, 'Dependency'): revdep = revdeps.setdefault(xmlext.getNodeText(dep), {}) revdep[package] = xmlext.toString(anydep)
def __generate_replaces(doc): replaces = [] packages = xmlext.getTagByName(doc, "Package") for node in packages: if xmlext.getNodeText(node, "Replaces"): replaces.append(xmlext.getNodeText(node, "Name")) return replaces
def __generate_components(doc): groups = {} components = xmlext.getTagByName(doc, "Component") for comp in components: group = xmlext.getNodeText(comp, "Group") name = xmlext.getNodeText(comp, "Name") groups.setdefault(group, []).append(name) return groups
def __generate_packages(doc): components = {} packages = xmlext.getTagByName(doc, "Package") for pkg in packages: name = xmlext.getNodeText(pkg, "Name") partof = xmlext.getNodeText(pkg, "PartOf") components.setdefault(partof, []).append(name) return components
def __generate_sources(doc): components = {} specfile = xmlext.getTagByName(doc, "SpecFile") for spec in specfile: source = xmlext.getNode(spec, "Source") name = xmlext.getNodeText(source, "Name") partof = xmlext.getNodeText(source, "PartOf") components.setdefault(partof, []).append(name) return components
def _get_repos(self): repo_doc = self._get_doc() order = {} for r in xmlext.getTagByName(repo_doc, "Repo"): media = xmlext.getNodeText(r, "Media") name = xmlext.getNodeText(r, "Name") order.setdefault(media, []).append(name) return order
def get_status(self, repo_name): repo_doc = self._get_doc() for r in xmlext.getTagByName(repo_doc, "Repo"): if xmlext.getNodeText(r, "Name") == repo_name: status_node = xmlext.getNode(r, "Status") if status_node: status = xmlext.getNodeText(status_node) if status in ["active", "inactive"]: return status return "inactive"
def __generate_revdeps(doc): revdeps = {} for node in xmlext.getTagByName(doc, "Package"): name = xmlext.getNodeText(node, 'Name') deps = xmlext.getNode(node, 'RuntimeDependencies') if deps: for dep in xmlext.getTagByName(deps, "Dependency"): revdeps.setdefault(xmlext.getNodeText(dep), set()).add( (name, xmlext.toString(dep))) return revdeps
def _set_i18n(tag, inst): try: for summary in xmlext.getTagByName(tag, "Summary"): inst.summary[xmlext.getNodeAttribute( summary, "xml:lang")] = xmlext.getNodeText(summary) for desc in xmlext.getTagByName(tag, "Description"): inst.description[xmlext.getNodeAttribute( desc, "xml:lang")] = xmlext.getNodeText(desc) except AttributeError as e: raise Error( _("translations.xml file is badly formed.: {}").format(e))
def __generate_revdeps(doc): revdeps = {} for spec in xmlext.getTagByName(doc, "SpecFile"): src = xmlext.getNode(spec, "Source") name = xmlext.getNodeText(src, "Name") deps = xmlext.getNode(src, "BuildDependencies") if deps: for dep in xmlext.getTagByName(deps, "Dependency"): revdeps.setdefault(xmlext.getNodeText(dep), set()).add( (name, xmlext.toString(dep))) return revdeps
def get_isa_packages(isa): repodb = inary.db.repodb.RepoDB() packages = set() for repo in repodb.list_repos(): doc = repodb.get_repo_doc(repo) for package in xmlext.getTagByName(doc, "Package"): if xmlext.getNodeText(package, "IsA"): for node in xmlext.getTagByName(package, "IsA"): if xmlext.getNodeText(node) == isa: packages.add(xmlext.getNodeText(package, "Name")) return list(packages)
def __generate_sources(doc): sources = {} pkgstosrc = {} for spec in xmlext.getTagByName(doc, "SpecFile"): src = xmlext.getNode(spec, "Source") src_name = xmlext.getNodeText(src, "Name") compressed_data = gzip.zlib.compress( xmlext.toString(spec).encode('utf-8')) sources[src_name] = compressed_data for package in xmlext.getTagByName(spec, "Package"): pkgstosrc[xmlext.getNodeText(package, "Name")] = src_name return sources, pkgstosrc
def read_translations(self, path): if not os.path.exists(path): return doc = xmlext.parse(path) if xmlext.getNodeText(xmlext.getNode(doc, "Source"), "Name") == self.source.name: # Set source package translations self._set_i18n(xmlext.getNode(doc, "Source"), self.source) for pak in xmlext.getTagByName(doc, "Package"): for inst in self.packages: if inst.name == xmlext.getNodeText(pak, "Name"): self._set_i18n(pak, inst) break
def remove(self, repo_name): repo_doc = self._get_doc() for r in xmlext.getChildElts(repo_doc): if xmlext.getNodeText(r, "Name") == repo_name: xmlext.removeChild(r, repo_doc) self._update(repo_doc)
def get_rev_deps(self, name, repo=None): try: rvdb = self.rvdb.get_item(name, repo) except BaseException: # FIXME: what exception could we catch here, replace with that. return [] rev_deps = [] for pkg, dep in rvdb: node = xmlext.parseString(dep) dependency = inary.analyzer.dependency.Dependency() dependency.package = xmlext.getNodeText(node) if xmlext.getAttributeList(node): if xmlext.getNodeAttribute(node, "version"): dependency.__dict__["version"] = xmlext.getNodeAttribute( node, "version") elif xmlext.getNodeAttribute(node, "release"): dependency.__dict__["release"] = xmlext.getNodeAttribute( node, "release") else: pass # FIXME: ugly rev_deps.append((pkg, dependency)) return rev_deps
def __get_last_date(meta_doc): history = xmlext.getNode(meta_doc, 'History') update = xmlext.getNode(history, 'Update') date = xmlext.getNodeText(update, 'Date') return date
def domodules(filepath): doc = xmlext.parse(filepath) for item in xmlext.getAllNodes("File"): path = xmlext.getNodeText(item, "Path") if path.startswith("lib/modules/"): kernelVersion = path.split("/")[2] subprocess.call(["/sbin/depmod", "-a", kernelVersion]) return
def __generate_groups(doc): groups = {} group = xmlext.getTagByName(doc, "Group") for gr in group: name = xmlext.getNodeText(gr, "Name") groups[name] = xmlext.toString(gr) return groups
def __generate_components(doc): components = {} component = xmlext.getTagByName(doc, "Component") for comp in component: name = xmlext.getNodeText(comp, "Name") components[name] = xmlext.toString(comp) return components
def __get_version(meta_doc): history = xmlext.getNode(meta_doc, 'History') update = xmlext.getNode(history, 'Update') version = xmlext.getNodeText(update, 'Version') release = xmlext.getNodeAttribute(update, 'release') return version, release, None
def __generate_packages(doc): pdict = {} for x in xmlext.getTagByName(doc, "Package"): name = xmlext.getNodeText(x, "Name") compressed_data = gzip.zlib.compress( xmlext.toString(x).encode('utf-8')) pdict[name] = compressed_data return pdict
def __generate_sources(doc): pdict = {} for x in xmlext.getTagByName(doc, "SpecFile"): source = xmlext.getNode(x, "Source") name = xmlext.getNodeText(source, "Name") compressed_data = gzip.zlib.compress( xmlext.toString(x).encode('utf-8')) pdict[name] = compressed_data return pdict
def __generate_obsoletes(doc): distribution = xmlext.getNode(doc, "Distribution") obsoletes = distribution and xmlext.getNode(distribution, "Obsoletes") src_repo = xmlext.getNode(doc, "SpecFile") is not None if not obsoletes or src_repo: return [] return [ xmlext.getNodeText(x) for x in xmlext.getTagByName(obsoletes, "Package") ]
def set_status(self, repo_name, status): repo_doc = self._get_doc() for r in xmlext.getTagByName(repo_doc, "Repo"): if xmlext.getNodeText(r, "Name") == repo_name: status_node = xmlext.getNode(r, "Status") if status_node: xmlext.removeChild(status_node, r) xmlext.addText(r, "Status", status) else: xmlext.addText(r, "Status", status) self._update(repo_doc)
def __make_dependency(depStr): node = xmlext.parseString(depStr) dependency = inary.analyzer.dependency.Dependency() dependency.package = xmlext.getNodeText(node) if xmlext.getAttributeList(node): if xmlext.getNodeAttribute(node, "version"): dependency.__dict__["version"] = xmlext.getNodeAttribute( node, "version") elif xmlext.getNodeAttribute(node, "release"): dependency.__dict__["release"] = xmlext.getNodeAttribute( node, "release") else: pass #FIXME: ugly return dependency
def doinfo(filepath, remove=False): # install-info is broken with i18n :( os.environ["LC_ALL"] = "C" doc = xmlext.parse(filepath) for item in xmlext.getAllNodes(doc, "File"): path = xmlext.getNodeText(item, "Path") if path.startswith("usr/share/info") and path.endswith( (".info", ".info.gz")): if remove: subprocess.call([ "install-info", "--delete", "/%s" % path, "/usr/share/info/dir" ]) else: subprocess.call( ["install-info", "/%s" % path, "/usr/share/info/dir"])
def decode(self, node, errs, where=""): # flags, tag name, instance attribute assert self.tag != '' nodes = xmlext.getAllNodes(node, self.tag) if not nodes: if self.req == mandatory: errs.append(where + ': ' + _("At least one '{}' tag should have local text." ).format(self.tag)) else: for node in nodes: lang = xmlext.getNodeAttribute(node, 'xml:lang') c = xmlext.getNodeText(node) if not c: errs.append(where + ': ' + _("'{0}' language of tag '{1}' is empty." ).format(lang, self.tag)) # FIXME: check for dups and 'en' if not lang: lang = 'en' self[lang] = str(c)
def __get_install_tar_hash(meta_doc): package = xmlext.getNode(meta_doc, 'Package') hash = xmlext.getNodeText(package, 'InstallTarHash') return hash
def __get_distro_release(meta_doc): distro = xmlext.getNodeText(meta_doc, 'Distribution') release = xmlext.getNodeText(meta_doc, 'DistributionRelease') return distro, release
def __get_summary(meta_doc): summary = xmlext.getNodeText(meta_doc, 'Summary') return summary