Beispiel #1
0
    def processPisi(self, path):
        zip = zipfile.ZipFile(path, "r")

        size = os.stat(path).st_size
        self.total_size += size

        doc = piksemel.parseString(zip.read("metadata.xml"))
        p = doc.getTag("Package")
        name = p.getTagData("Name")
        inst_size = int(p.getTagData("InstalledSize"))
        self.total_installed_size += inst_size

        doc = piksemel.parseString(zip.read("files.xml"))
        for item in doc.tags("File"):
            tname = item.getTagData("Type")
            sz = item.getTagData("Size")
            try:
                sz = int(sz)
            except:
                sz = 0
            if self.installed_sizes.has_key(tname):
                self.installed_sizes[tname] += sz
            else:
                self.installed_sizes[tname] = sz

        pak = packages.get(name, None)
        if not pak:
            return

        pak.size = size
        pak.installedSize = inst_size
Beispiel #2
0
    def make_index(self, package_list):
        doc = piksemel.newDocument("PISI")

        # since new PiSi (pisi 2) needs component info in index file, we need to copy it from original index that user specified
        indexpath = fetch_uri(self.base_uri, self.cache_dir, self.index_name, None, False)
        if indexpath.endswith(".bz2"):
            import bz2
            data = open(indexpath).read()
            data = bz2.decompress(data)
            doc_index = piksemel.parseString(data)
        elif indexpath.endswith(".xz"):
            try:
                import lzma
            except ImportError:
                print "Install python-pyliblzma package, or try a different index format."
                return

            data = open(indexpath).read()
            data = lzma.decompress(data)
            doc_index = piksemel.parseString(data)
        else:
            doc_index = piksemel.parse(indexpath)

        # old PiSi needs obsoletes list, so we need to copy it too.
        for comp_node in doc_index.tags("Distribution"):
            doc.insertNode(comp_node)

        for name in package_list:
            doc.insertNode(self.packages[name].node)

        for comp_node in doc_index.tags("Component"):
            doc.insertNode(comp_node)

        return doc.toPrettyString()
Beispiel #3
0
    def make_index(self, package_list):
        doc = piksemel.newDocument("PISI")

        # since new PiSi (pisi 2) needs component info in index file, we need to copy it from original index that user specified
        indexpath = fetch_uri(self.base_uri, self.cache_dir, self.index_name,
                              None, False)
        if indexpath.endswith(".bz2"):
            import bz2
            data = open(indexpath).read()
            data = bz2.decompress(data)
            doc_index = piksemel.parseString(data)
        elif indexpath.endswith(".xz"):
            try:
                import lzma
            except ImportError:
                print "Install python-pyliblzma package, or try a different index format."
                return

            data = open(indexpath).read()
            data = lzma.decompress(data)
            doc_index = piksemel.parseString(data)
        else:
            doc_index = piksemel.parse(indexpath)

        # old PiSi needs obsoletes list, so we need to copy it too.
        for comp_node in doc_index.tags("Distribution"):
            doc.insertNode(comp_node)

        for name in package_list:
            doc.insertNode(self.packages[name].node)

        for comp_node in doc_index.tags("Component"):
            doc.insertNode(comp_node)

        return doc.toPrettyString()
Beispiel #4
0
    def processPisi(self, path):
        zip = zipfile.ZipFile(path, "r")

        size = os.stat(path).st_size
        self.total_size += size

        doc = piksemel.parseString(zip.read("metadata.xml"))
        p = doc.getTag("Package")
        name = p.getTagData("Name")
        inst_size = int(p.getTagData("InstalledSize"))
        self.total_installed_size += inst_size

        doc = piksemel.parseString(zip.read("files.xml"))
        for item in doc.tags("File"):
            tname = item.getTagData("Type")
            sz = item.getTagData("Size")
            try:
                sz = int(sz)
            except:
                sz = 0
            if self.installed_sizes.has_key(tname):
                self.installed_sizes[tname] += sz
            else:
                self.installed_sizes[tname] = sz

        pak = packages.get(name, None)
        if not pak:
            return

        pak.size = size
        pak.installedSize = inst_size
Beispiel #5
0
def piksemelize(xml_path):
    """
        Uncompress and parse the given index file.
        return Piksemel Object.
    """

    if xml_path.endswith("bz2"):
        return piksemel.parseString(bz2.decompress(file(xml_path).read()))
    return piksemel.parseString(lzma.decompress(file(xml_path).read()))
Beispiel #6
0
def piksemelize(xml_path):
    """
        Uncompress and parse the given index file.
        return Piksemel Object.
    """

    if xml_path.endswith("bz2"):
        return piksemel.parseString(bz2.decompress(file(xml_path).read()))
    return piksemel.parseString(lzma.decompress(file(xml_path).read()))
