Beispiel #1
0
 def getFileName(self, info):
     name = info._package.name
     version, arch = splitarch(info._package.version)
     version = EPOCHRE.sub("", version)
     filename = "%s-%s.%s.rpm" % (name, version, arch)
     if filename in self._prefix:
         filename = os.path.join(self._prefix[filename], filename)
     return filename
Beispiel #2
0
    def getURLs(self):
        version, arch = splitarch(self._package.version)

        # replace last digit with media number as yast does
        baseurl = self._loader._baseurl.rstrip("/")
        if baseurl[-1:] == "1" and not baseurl[-2:-1].isdigit():
            baseurl = baseurl.rstrip("1")
            baseurl += self._info.get("media")

        return [posixpath.join(baseurl, self._loader._datadir, arch, self._info.get("filename"))]
Beispiel #3
0
    def parseEntry(self):
        Pkg = RPMPackage
        Req = RPMRequires
        Prq = RPMPreRequires
        Prv = RPMProvides
        Con = RPMConflicts
        Obs = RPMObsoletes
        NPrv = RPMNameProvides
        # SUSE fields not yet handled
        # Rec / Sug / Src / Aut / Key

        requires = ()
        provides = ()
        conflicts = ()
        obsoletes = ()

        # avoid parsing errors on undefined fields
        requires = prequire = conflicts = obsoletes = []
        group = summary = description = size = instsize = filename = media = ""

        for line in self._pkgentry:
            kw = line[:4]
            if kw == "=Pkg":
                entryname = line[6:]
                nameparts = entryname.split(" ")

                try:
                    # skip entry if arch is not compatible
                    arch = nameparts[3]
                except IndexError:
                    raise Error("Error loading YaST2 channel info. Possibly " \
                                "corrupted file.\n%s" % self._pkginfofile)
                
                if getArchScore(arch) == 0:
                    return
                name = nameparts[0]
                self.curpkgname = name
                version = nameparts[1]
                release = nameparts[2]
                versionarch = "%s-%s@%s" % \
                               (version, release, arch)
            elif kw == "+Req":
                requires = self.getInfoEntity("Req")
            elif kw == "+Prq":
                prequire = self.getInfoEntity("Prq")
            elif kw == "+Prv":
                provides = self.getInfoEntity("Prv")
            elif kw == "+Con":
                conflicts = self.getInfoEntity("Con")
            elif kw == "+Obs":
                obsoletes = self.getInfoEntity("Obs")
            elif kw == "=Loc":
                locparts = line[6:].split(" ")
                media = locparts[0]
                filename = locparts[1]
            elif kw == "=Siz":
                sizeparts = line[6:].split(" ")
                size = sizeparts[0]
                instsize = sizeparts[1]
            elif kw == "=Grp":
                group = line[6:]
            elif kw == "=Shr":
                shares = line[6:].split()
                for pkgshr in self._packages:
                    shrver, shrarch = splitarch(pkgshr.version)
                    if (pkgshr.name == name and 
                    (shrver == (shares[1]+"-"+shares[2]) and shrarch == shares[3])):
                        shrinfo = self.getInfo(pkgshr)
                        summary = shrinfo.getSummary()
                        description = shrinfo.getDescription()
                        break
        
        if summary == "" and description == "":
            summary, description = self.readPkgSummDesc(entryname)

        info = { "summary"     : summary,
                 "description" : description,
                 "size"        : size,
                 "instsize"    : instsize,
                 "group"       : group,
                 "media"       : media,
                 "filename"    : filename }
                 
        prvdict = {}
        for n, r, v in provides:
            if n == name and v == version + "-" + release:
                prv = (NPrv, n, versionarch)
            else:
                prv = (Prv, n, v)
            prvdict[prv] = True

        reqdict = {}
        for n, r, v in requires:
            if not ((r is None or "=" in r) and (Prv, n, v) in prvdict or
                    system_provides.match(n, r, v)):
                    reqdict[(Req, n, r, v)] = True
        for n, r, v in prequire:
            if not ((r is None or "=" in r) and (Prv, n, v) in prvdict or
                    system_provides.match(n, r, v)):
                    reqdict[(Prq, n, r, v)] = True

        cnfdict = {}
        for n, r, v in conflicts:
            cnfdict[(Con, n, r, v)] = True
                        
        upgdict = {}
        upgdict[(Obs, name, "<", versionarch)] = True
                   
        for n, r, v in obsoletes:
            upg = (Obs, n, r, v)
            upgdict[upg] = True
            cnfdict[upg] = True
                    
        pkg = self.buildPackage((Pkg, name, versionarch),
                                prvdict.keys(), collapse_libc_requires(reqdict.keys()),
                                upgdict.keys(), cnfdict.keys())
                    
        pkg.loaders[self] = info
