support/package-builder/PackageInfo.py
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
         self.logger = Logger.getLogger(logName, logPath)
97a9151c
         self.pkgList = {}
2cfb758d
 
97a9151c
     def loadPackagesData(self):
87815216
         listPackages = SPECS.getData().getListPackages()
97a9151c
         listPackages.sort()
         listRPMFiles = []
         cmdUtils = CommandUtils()
         for package in listPackages:
45c9260c
             release = SPECS.getData().getRelease(package)
             version = SPECS.getData().getVersion(package)
             listRPMPackages = SPECS.getData().getRPMPackages(package)
87815216
             srpmFileName = package + "-" + version + "-" + release + ".src.rpm"
97a9151c
             srpmFiles = cmdUtils.findFile(srpmFileName, constants.sourceRpmPath)
             srpmFile = None
             if len(srpmFiles) == 1:
                 srpmFile = srpmFiles[0]
87815216
             debugrpmFileName = package + "-debuginfo-" + version + "-" + release + "*"
97a9151c
             debugrpmFiles = cmdUtils.findFile(debugrpmFileName, constants.rpmPath)
             debugrpmFile = None
             if len(debugrpmFiles) == 1:
                 debugrpmFile = debugrpmFiles[0]
87815216
             pkgUtils = PackageUtils(self.logName, self.logPath)
97a9151c
             for rpmPkg in listRPMPackages:
                 rpmFile = pkgUtils.findRPMFileForGivenPackage(rpmPkg)
                 if rpmFile is not None:
                     listRPMFiles.append(rpmFile)
87815216
                     listPkgAttributes = {"sourcerpm":srpmFile, "rpm":rpmFile,
                                          "debugrpm":debugrpmFile}
97a9151c
                     self.pkgList[rpmPkg] = listPkgAttributes
87815216
                     self.logger.debug("Added " + rpmPkg + " rpm package to the list")
97a9151c
                 else:
87815216
                     self.logger.error("Missing rpm file for package:" + rpmPkg)
2cfb758d
 
97a9151c
     def writePkgListToFile(self, fileName):
87815216
         self.logger.info("Writing package list to the json file")
         cmdUtils = CommandUtils()
         dirPath = os.path.basename(fileName)
         if not os.path.isdir(dirPath):
             cmdUtils.runCommandInShell("mkdir -p " + dirPath)
         pkgInfoFile = open(fileName, 'w+')
         json.dump(self.pkgList, pkgInfoFile, indent=4)
         pkgInfoFile.close()