Beispiel #7
0
def parse_paks():
    for pisi in pisi_paks(sys.argv[1]):
        zip = zipfileext.ZipFileExt(pisi, "r")
        data = zip.read("metadata.xml")
        doc = iks.parseString(data)
        name = doc.getTag("Package").getTagData("Name")
        data = zip.read("files.xml")
        doc = iks.parseString(data)
        for fi in doc.tags("File"):
            path = fi.getTagData("Path")
            if files.has_key(path):
                print "Package '%s' and '%s' has same file\n  %s\n" % (files[path], name, path)
            else:
                files[path] = name
Beispiel #8
0
    def parse_index(self, console=None, update_repo=False):
        path = fetch_uri(self.base_uri, self.cache_dir, self.index_name,
                         console, update_repo)
        if path.endswith(".bz2"):
            import bz2
            data = open(path).read()
            data = bz2.decompress(data)
            doc = piksemel.parseString(data)
        elif path.endswith(".xz"):
            try:
                import lzma
            except ImportError:
                print "Install python-pyliblzma package, or try a different index format."
                return

            data = open(path).read()
            data = lzma.decompress(data)
            doc = piksemel.parseString(data)
        else:
            doc = piksemel.parse(path)
        for tag in doc.tags('Package'):
            p = Package(tag)
            self.packages[p.name] = p
            self.size += p.size
            self.inst_size += p.inst_size
            if p.component not in self.components:
                self.components[p.component] = []
        for name in self.packages:
            p = self.packages[name]
            for name2 in p.depends:
                if self.packages.has_key(name2):
                    self.packages[name2].revdeps.append(p.name)
                else:
                    raise ExPackageMissing, (p.name, name2)
            if p.component in self.components:
                self.components[p.component].append(p.name)
            else:
                self.components[p.component] = []
        from pisi.graph import Digraph, CycleException
        dep_graph = Digraph()
        for name in self.packages:
            p = self.packages[name]
            for dep in p.depends:
                dep_graph.add_edge(name, dep)
        try:
            dep_graph.dfs()
        except CycleException, c:
            raise ExPackageCycle, (c.cycle)
def getPathsByPackageName(packageNames, index=None):
    if not index:
        index = os.path.join(ctx.consts.source_dir, "repo/pisi-index.xml.bz2")
    if index.endswith("bz2"):
        piksemelObj = piksemel.parseString(bz2.decompress(file(index).read()))
    else:
        piksemelObj = piksemel.parseString(lzma.decompress(file(index).read()))

    paths = []
    for package in piksemelObj.tags("Package"):
        for node in package.tags("Name"):
            name = node.firstChild().data()
            if name in packageNames:
                uri = package.getTagData("PackageURI")
                paths.append(os.path.join(ctx.consts.source_dir, "repo", uri))
    return paths
Beispiel #10
0
def clear_log(log):
    ''' Removes not needed lines from log output '''
    try:
        piks = piksemel.parseString(unicode(log))
        return piks.getAttribute('line'), piks.getTagData('paragraph')
    except:
        return 1, _('Rasta parse error: %s' % log)
    def run():
        try:
            os.makedirs('/etc/network')
        except:
            pass

        link = ComarLink()
        link.dump()
        reply = link.read_cmd()

        doc = piksemel.parseString(reply.data)
        for item in doc.tags():
            model, package, name = item.getTagData('key').split('/')
            if model == 'Net.Link':
                name = name.split('=')[1]
                config = {}
                for data in item.tags():
                    key = data.getAttribute('key')
                    value = data.getTagData('value')
                    if not value or key == 'name':
                        continue
                    config[key] = value
                fname = '/etc/network/%s' % package.replace('-', '_')
                f = file(fname, 'a')
                f.write('[%s]\n' % name)
                for key, value in config.iteritems():
                    f.write('%s = %s\n' % (key, value))
                f.write('\n')
                f.close()
                os.chmod(fname, 0600)
                print '%s - %s' % (package, name)
    def parseRepoIndex(self):
        self.printDebug("* Parsing package properties in new repo")

        pkgprop = {}
        obsoletelist = []
        ix = piksemel.parseString(self.nextRepoRaw)

        obsoleteParent = ix.getTag("Distribution").getTag("Obsoletes")
        for node in obsoleteParent.tags("Package"):
            obsoletelist.append(node.firstChild().data())

        for i in ix.tags("Package"):
            replaceslist = []

            pkgName = i.getTagData("Name")
            pkgURI = i.getTagData("PackageURI")
            pkgSize = int(i.getTagData("PackageSize"))
            pkgHash = i.getTagData("PackageHash")
            pkgInstalledSize = int(i.getTagData("InstalledSize"))

            replacedPackages = i.getTag("Replaces")

            if replacedPackages:
                for replaced in replacedPackages.tags("Package"):
                    replaceslist.append(replaced.firstChild().data())

            pkgprop[pkgName] = [replaceslist, pkgURI, pkgSize, pkgInstalledSize, pkgHash]

        self.printDebug("    found %d packages and %s obsoletelist" % (len(pkgprop.keys()), len(obsoletelist)))

        self.nextRepoPackages = pkgprop
        self.nextRepoObsoletes = obsoletelist
