2cfb758d |
import json |
87815216 |
import os.path |
2cfb758d |
from Logger import Logger
from constants import constants
from CommandUtils import CommandUtils |
97a9151c |
from PackageUtils import PackageUtils |
45c9260c |
from SpecData import SPECS |
2cfb758d |
|
97a9151c |
class PackageInfo(object): |
2cfb758d |
|
97a9151c |
def __init__(self, logName=None, logPath=None): |
2cfb758d |
if logName is None: |
97a9151c |
logName = "PackageInfo" |
2cfb758d |
if logPath is None:
logPath = constants.logPath |
87815216 |
self.logName = logName
self.logPath = logPath |
26b55679 |
self.logger = Logger.getLogger(logName, logPath, constants.logLevel) |
97a9151c |
self.pkgList = {} |
2cfb758d |
|
97a9151c |
def loadPackagesData(self): |
87815216 |
listPackages = SPECS.getData().getListPackages() |
97a9151c |
listPackages.sort()
cmdUtils = CommandUtils()
for package in listPackages: |
0bea326a |
for version in SPECS.getData().getVersions(package):
release = SPECS.getData().getRelease(package, version)
listRPMPackages = SPECS.getData().getRPMPackages(package, version)
srpmFileName = package + "-" + version + "-" + release + ".src.rpm"
srpmFiles = cmdUtils.findFile(srpmFileName, constants.sourceRpmPath)
srpmFile = None
if len(srpmFiles) == 1:
srpmFile = srpmFiles[0]
debugrpmFileName = package + "-debuginfo-" + version + "-" + release + "*"
debugrpmFiles = cmdUtils.findFile(debugrpmFileName, constants.rpmPath)
debugrpmFile = None
if len(debugrpmFiles) == 1:
debugrpmFile = debugrpmFiles[0]
pkgUtils = PackageUtils(self.logName, self.logPath)
for rpmPkg in listRPMPackages: |
92ce7429 |
rpmFile = pkgUtils.findRPMFileForGivenPackage(rpmPkg, version) |
0bea326a |
if rpmFile is not None:
listPkgAttributes = {"sourcerpm":srpmFile, "rpm":rpmFile,
"debugrpm":debugrpmFile} |
92ce7429 |
self.pkgList[rpmPkg+"-"+version] = listPkgAttributes
self.logger.debug("Added " + rpmPkg + "-" + version + " to the package info json") |
0bea326a |
else: |
9bc3518e |
self.logger.debug("Missing rpm file for package:" + rpmPkg) |
2cfb758d |
|
97a9151c |
def writePkgListToFile(self, fileName): |
26b55679 |
self.logger.debug("Writing package list to the json file") |
87815216 |
cmdUtils = CommandUtils()
dirPath = os.path.basename(fileName)
if not os.path.isdir(dirPath):
cmdUtils.runCommandInShell("mkdir -p " + dirPath) |
326d5ca8 |
with open(fileName, 'w+') as pkgInfoFile:
json.dump(self.pkgList, pkgInfoFile, indent=4) |