示例#1
0
 def parseSpecFile(self, specfile):
     self._createDefaultPackage()
     currentPkg = "default"
     with open(specfile) as specFile:
         lines = specFile.readlines()
         totalLines = len(lines)
         i = 0
         while i < totalLines:
             line = lines[i].strip()
             if self._isConditionalArch(line):
                 if platform.machine() != self._readConditionalArch(line):
                     # skip conditional body
                     deep = 1
                     while i < totalLines and deep != 0:
                         i = i + 1
                         line = lines[i].strip()
                         if self._isConditionalMacroStart(line):
                             deep = deep + 1
                         elif self._isConditionalMacroEnd(line):
                             deep = deep - 1
             elif self._isIfCondition(line):
                 if not self._isConditionTrue(line):
                     # skip conditional body
                     deep = 1
                     while i < totalLines and deep != 0:
                         i = i + 1
                         line = lines[i].strip()
                         if self._isConditionalMacroStart(line):
                             deep = deep + 1
                         elif self._isConditionalMacroEnd(line):
                             deep = deep - 1
             elif self._isSpecMacro(line):
                 macro, i = self._readMacroFromFile(i, lines)
                 self._updateSpecMacro(macro)
             elif self._isPackageMacro(line):
                 defaultpkg = self.packages.get('default')
                 returnVal, packageName = self._readPkgNameFromPackageMacro(
                     line, defaultpkg.name)
                 packageName = self._replaceMacros(packageName)
                 if not returnVal:
                     return False
                 if line.startswith('%package'):
                     pkg = Package(defaultpkg)
                     pkg.name = packageName
                     currentPkg = packageName
                     self.packages[pkg.name] = pkg
                 else:
                     if defaultpkg.name == packageName:
                         packageName = 'default'
                     macro, i = self._readMacroFromFile(i, lines)
                     if packageName not in self.packages:
                         i = i + 1
                         continue
                     self.packages[packageName].updatePackageMacro(macro)
             elif self._isPackageHeaders(line):
                 self._readPackageHeaders(line, self.packages[currentPkg])
             elif self._isGlobalSecurityHardening(line):
                 self._readSecurityHardening(line)
             elif self._isChecksum(line):
                 self._readChecksum(line, self.packages[currentPkg])
             elif self._isExtraBuildRequires(line):
                 self._readExtraBuildRequires(line,
                                              self.packages[currentPkg])
             elif self._isDefinition(line):
                 self._readDefinition(line)
             elif self._isConditionalCheckMacro(line):
                 self.conditionalCheckMacroEnabled = True
             elif self.conditionalCheckMacroEnabled and self._isConditionalMacroEnd(
                     line):
                 self.conditionalCheckMacroEnabled = False
             else:
                 self.specAdditionalContent += line + "\n"
             i = i + 1
示例#2
0
 def _createDefaultPackage(self):
     self.packages["default"] = Package()