Beispiel #13
0
 def parsexml(self, xml):
     """parses xml string and returns DOM"""
     try:
         self.doc = iks.parseString(xml)
         return self.doc
     except Exception, e:
         raise Error(_("String '%s' has invalid XML") % (xml))
Beispiel #14
0
def clear_log(log):
    ''' Removes not needed lines from log output '''
    try:
        piks = piksemel.parseString(unicode(log))
        return piks.getAttribute('line'), piks.getTagData('paragraph')
    except:
        return 1, _('Rasta parse error: %s' % log)
Beispiel #15
0
 def parse_pisi(self, path):
     zip = zipfile.ZipFile(path, 'r')
     for info in zip.infolist():
         if info.filename == "metadata.xml":
             data = zip.read(info.filename)
             doc = iks.parseString(data)
             Package(self, self.list, path, doc)
Beispiel #16
0
    def __init__(self, index):

        self.__source_nodes = {}
        self.__pkgstosrc = {}

        doc = piksemel.parseString(index)
        self.__source_nodes, self.__pkgstosrc = self.__generate_sources(doc)
Beispiel #17
0
def parseRepo(repoURI):
    pkgdict = {}

    rawData = getIndex(repoURI)
    doc = piksemel.parseString(rawData)
    hasSpecFile = doc.getTag("SpecFile")

    if hasSpecFile:
        for parent in doc.tags("SpecFile"):
            pkgname = parent.getTag("Source").getTagData("Name")
            srcname = pkgname

            partof = parent.getTag("Source").getTagData("PartOf")

            lastRelease = parent.getTag("History").tags("Update").next()
            release = lastRelease.getAttribute("release")

            pkgdict[srcname] = [partof, release]
    else:
        for parent in doc.tags("Package"):
            pkgname = parent.getTagData("Name")
            srcname = parent.getTag("Source").getTagData("Name")

            partof = parent.getTagData("PartOf")

            lastRelease = parent.getTag("History").tags("Update").next()
            release = lastRelease.getAttribute("release")

            pkgdict[srcname] = [partof, release]

    return pkgdict
Beispiel #18
0
def getSourceIndex(indexfile):
    if indexfile.endswith(".bz2"):
        import bz2
        data = file(indexfile).read()
        data = bz2.decompress(data)
        doc = piksemel.parseString(data)
    else:
        doc = piksemel.parse(indexfile)
    sources = {}
    packages = {}
    base = []
    for tag in doc.tags("SpecFile"):
        name = tag.getTag("Source").getTagData("Name")
        sources[name] = {}
        version = tag.getTag('History').getTag('Update').getTagData('Version')
        release = tag.getTag('History').getTag('Update').getAttribute(
            'release')
        sources[name]["version"] = "%s-%s" % (version, release)
        sources[name]["deps"] = []
        sources[name]["packages"] = []
        for pak in tag.tags("Package"):
            packages[pak.getTagData("Name")] = name
            sources[name]["packages"].append(pak.getTagData("Name"))
        deps = tag.getTag("Source").getTag("BuildDependencies")
        if deps:
            sources[name]["deps"] = []
            for dep in deps.tags("Dependency"):
                sources[name]["deps"].append(dep.firstChild().data())
        if tag.getTag("Source").getTagData("PartOf") in [
                "system.base", "system.devel"
        ]:
            base.extend(sources[name]["packages"])
    return sources, packages, base
Beispiel #19
0
def main():
    if os.getuid() != 0:
        print 'Must be run as root'
        return 1

    link = ComarLink()
    link.dump()
    reply = link.read_cmd()

    doc = piksemel.parseString(reply.data)
    for item in doc.tags():
        model, package, name = item.getTagData('key').split('/')
        if model == 'Net.Link':
            name = name.split('=')[1]
            config = {}
            for data in item.tags():
                key = data.getAttribute('key')
                value = data.getTagData('value')
                if not value:
                    continue
                config[key] = value
            db = pardus.iniutils.iniDB('/etc/network/%s' % package)
            db.setDB(name, config)
            print '%s - %s' % (package, name)

    return 0
