def init(self): repo = FakeRepository(self._fileName) header = rpmutils.readRpmHeader(self._fileName) if not header: return False RpmHeaderPackage.__init__(self, header, repo) return True
def _doRpmTransaction(self, operations, noDependents=False): ts = rpm.TransactionSet() for pkg, action in operations.iteritems(): if action == resolver.INSTALL: pkgPath = self._getRpmFilePath(pkg) if not pkgPath: Log.cout(Log.ERROR, 'Get pkg %s failed' % pkg) return False header = rpmutils.readRpmHeader(pkgPath) if header is None: Log.cout(Log.ERROR, 'Get pkg %s header failed' % pkg) return False ts.addInstall(header, pkgPath, 'u') elif action == resolver.REMOVE: ts.addErase(str(pkg)) unresolved = None if not noDependents: unresolved = ts.check() if not unresolved: ts.order() pkgDict = {} try: flags = rpm.RPMPROB_FILTER_OLDPACKAGE |\ rpm.RPMPROB_FILTER_REPLACEPKG ts.setProbFilter(flags) tsError = ts.run(self._runCallback, pkgDict) if tsError is None: return True Log.cout(Log.ERROR, 'Transaction run failed:%s' % tsError) return False except Exception, e: Log.cout(Log.ERROR, 'Rpm Transaction run failed:%s' % e) return False return True
def buildInstalledPkgSack(self): sack = PackageSack() ainstRoot = AinstRoot(self._installRoot) if not ainstRoot.isValidAinstRoot(): Log.cout(Log.DEBUG, '%s is invalid ainst root' % self._installRoot) return None reader = AinstRootReader(ainstRoot) installPkgMetas = reader.getInstallPkgMetas() if installPkgMetas is None: Log.cout(Log.DEBUG, 'Get install meta of %s failed' % self._installRoot) return None for pkgVer, rpmPath in installPkgMetas: header = rpmutils.readRpmHeader(rpmPath) if header: repo = FakeRepository(self._installRoot, True) pkg = AinstRpmPackage(header, repo) sack.addPackageObject(pkg) return sack
def buildActivePkgSack(self): sack = PackageSack() ainstRoot = AinstRoot(self._installRoot) if not ainstRoot.isValidAinstRoot(): Log.cout(Log.DEBUG, '%s is invalid ainst root' % self._installRoot) return None reader = AinstRootReader(ainstRoot) activePkgMetas = reader.getActivePkgMetas() if activePkgMetas is None: Log.cout(Log.DEBUG, 'Get active meta of %s failed' % self._installRoot) return None for pkgName, rpmPath, aicfPath in activePkgMetas: aicfInfo = None if file_util.isFile(aicfPath): aicfInfo = AicfParser().parse(aicfPath) header = rpmutils.readRpmHeader(rpmPath) if header: repo = FakeRepository(self._installRoot, True) pkg = AinstRpmPackage(header, repo, aicfInfo) sack.addPackageObject(pkg) return sack
def convert(self, rpmFilePath): if not file_util.isFile(rpmFilePath): Log.cout(Log.ERROR, 'Rpm file [%s] not existed' % rpmFilePath) return None rpmHeader = rpmutils.readRpmHeader(rpmFilePath) if rpmHeader is None: Log.cout(Log.ERROR, 'Read rpm header failed: [%s]' % rpmFilePath) return None rpmHeaderReader = RpmHeaderReader(rpmHeader) fileList = rpmHeaderReader.getFiles() rpmFileInfoList = [] if len(fileList) == 0: Log.cout(Log.INFO, 'Rpm filelist has no file') return rpmFileInfoList firstPath = rpmHeaderReader.getDirNameByIndex(fileList[0][2]) + fileList[0][1] if stat.S_ISDIR(fileList[0][3]): firstPath += '/' for fileObj in fileList: dirName = rpmHeaderReader.getDirNameByIndex(fileObj[2]) path = dirName + fileObj[1] isDir = stat.S_ISDIR(fileObj[3]) if isDir: path = path + '/' if not path.startswith('/'): Log.cout(Log.ERROR, 'Rpm file has illegal prefix: %s' % path) return None path = path[len('/'):] if (path == '' or path.startswith('ainst/') or path.startswith('usr/ainst/') or path.startswith('usr/local/ainst/')): continue rpmFileInfo = RpmFileInfo(fileObj[1], isDir, path, fileObj[0]) rpmFileInfoList.append(rpmFileInfo) return rpmFileInfoList
if index > dirListLength: Log.cout(Log.ERROR, 'Get dir name failed') return None return self._getDirs()[index] def _getDirs(self): if self._dirList is None: self._dirList = self._header[rpm.RPMTAG_DIRNAMES] return self._dirList if __name__ == '__main__': import rpmutils ts = rpm.TransactionSet() path = '/home/xiaoming.zhang/aicf/aggregator/build/release64/rpm_build/RPMS/x86_64/aggregator-3.9.1-rc_1.x86_64.rpm' path = '/home/xiaoming.zhang/xx/var/ainst/tmp/amonitor-0.1.3-rc_2.x86_64.rpm' header = rpmutils.readRpmHeader(ts, path) reader = RpmHeaderReader(header) print reader.getInfoByName('name') print reader.getInfoByName('version') print reader.getInfoByName('release') print reader.getInfoByName('summary') print reader.getInfoByName('description') print reader.getInfoByName('buildtime') print reader.getInfoByName('buildhost') print reader.getInfoByName('size') print reader.getInfoByName('license') print reader.getInfoByName('group') print reader.getInfoByName('os') print reader.getInfoByName('arch') print reader.getInfoByName('sourcerpm') print reader.getInfoByName('fileverifyflags')