Beispiel #4
0
def main(ctrl, opts):
 
    # Argument check
    if not opts.args:
        raise Error, _("no package(s) given")

    if opts.attempt:
	sysconf.set("attempt-install", True, soft=True)

    if opts.explain:
        sysconf.set("explain-changesets", True, soft=True)

    urls = []
    for arg in opts.args[:]:
        if (os.path.isfile(arg) and
            '/' in arg or ctrl.checkPackageFile(arg)):
            ctrl.addFileChannel(arg)
            opts.args.remove(arg)
        elif ":/" in arg:
            urls.append(arg)
    if urls:
        succ, fail = ctrl.downloadURLs(urls, _("packages"),
                                       targetdir=os.getcwd())
        if fail:
            raise Error, _("Failed to download packages:\n") + \
                         "\n".join(["    %s: %s" % (url, fail[url])
                                    for url in fail])
        for url, file in succ.items():
            ctrl.addFileChannel(file)
            opts.args.remove(url)
    if sysconf.get("auto-update"):
        from smart.commands import update
        updateopts = update.parse_options([])
        update.main(ctrl, updateopts)
    else:
        ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyInstall)
    for channel in ctrl.getFileChannels():
        for loader in channel.getLoaders():
            for pkg in loader.getPackages():
                if pkg.installed:
                    raise Error, _("%s is already installed") % pkg
                trans.enqueue(pkg, INSTALL)


    for arg in opts.args:

        ratio, results, suggestions = ctrl.search(arg)

        if not results:
            if suggestions:
                dct = {}
                for r, obj in suggestions:
                    if isinstance(obj, Package):
                        dct[obj] = True
                    else:
                        dct.update(dict.fromkeys(obj.packages, True))
                raise Error, _("'%s' matches no packages. "
                               "Suggestions:\n%s") % \
                             (arg, "\n".join(["    "+str(x) for x in dct]))
            else:
                raise Error, _("'%s' matches no packages") % arg

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            installed = False
            names = {}
            for obj in results:
                for pkg in obj.packages:
                    if pkg.installed:
                        iface.info(_("%s (for %s) is already installed")
                                      % (pkg, arg))
                        installed = True
                        break
                    else:
                        pkgs.append(pkg)
                        names[pkg.name] = True
                else:
                    continue
                break
            if installed:
                continue
            if len(names) == 2 and sysconf.get("rpm-strict-multilib"):
                from smart.backends.rpm.rpmver import splitarch
                # two packages with the same version but different arch, pick best
                if splitarch(pkgs[0].version)[0] == splitarch(pkgs[1].version)[0]:
                    pkg = max(pkgs[0], pkgs[1])
                    names.pop(pkg.name)
                    pkgs.remove(pkg)
            if len(names) > 1:
                raise Error, _("There are multiple matches for '%s':\n%s") % \
                              (arg, "\n".join(["    "+str(x) for x in pkgs]))

        if len(pkgs) > 1:
            sortUpgrades(pkgs)

        names = {}
        for pkg in pkgs:
            names.setdefault(pkg.name, []).append(pkg)
        for name in names:
            pkg = names[name][0]
            if pkg.installed:
                iface.info(_("%s is already installed") % pkg)
            else:
                trans.enqueue(pkg, INSTALL)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        confirm = not opts.yes
        if opts.urls:
            ctrl.dumpTransactionURLs(trans)
        elif opts.metalink:
            ctrl.dumpTransactionMetalink(trans)
        elif opts.dump:
            ctrl.dumpTransactionPackages(trans, install=True)
        elif opts.download:
            ctrl.downloadTransaction(trans, confirm=confirm)
        elif opts.stepped:
            ctrl.commitTransactionStepped(trans, confirm=confirm)
        else:
            ctrl.commitTransaction(trans, confirm=confirm)