Beispiel #20
0
def main():
    if os.getuid() != 0:
        print 'Must be run as root'
        return 1
    
    link = ComarLink()
    link.dump()
    reply = link.read_cmd()
    
    doc = piksemel.parseString(reply.data)
    for item in doc.tags():
        model, package, name = item.getTagData('key').split('/')
        if model == 'Net.Link':
            name = name.split('=')[1]
            config = {}
            for data in item.tags():
                key = data.getAttribute('key')
                value = data.getTagData('value')
                if not value:
                    continue
                config[key] = value
            db = pardus.iniutils.iniDB('/etc/network/%s' % package)
            db.setDB(name, config)
            print '%s - %s' % (package, name)
    
    return 0
Beispiel #21
0
    def parseRepoIndex(self):
        self.printDebug("* Parsing package properties in new repo")

        pkgprop = {}
        obsoletelist = []
        ix = piksemel.parseString(self.nextRepoRaw)

        obsoleteParent = ix.getTag("Distribution").getTag("Obsoletes")
        for node in obsoleteParent.tags("Package"):
            obsoletelist.append(node.firstChild().data())

        for i in ix.tags("Package"):
            replaceslist = []

            pkgName = i.getTagData("Name")
            pkgURI = i.getTagData("PackageURI")
            pkgSize = int(i.getTagData("PackageSize"))
            pkgHash = i.getTagData("PackageHash")
            pkgInstalledSize = int(i.getTagData("InstalledSize"))

            replacedPackages = i.getTag("Replaces")

            if replacedPackages:
                for replaced in replacedPackages.tags("Package"):
                    replaceslist.append(replaced.firstChild().data())

            pkgprop[pkgName] = [
                replaceslist, pkgURI, pkgSize, pkgInstalledSize, pkgHash
            ]

        self.printDebug("    found %d packages and %s obsoletelist" %
                        (len(pkgprop.keys()), len(obsoletelist)))

        self.nextRepoPackages = pkgprop
        self.nextRepoObsoletes = obsoletelist
Beispiel #22
0
def getPathsByPackageName(packageNames, index=None):
    if not index:
        index = os.path.join(ctx.consts.source_dir, "repo/pisi-index.xml.bz2")
    if index.endswith("bz2"):
        piksemelObj = piksemel.parseString(bz2.decompress(file(index).read()))
    else:
        piksemelObj = piksemel.parseString(lzma.decompress(file(index).read()))

    paths = []
    for package in piksemelObj.tags("Package"):
        for node in package.tags("Name"):
            name = node.firstChild().data()
            if name in packageNames:
                uri = package.getTagData("PackageURI")
                paths.append(os.path.join(ctx.consts.source_dir, 'repo', uri))
    return paths
Beispiel #23
0
 def parse_index(self, console=None, update_repo=False):
     path = fetch_uri(self.base_uri, self.cache_dir, self.index_name, console, update_repo)
     if path.endswith(".bz2"):
         import bz2
         data = file(path).read()
         data = bz2.decompress(data)
         doc = piksemel.parseString(data)
     else:
         doc = piksemel.parse(path)
     for tag in doc.tags('Package'):
         p = Package(tag)
         self.packages[p.name] = p
         self.size += p.size
         self.inst_size += p.inst_size
         self.components[p.component] = []
     for name in self.packages:
         p = self.packages[name]
         for name2 in p.depends:
             if self.packages.has_key(name2):
                 self.packages[name2].revdeps.append(p.name)
             else:
                 print "Error: package %s depends on non existing package %s" % (p.name, name2)
         if self.components.has_key(p.component):
             self.components[p.component].append(p.name)
     from pisi.graph import Digraph, CycleException
     dep_graph = Digraph()
     for name in self.packages:
         p = self.packages[name]
         for dep in p.depends:
             dep_graph.add_edge(name, dep)
     try:
         dep_graph.dfs()
     except CycleException, c:
         print "Error: Cyclic dependency detected: %s" % " -> ".join(c.cycle)
         sys.exit(1)
Beispiel #24
0
 def parsexml(self, xml):
     """parses xml string and returns DOM"""
     try:
         self.doc = iks.parseString(xml)
         return self.doc
     except Exception, e:
         raise Error(_("String '%s' has invalid XML") % (xml))
def getSourceIndex(indexfile):
    if indexfile.endswith(".bz2"):
        import bz2

        data = file(indexfile).read()
        data = bz2.decompress(data)
        doc = piksemel.parseString(data)
    else:
        doc = piksemel.parse(indexfile)
    sources = {}
    packages = {}
    base = []
    for tag in doc.tags("SpecFile"):
        name = tag.getTag("Source").getTagData("Name")
        sources[name] = {}
        version = tag.getTag("History").getTag("Update").getTagData("Version")
        release = tag.getTag("History").getTag("Update").getAttribute("release")
        sources[name]["version"] = "%s-%s" % (version, release)
        sources[name]["deps"] = []
        sources[name]["packages"] = []
        for pak in tag.tags("Package"):
            packages[pak.getTagData("Name")] = name
            sources[name]["packages"].append(pak.getTagData("Name"))
        deps = tag.getTag("Source").getTag("BuildDependencies")
        if deps:
            sources[name]["deps"] = []
            for dep in deps.tags("Dependency"):
                sources[name]["deps"].append(dep.firstChild().data())
        if tag.getTag("Source").getTagData("PartOf") in ["system.base", "system.devel"]:
            base.extend(sources[name]["packages"])
    return sources, packages, base
