示例#1
0
 def populateRPMSetFromDirectory(dirname, rpmdb):
     files = os.listdir(dirname)
     for fname in files:
         path = os.path.join(dirname, fname)
         if os.path.isdir(path):
             populateRPMSetFromDirectory(path, rpmdb)
         else:
             if fname.lower().endswith(".rpm"):
                 rpmdb.addRPM(RPM.fromFile(path))
示例#2
0
文件: repo.py 项目: johnmdilley/xenrt
 def populateRPMSetFromDirectory(dirname, rpmdb):
     files = os.listdir(dirname)
     for fname in files:
         path = os.path.join(dirname, fname)
         if os.path.isdir(path):
             populateRPMSetFromDirectory(path, rpmdb)
         else:
             if fname.lower().endswith(".rpm"):
                 rpmdb.addRPM(RPM.fromFile(path))
示例#3
0
def getSuseRPMSet(repoPath):
    _log(1, "Parsing SUSE repository package data...")

    packages_path = os.path.join(repoPath, "suse/setup/descr/packages")
    extra_prov_path = os.path.join(repoPath, "suse/setup/descr/EXTRA_PROV")

    package_fobj = open(packages_path, "r")

    rpmdb = RPMSet()

    # check the version of the file; we currently know how to read
    # version 2:
    next = package_fobj.readline().strip("\n").strip()
    if next[:5] == "=Ver:":
        version = next[len(next) - 3:]
        if version != "2.0":
            raise Exception(
                "Unable to deal with this version of repository: %s" % version)

    # now read the rest of the file:
    currentPackage = None
    inDeps = False
    inProvs = False
    for line in package_fobj:
        line = line.strip("\n")
        if line[:5] == "=Pkg:":
            if currentPackage:
                # we have a package ready to save:
                rpm = RPM(currentProvides, [], currentDepends,
                          currentPackageName, currentLocation)
                rpmdb.addRPM(rpm)

            # we have a new package - re-initialise the variables:
            currentPackage = None
            currentPackageName = ""
            currentArch = ""
            currentLocation = ""
            currentProvides = []
            currentDepends = []

            currentPackage = line[5:].strip().split(" ")
            currentPackageName = currentPackage[0]
            currentArch = currentPackage[3]

        if line[:5] == "=Loc:":
            values = line[5:].strip().split(" ")
            # we're not interested in src RPMs:
            if not (len(values) == 3 and values[2] == "src"):
                (disc, location) = values[:2]
                currentLocation = os.path.join(
                    os.path.join(repoPath, "suse/" + currentArch), location)

        if line[:5] == "-Req:" or line[:5] == "-Prq:":
            inDeps = False

        if line[:5] == "-Prv:":
            inProvs = False

        if inDeps: currentDepends.append(RPM.depFromString(line))

        if inProvs: currentProvides.append(RPM.provideFromString(line))

        if line[:5] == "+Req:" or line[:5] == "+Prq:":
            inDeps = True

        if line[:5] == "+Prv:":
            inProvs = True

    package_fobj.close()

    # Now read the EXTRA_PROV file if it exists... (ugh)
    if os.path.exists(extra_prov_path):
        extraprov_fobj = open(extra_prov_path, "r")

        for line in extraprov_fobj:
            line = line.strip("\n")
            (package, extraprov) = line.split(":\t")
            extraprov = extraprov.split(" ")

            rpms = rpmdb.whoProvides(RPM.provideFromString(package))
            for rpm in rpms:
                for prov in extraprov:
                    rpm.addProvides(RPM.provideFromString(prov))

        extraprov_fobj.close()

    # XXX SLES9 has a couple of extra files that aren't listed in its meta-data
    # We should abstract out classes for dealing with repos but for now we'll
    # hack this in here:
    extra_files = ['suse/i586/sles-release-9-82.11.i586.rpm']
    for f in extra_files:
        f = os.path.join(repoPath, f)
        if os.path.isfile(f):
            rpmdb.addRPM(RPM.fromFile(f))

    return rpmdb
示例#4
0
文件: repo.py 项目: johnmdilley/xenrt
def getSuseRPMSet(repoPath):
    _log(1, "Parsing SUSE repository package data...")

    packages_path = os.path.join(repoPath, "suse/setup/descr/packages")
    extra_prov_path = os.path.join(repoPath, "suse/setup/descr/EXTRA_PROV")

    package_fobj = open(packages_path, "r")

    rpmdb = RPMSet()

    # check the version of the file; we currently know how to read
    # version 2:
    next = package_fobj.readline().strip("\n").strip()
    if next[:5] == "=Ver:":
        version = next[len(next)-3:]
        if version != "2.0":
            raise Exception("Unable to deal with this version of repository: %s" % version)

    # now read the rest of the file:
    currentPackage = None
    inDeps = False
    inProvs = False
    for line in package_fobj:
        line = line.strip("\n")
        if line[:5] == "=Pkg:":
            if currentPackage:
                # we have a package ready to save:
                rpm = RPM(currentProvides, [], currentDepends,
                          currentPackageName, currentLocation)
                rpmdb.addRPM(rpm)

            # we have a new package - re-initialise the variables:
            currentPackage = None
            currentPackageName = ""
            currentArch = ""
            currentLocation = ""
            currentProvides = []
            currentDepends = []
            
            currentPackage = line[5:].strip().split(" ")
            currentPackageName = currentPackage[0]
            currentArch = currentPackage[3]

        if line[:5] == "=Loc:":
            values = line[5:].strip().split(" ")
            # we're not interested in src RPMs:
            if not (len(values) == 3 and values[2] == "src"):
                (disc, location) = values[:2]
                currentLocation = os.path.join(os.path.join(repoPath, "suse/" + currentArch), location)

        if line[:5] == "-Req:" or line[:5] == "-Prq:":
            inDeps = False

        if line[:5] == "-Prv:":
            inProvs = False

        if inDeps: currentDepends.append(RPM.depFromString(line))

        if inProvs: currentProvides.append(RPM.provideFromString(line))

        if line[:5] == "+Req:" or line[:5] == "+Prq:":
            inDeps = True

        if line[:5] == "+Prv:":
            inProvs = True

    package_fobj.close()

    # Now read the EXTRA_PROV file if it exists... (ugh)
    if os.path.exists(extra_prov_path):
        extraprov_fobj = open(extra_prov_path, "r")

        for line in extraprov_fobj:
            line = line.strip("\n")
            (package, extraprov) = line.split(":\t")
            extraprov = extraprov.split(" ")

            rpms = rpmdb.whoProvides(RPM.provideFromString(package))
            for rpm in rpms:
                for prov in extraprov:
                    rpm.addProvides(RPM.provideFromString(prov))

        extraprov_fobj.close()

    # XXX SLES9 has a couple of extra files that aren't listed in its meta-data
    # We should abstract out classes for dealing with repos but for now we'll
    # hack this in here:
    extra_files = ['suse/i586/sles-release-9-82.11.i586.rpm']
    for f in extra_files:
        f = os.path.join(repoPath, f)
        if os.path.isfile(f):
            rpmdb.addRPM(RPM.fromFile(f))

    return rpmdb