Beispiel #5
0
 def getURLs(self):
     name = self._package.name
     version, arch = splitarch(self._package.version)
     version = EPOCHRE.sub("", version)
     return [posixpath.join(self._loader._baseurl,
                            "%s-%s.%s.rpm" % (name, version, arch))]
Beispiel #6
0
def main(ctrl, opts):

    # Argument check
    if not opts.args:
        raise Error, _("no package(s) given")

    if opts.attempt:
        sysconf.set("attempt-install", True, soft=True)

    if opts.explain:
        sysconf.set("explain-changesets", True, soft=True)

    urls = []
    for arg in opts.args[:]:
        if (os.path.isfile(arg) and '/' in arg or ctrl.checkPackageFile(arg)):
            ctrl.addFileChannel(arg)
            opts.args.remove(arg)
        elif ":/" in arg:
            urls.append(arg)
    if urls:
        succ, fail = ctrl.downloadURLs(urls,
                                       _("packages"),
                                       targetdir=os.getcwd())
        if fail:
            raise Error, _("Failed to download packages:\n") + \
                         "\n".join(["    %s: %s" % (url, fail[url])
                                    for url in fail])
        for url, file in succ.items():
            ctrl.addFileChannel(file)
            opts.args.remove(url)
    if sysconf.get("auto-update"):
        from smart.commands import update
        updateopts = update.parse_options([])
        update.main(ctrl, updateopts)
    else:
        ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyInstall)
    for channel in ctrl.getFileChannels():
        for loader in channel.getLoaders():
            for pkg in loader.getPackages():
                if pkg.installed:
                    raise Error, _("%s is already installed") % pkg
                trans.enqueue(pkg, INSTALL)

    for arg in opts.args:

        ratio, results, suggestions = ctrl.search(arg)

        if not results:
            if suggestions:
                dct = {}
                for r, obj in suggestions:
                    if isinstance(obj, Package):
                        dct[obj] = True
                    else:
                        dct.update(dict.fromkeys(obj.packages, True))
                raise Error, _("'%s' matches no packages. "
                               "Suggestions:\n%s") % \
                             (arg, "\n".join(["    "+str(x) for x in dct]))
            else:
                raise Error, _("'%s' matches no packages") % arg

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            installed = False
            names = {}
            for obj in results:
                for pkg in obj.packages:
                    if pkg.installed:
                        iface.info(
                            _("%s (for %s) is already installed") % (pkg, arg))
                        installed = True
                        break
                    else:
                        pkgs.append(pkg)
                        names[pkg.name] = True
                else:
                    continue
                break
            if installed:
                continue
            if len(names) == 2 and sysconf.get("rpm-strict-multilib"):
                from smart.backends.rpm.rpmver import splitarch
                # two packages with the same version but different arch, pick best
                if splitarch(pkgs[0].version)[0] == splitarch(
                        pkgs[1].version)[0]:
                    pkg = max(pkgs[0], pkgs[1])
                    names.pop(pkg.name)
                    pkgs.remove(pkg)
            if len(names) > 1:
                raise Error, _("There are multiple matches for '%s':\n%s") % \
                              (arg, "\n".join(["    "+str(x) for x in pkgs]))

        if len(pkgs) > 1:
            sortUpgrades(pkgs)

        names = {}
        for pkg in pkgs:
            names.setdefault(pkg.name, []).append(pkg)
        for name in names:
            pkg = names[name][0]
            if pkg.installed:
                iface.info(_("%s is already installed") % pkg)
            else:
                trans.enqueue(pkg, INSTALL)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        confirm = not opts.yes
        if opts.urls:
            ctrl.dumpTransactionURLs(trans)
        elif opts.metalink:
            ctrl.dumpTransactionMetalink(trans)
        elif opts.dump:
            ctrl.dumpTransactionPackages(trans, install=True)
        elif opts.download:
            ctrl.downloadTransaction(trans, confirm=confirm)
        elif opts.stepped:
            ctrl.commitTransactionStepped(trans, confirm=confirm)
        else:
            ctrl.commitTransaction(trans, confirm=confirm)
Beispiel #7
0
 def test_splitarch(self):
     version, arch = splitarch("1.0-1@i686")
     self.assertEquals(version, "1.0-1")
     self.assertEquals(arch, "i686")
 def test_splitarch(self):
     version, arch = splitarch("1.0-1@i686")
     self.assertEquals(version, "1.0-1")
     self.assertEquals(arch, "i686")