Beispiel #26
0
    def parse_index(self, console=None, update_repo=False):
        path = fetch_uri(self.base_uri, self.cache_dir, self.index_name, console, update_repo)
        if path.endswith(".bz2"):
            import bz2
            data = open(path).read()
            data = bz2.decompress(data)
            doc = piksemel.parseString(data)
        elif path.endswith(".xz"):
            try:
                import lzma
            except ImportError:
                print "Install python-pyliblzma package, or try a different index format."
                return

            data = open(path).read()
            data = lzma.decompress(data)
            doc = piksemel.parseString(data)
        else:
            doc = piksemel.parse(path)
        for tag in doc.tags('Package'):
            p = Package(tag)
            self.packages[p.name] = p
            self.size += p.size
            self.inst_size += p.inst_size
            if p.component not in self.components:
                self.components[p.component] = []
        for name in self.packages:
            p = self.packages[name]
            for name2 in p.depends:
                if self.packages.has_key(name2):
                    self.packages[name2].revdeps.append(p.name)
                else:
                    raise ExPackageMissing, (p.name, name2)
            if p.component in self.components:
                self.components[p.component].append(p.name)
            else:
                self.components[p.component] = []
        from pisi.graph import Digraph, CycleException
        dep_graph = Digraph()
        for name in self.packages:
            p = self.packages[name]
            for dep in p.depends:
                dep_graph.add_edge(name, dep)
        try:
            dep_graph.dfs()
        except CycleException, c:
            raise ExPackageCycle, (c.cycle)
Beispiel #27
0
 def __make_dependency(self, depStr):
     node = piksemel.parseString(depStr)
     dependency = pisi.dependency.Dependency()
     dependency.package = node.firstChild().data()
     if node.attributes():
         attr = node.attributes()[0]
         dependency.__dict__[attr] = node.getAttribute(attr)
     return dependency
 def __make_dependency(self, depStr):
     node = piksemel.parseString(depStr)
     dependency = pisi.dependency.Dependency()
     dependency.package = node.firstChild().data()
     if node.attributes():
         attr = node.attributes()[0]
         dependency.__dict__[attr] = node.getAttribute(attr)
     return dependency
Beispiel #29
0
 def parsexml(self, xml):
     """parses xml string and returns DOM"""
     try:
         self.doc = iks.parseString(xml.decode() if type(xml) ==
                                    bytes else xml)
         return self.doc
     except Exception as e:
         raise Error(_("String '%s' has invalid XML") % (xml))
    def convertToPisiRepoDB(self, ix):
        self.printDebug("* Converting package objects to db object")

        doc = piksemel.parseString(ix)
        dbobj = pisi.index.Index()
        dbobj.decode(doc, [])

        self.printDebug("    done")
        return dbobj
def getXmlData(_file):
    if os.path.exists(_file):
        return piksemel.parse(_file)
    elif os.path.exists("%s.bz2" % _file):
        indexdata = bz2.decompress(file("%s.bz2" % _file).read())
        return piksemel.parseString(indexdata)
    else:
        print "%s not found" % indexfile
        sys.exit(1)
Beispiel #32
0
def getPackages(tag=None, value=None, index=None):
    if not index:
        index = os.path.join(ctx.consts.source_dir, "repo/pisi-index.xml.bz2")
    if index.endswith("bz2"):
        piksemelObj = piksemel.parseString(bz2.decompress(file(index).read()))
    else:
        piksemelObj = piksemel.parseString(lzma.decompress(file(index).read()))
    ret = []
    for package in piksemelObj.tags("Package"):
        tagData = package.getTagData(tag)
        if tagData:
            for node in package.tags(tag):
                data = node.firstChild().data()
                #if (not data.find(':') == -1 and data.startswith(value)) or (data.find(':') == -1 and data == value):
                #Really don't understand why this control clauses used.
                if data.startswith(value):
                    ret.append("%s,%s" % (package.getTagData("PackageURI"), data))
    return ret
Beispiel #33
0
def parseXml():
    xmlStr = extractData("repo/pisi-index.xml.bz2")
    doc = piksemel.parseString(xmlStr)
    installedsize = 0
    for tags in doc.tags("Package"):
        sizes = int(tags.getTagData("InstalledSize"))
        installedsize += int(sizes)
    architecture = tags.getTagData("Architecture")
    return installedsize, architecture
Beispiel #34
0
    def convertToPisiRepoDB(self, ix):
        self.printDebug("* Converting package objects to db object")

        doc = piksemel.parseString(ix)
        dbobj = pisi.index.Index()
        dbobj.decode(doc, [])

        self.printDebug("    done")
        return dbobj
def getPackages(tag=None, value=None, index=None):
    if not index:
        index = os.path.join(ctx.consts.source_dir, "repo/pisi-index.xml.bz2")
    if index.endswith("bz2"):
        piksemelObj = piksemel.parseString(bz2.decompress(file(index).read()))
    else:
        piksemelObj = piksemel.parseString(lzma.decompress(file(index).read()))
    ret = []
    for package in piksemelObj.tags("Package"):
        tagData = package.getTagData(tag)
        if tagData:
            for node in package.tags(tag):
                data = node.firstChild().data()
                # if (not data.find(':') == -1 and data.startswith(value)) or (data.find(':') == -1 and data == value):
                # Really don't understand why this control clauses used.
                if data.startswith(value):
                    ret.append("%s,%s" % (package.getTagData("PackageURI"), data))
    return ret
Beispiel #36
0
    def __add_to_revdeps(self, package, revdeps):
        data = gzip.zlib.decompress(self.installed_db[package])
        doc = piksemel.parseString(data)
        name = doc.getTag('Name')
        deps = doc.getTag('RuntimeDependencies')

        if deps:
            for dep in deps.tags("Dependency"):
                revdeps.setdefault(dep.firstChild().data(), set()).add((name, dep.toString()))
Beispiel #37
0
def getXmlData(_file):
    if os.path.exists(_file):
        return piksemel.parse(_file)
    elif os.path.exists("%s.bz2" % _file):
        indexdata = bz2.decompress(file("%s.bz2" % _file).read())
        return piksemel.parseString(indexdata)
    else:
        print "%s not found" % indexfile
        sys.exit(1)
Beispiel #38
0
def parseXml():
    xmlStr = extractData("repo/pisi-index.xml.bz2")
    doc = piksemel.parseString(xmlStr)
    installedsize = 0
    for tags in doc.tags("Package"):
        sizes = int(tags.getTagData("InstalledSize"))
        installedsize += int(sizes)
    architecture = tags.getTagData("Architecture")
    return installedsize, architecture
Beispiel #39
0
    def __add_to_revdeps(self, package, revdeps):
        data = gzip.zlib.decompress(self.installed_db[package])
        doc = piksemel.parseString(data)
        name = doc.getTag('Name')
        deps = doc.getTag('RuntimeDependencies')

        if deps:
            for dep in deps.tags("Dependency"):
                revdeps.setdefault(dep.firstChild().data(), set()).add(
                    (name, dep.toString()))
Beispiel #40
0
def parseRepoIndex(index):
    """Method for parsing repo index into a comma separated file containing only
    package name, version and release information."""

    if index.endswith("bz2"):
        doc = piksemel.parseString(bz2.decompress(file(index).read()))
    else:
        doc = piksemel.parse(index)

    return [p.getTagData("PackageURI") for p in doc.tags("Package")]
Beispiel #41
0
def getCollectionPackages(collectionIndex, kernels=False):
    ctx.logger.debug("index_path%s" % collectionIndex)
    if collectionIndex.endswith("bz2"):
        piksemelObj = piksemel.parseString(bz2.decompress(file(collectionIndex).read()))
    else:
        piksemelObj = piksemel.parseString(lzma.decompress(file(collectionIndex).read()))
    collectionPackages = []
    for package in piksemelObj.tags("Package"):
        # ignorekernel assignment changes kernel packages adding into package list
        if kernels:
            partof =  package.getTagData("PartOf")
            # Get collection packages without all kernel components
            if partof and partof.startswith("kernel"):
                continue
            else:
                tagData = package.getTagData("PackageURI")
        else:
            tagData = package.getTagData("PackageURI")
        collectionPackages.append(tagData)
    return collectionPackages
Beispiel #42
0
def getLicense(pisi):
    zip_archive = zipfile.ZipFile(pisi, "r")
    data = zip_archive.read(metadata_file)

    nod_tree = piksemel.parseString(data)
    license = nod_tree.getTag('Package').getTagData('License')

    listoflisence.append(license)
    print "%s package lisence  : %s " % (pisi, license)

    zip_archive.close()
Beispiel #43
0
    def get_version(self, name, repo):
        if not self.has_package(name, repo):
            raise Exception(_('Package %s not found.') % name)
            
        pkg_doc = piksemel.parseString(self.pdb.get_item(name, repo))
        history = pkg_doc.getTag("History")
        build = pkg_doc.getTagData("Build")
        version = history.getTag("Update").getTagData("Version")
        release = history.getTag("Update").getAttribute("release")

        return version, release, build and int(build)
Beispiel #44
0
    def get_version(self, name, repo):
        if not self.has_package(name, repo):
            raise Exception(_('Package %s not found.') % name)
            
        pkg_doc = piksemel.parseString(self.pdb.get_item(name, repo))
        history = pkg_doc.getTag("History")
        build = pkg_doc.getTagData("Build")
        version = history.getTag("Update").getTagData("Version")
        release = history.getTag("Update").getAttribute("release")

        return version, release, build and int(build)
Beispiel #45
0
def getLicense(pisi):
    zip_archive = zipfile.ZipFile(pisi, "r")
    data = zip_archive.read(metadata_file)

    nod_tree = piksemel.parseString(data)
    license = nod_tree.getTag('Package').getTagData('License')

    listoflisence.append(license)
    print "%s package lisence  : %s " % ( pisi , license)

    zip_archive.close()
def getCollectionPackages(collectionIndex, kernels=False):
    ctx.logger.debug("index_path%s" % collectionIndex)
    if collectionIndex.endswith("bz2"):
        piksemelObj = piksemel.parseString(bz2.decompress(file(collectionIndex).read()))
    else:
        piksemelObj = piksemel.parseString(lzma.decompress(file(collectionIndex).read()))
    collectionPackages = []
    for package in piksemelObj.tags("Package"):
        # ignorekernel assignment changes kernel packages adding into package list
        if kernels:
            partof = package.getTagData("PartOf")
            # Get collection packages without all kernel components
            if partof and partof.startswith("kernel"):
                continue
            else:
                tagData = package.getTagData("PackageURI")
        else:
            tagData = package.getTagData("PackageURI")
        collectionPackages.append(tagData)
    return collectionPackages
Beispiel #47
0
def parse_paks():
    for pisi in pisi_paks(sys.argv[1]):
        zip = zipfile.ZipFile(pisi, "r")
        data = zip.read("metadata.xml")
        doc = iks.parseString(data)
        name = doc.getTag("Package").getTagData("Name")
        data = zip.read("files.xml")
        doc = iks.parseString(data)
        for fi in doc.tags("File"):
            path = fi.getTagData("Path")
            if fi.getTag("Hash"):
                if files.has_key(path):
                    files[path].append(name)
                else:
                    files[path] = [name]

    for path in files:
        if len(files[path]) > 1:
            print "File '%s' is duplicated in:" % path
            print "  %s" % "\n  ".join(files[path])
            print
Beispiel #48
0
def getDocument(filetype, _url):
    rawdata = readFileFrom(_url)
    if filetype == "xz":
        data = lzma.decompress(rawdata.read())

    elif filetype == "bzip2":
        data = bz2.decompress(rawdata.read())

    else:
        fail("not support filetype %s for decompress" % filetype)

    return piksemel.parseString(data)
def getDocument( filetype, _url ):
    rawdata = readFileFrom( _url )
    if filetype == "xz":
        data = lzma.decompress( rawdata.read() )

    elif filetype == "bzip2":
        data = bz2.decompress( rawdata.read() )

    else:
        fail("not support filetype %s for decompress" % filetype)

    return piksemel.parseString(data)
Beispiel #50
0
def getPackages(tag, value):
    index_path = os.path.join(consts.source_dir, "repo/pisi-index.xml.bz2")
    piksemelObj = piksemel.parseString(bz2.decompress(file(index_path).read()))
    ret = []
    for package in piksemelObj.tags("Package"):
        tagData = package.getTagData(tag)
        if tagData:
            for node in package.tags(tag):
                data = node.firstChild().data()
                if (not data.find(':') == -1 and data.startswith(value)) or (data.find(':') == -1 and data == value):
                    ret.append("%s,%s" % (package.getTagData("PackageURI"), data))
    return ret
Beispiel #51
0
def parse_paks():
    for pisi in pisi_paks(sys.argv[1]):
        zip = zipfile.ZipFile(pisi, "r")
        data = zip.read("metadata.xml")
        doc = iks.parseString(data)
        name = doc.getTag("Package").getTagData("Name")
        data = zip.read("files.xml")
        doc = iks.parseString(data)
        for fi in doc.tags("File"):
            path = fi.getTagData("Path")
            if fi.getTag("Hash"):
                if files.has_key(path):
                    files[path].append(name)
                else:
                    files[path] = [ name ]

    for path in files:
        if len(files[path]) > 1:
            print "File '%s' is duplicated in:" % path
            print "  %s" % "\n  ".join(files[path])
            print
Beispiel #52
0
 def __init__(self, path=None, xmlstring=None):
     doc = None
     if path:
         if xmlstring:
             raise TypeError("Don't use both path and xmlstring in AutoPiksemel()")
         doc = piksemel.parse(path)
     elif xmlstring:
         doc = piksemel.parseString(xmlstring)
     if doc:
         errors = []
         self._autoPiks(doc, errors)
         if len(errors) > 0:
             raise InvalidDocument("\n".join(errors))
Beispiel #53
0
 def __init__(self, path=None, xmlstring=None):
     doc = None
     if path:
         if xmlstring:
             raise TypeError("Don't use both path and xmlstring in AutoPiksemel()")
         doc = piksemel.parse(path)
     elif xmlstring:
         doc = piksemel.parseString(xmlstring)
     if doc:
         errors = []
         self._autoPiks(doc, errors)
         if len(errors) > 0:
             raise InvalidDocument("\n".join(errors))
def getMyPackages(index, me):
    global countPackages
    if index.endswith("xz"):
        doc = piksemel.parseString(lzma.decompress(file(index).read()))
    elif index.endswith("bz2"):
        doc = piksemel.parseString(bz2.decompress(file(index).read()))
    else:
        panic()

    for spec in doc.tags("Package"):
        packager = spec.getTag("Source").getTag("Packager").getTagData("Name")
        package = spec.getTag("Source").getTagData("Name")
        subPackage = spec.getTagData("Name")

        if packager == me:
            if myPackages.has_key(package):
                myPackages[package].append(subPackage)
            else:
                countPackages += 1
                myPackages[package] = [subPackage]

    return myPackages
Beispiel #55
0
def getMyPackages(index, me):
    global countPackages
    if index.endswith("xz"):
        doc = piksemel.parseString(lzma.decompress(file(index).read()))
    elif index.endswith("bz2"):
        doc = piksemel.parseString(bz2.decompress(file(index).read()))
    else:
        panic()

    for spec in doc.tags("Package"):
        packager = spec.getTag("Source").getTag("Packager").getTagData("Name")
        package = spec.getTag("Source").getTagData("Name")
        subPackage = spec.getTagData("Name")

        if packager == me:
            if myPackages.has_key(package):
                myPackages[package].append(subPackage)
            else:
                countPackages += 1
                myPackages[package] = [subPackage]

    return myPackages
Beispiel #56
0
    def __slot_check(self):
        """
            Fetches URL and checks for errors.
        """
        if len(self.editURL.text()):
            repo_url = str(self.editURL.text())

            progress = wrappers.Progress(self)
            progress.started("Fetching...")

            try:
                connection = urllib2.urlopen(repo_url)
            except ValueError:
                progress.finished()
                QtGui.QMessageBox.warning(self, "Connection Error",
                                          "Unable to download %s" % repo_url)
                return

            output = os.tmpfile()
            total_size = int(connection.info()['Content-Length'])
            size = 0
            while size < total_size:
                data = connection.read(4096)
                output.write(data)
                size += len(data)
                progress.progress("%d / %d" % (size, total_size),
                                  100 * size / total_size)
            output.seek(0)
            data = output.read()
            output.close()
            connection.close()
            progress.finished()

            if repo_url.endswith(".bz2"):
                import bz2
                data = bz2.decompress(data)

            import piksemel
            try:
                tag = piksemel.parseString(data).getTag("Distribution")
                name = "%s-%s" % (tag.getTagData("SourceName"),
                                  tag.getTagData("Version"))
            except:
                QtGui.QMessageBox.warning(self, "Connection Error",
                                          "Unable to download %s" % repo_url)
                name = ""

            if not len(self.editName.text()):
                name = name.replace(" ", "-")
                self.editName.setText(name)
Beispiel #57
0
    def get_rev_deps(self, name):

        rev_deps = []

        if self.rev_deps_db.has_key(name):
            for pkg, dep in self.rev_deps_db[name]:
                node = piksemel.parseString(dep)
                dependency = pisi.dependency.Dependency()
                dependency.package = node.firstChild().data()
                if node.attributes():
                    attr = node.attributes()[0]
                    dependency.__dict__[attr] = node.getAttribute(attr)
                rev_deps.append((pkg, dependency))

        return rev_deps
Beispiel #58
0
    def get_replaces(self, repo=None):
        pairs = {}

        for pkg_name in self.rpdb.get_list_item():
            xml = self.pdb.get_item(pkg_name, repo)
            package = piksemel.parseString(xml)
            replaces_tag = package.getTag("Replaces")
            if replaces_tag:
                for node in replaces_tag.tags("Package"):
                    r = pisi.relation.Relation()
                    # XXX Is there a better way to do this?
                    r.decode(node, [])
                    if pisi.replace.installed_package_replaced(r):
                        pairs.setdefault(r.package, []).append(pkg_name)

        return pairs