It includes:
- merge package-builder's and SpecDeps's spec parser to avoid code
duplication
- spec parser: support for Requires(post|pre|postun|preun)
- spec parser: support for conditional requires, such as
"Requires: (aaa <= 3.1 or bbb) ccc (ddd or fff > 4.5.6)"
- add "file to owner package" mapping. "/sbin/useradd -> shadow" to
install proper build requires
- create SPECS singleton to store parsed spec data
- use constants.py only to store constants
Change-Id: I9fbb9ccdb9fdfef932d4097983e02eb41bb73987
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/3819
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Vinay Kulkarni <kulkarniv@vmware.com>
Reviewed-by: Xiaolin Li <xiaolinl@vmware.com>
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,14 +0,0 @@ |
1 |
-import commands |
|
2 |
- |
|
3 |
-class RepoQueryDependency(object): |
|
4 |
- def __init__(self, repoFile): |
|
5 |
- self.repo_file = repoFile |
|
6 |
- def getRequiresList(self,pkg): |
|
7 |
- cmd = "repoquery -c "+self.repo_file+" -R -q "+pkg+" | xargs repoquery -c "+self.repo_file+" --whatprovides -q | sed 's/-[0-9]/ /g' | cut -f 1 -d ' ' | sort | uniq " |
|
8 |
- status,output = commands.getstatusoutput(cmd) |
|
9 |
- if status == 0: |
|
10 |
- outList = output.split('\n') |
|
11 |
- if "" in outList: outList.remove("") |
|
12 |
- if "Options:" in outList: outList.remove("Options:") |
|
13 |
- if "Usage:" in outList: outList.remove("Usage:") |
|
14 |
- return outList |
15 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,280 +0,0 @@ |
1 |
-from SpecUtils import Specutils |
|
2 |
-from StringUtils import StringUtils |
|
3 |
-import operator |
|
4 |
-import os |
|
5 |
-import collections |
|
6 |
-import Queue |
|
7 |
-import json |
|
8 |
- |
|
9 |
-class SerializableSpecObject(object): |
|
10 |
- def __init__(self): |
|
11 |
- self.listPackages=[] |
|
12 |
- self.name="" |
|
13 |
- self.version="" |
|
14 |
- self.release="" |
|
15 |
- self.buildRequirePackages=[] |
|
16 |
- self.installRequiresAllPackages=[] |
|
17 |
- self.installRequiresPackages={} |
|
18 |
- self.specFile="" |
|
19 |
- self.listSources=[] |
|
20 |
- self.listPatches=[] |
|
21 |
- self.securityHardening="" |
|
22 |
- |
|
23 |
-class SerializedSpecObjects(object): |
|
24 |
- |
|
25 |
- def __init__(self, inputDataDir, stageDir): |
|
26 |
- self.mapSerializableSpecObjects={} |
|
27 |
- self.mapPackageToSpec={} |
|
28 |
- self.jsonFilesOutPath = stageDir + "/common/data/" |
|
29 |
- self.inputDataDir = inputDataDir |
|
30 |
- |
|
31 |
- def findTotalRequires(self, allDeps, depQue, parent, displayOption): |
|
32 |
- while not depQue.empty(): |
|
33 |
- specPkg = depQue.get() |
|
34 |
- specName = self.getSpecName(specPkg) |
|
35 |
- if specName is None: |
|
36 |
- print specPkg + " is missing" |
|
37 |
- specObj = self.mapSerializableSpecObjects[specName] |
|
38 |
- for depPkg in specObj.installRequiresPackages[specPkg]: |
|
39 |
- if True == allDeps.has_key(depPkg): |
|
40 |
- if(allDeps[depPkg] < allDeps[specPkg] + 1): |
|
41 |
- allDeps[depPkg] = allDeps[specPkg] + 1 |
|
42 |
- parent[depPkg] = specPkg |
|
43 |
- self.updateLevels(allDeps, depPkg, parent, allDeps[depPkg]) |
|
44 |
- else: |
|
45 |
- allDeps[depPkg] = allDeps[specPkg] + 1 |
|
46 |
- parent[depPkg] = specPkg |
|
47 |
- depQue.put(depPkg) |
|
48 |
- |
|
49 |
- def findTotalWhoNeedsToBuild(self, depQue, whoBuildDeps, whoBuildDepSet, displayOption): |
|
50 |
- while not depQue.empty(): |
|
51 |
- specPkg = depQue.get() |
|
52 |
- specName = self.getSpecName(specPkg) |
|
53 |
- spec=Specutils(self.getSpecFile(specPkg)) |
|
54 |
- RPMName=spec.getRPMName(specPkg) |
|
55 |
- debuginfoRPMName=spec.getDebuginfoRPMName(specPkg) |
|
56 |
- whoBuildDepSet.add(RPMName) |
|
57 |
- whoBuildDepSet.add(debuginfoRPMName) |
|
58 |
- if specName is None: |
|
59 |
- print specPkg + " is missing" |
|
60 |
- if not whoBuildDeps.has_key(specPkg): |
|
61 |
- continue |
|
62 |
- for depPkg in whoBuildDeps[specPkg]: |
|
63 |
- depQue.put(depPkg) |
|
64 |
- |
|
65 |
- def printTree(self, allDeps, children, curParent , depth): |
|
66 |
- if (children.has_key(curParent)): |
|
67 |
- for child in children[curParent]: |
|
68 |
- print "\t" * depth, child |
|
69 |
- self.printTree(allDeps, children, child, depth+1) |
|
70 |
- |
|
71 |
- def get_all_package_names(self, jsonFilePath): |
|
72 |
- base_path = os.path.dirname(jsonFilePath) |
|
73 |
- jsonData = open(jsonFilePath) |
|
74 |
- option_list_json = json.load(jsonData) |
|
75 |
- jsonData.close() |
|
76 |
- packages = option_list_json["packages"] |
|
77 |
- return packages |
|
78 |
- |
|
79 |
- def updateLevels(self, allDeps, inPkg, parent, level): |
|
80 |
- specName = self.getSpecName(inPkg) |
|
81 |
- specObj = self.mapSerializableSpecObjects[specName] |
|
82 |
- for depPkg in specObj.installRequiresPackages[inPkg]: |
|
83 |
- if (allDeps.has_key(depPkg) and allDeps[depPkg] < level + 1): |
|
84 |
- allDeps[depPkg] = level + 1 |
|
85 |
- parent[depPkg] = inPkg |
|
86 |
- self.updateLevels(allDeps, depPkg, parent, allDeps[depPkg]) |
|
87 |
- |
|
88 |
- def readSpecsAndConvertToSerializableObjects(self, specFilesPath, inputType, inputValue, displayOption): |
|
89 |
- children = {} |
|
90 |
- listSpecFiles=[] |
|
91 |
- whoNeedsList=[] |
|
92 |
- whoBuildDepSet= set() |
|
93 |
- independentRPMS=[] # list of all RPMS not built from photon and that must be blindly copied. |
|
94 |
- whoBuildDeps = {} |
|
95 |
- allDeps={} |
|
96 |
- parent={} |
|
97 |
- depQue = Queue.Queue() |
|
98 |
- packageFound = False |
|
99 |
- self.getListSpecFiles(listSpecFiles,specFilesPath) |
|
100 |
- for specFile in listSpecFiles: |
|
101 |
- spec=Specutils(specFile) |
|
102 |
- specName=spec.getBasePackageName() |
|
103 |
- specObj=SerializableSpecObject() |
|
104 |
- specObj.name=specName |
|
105 |
- specObj.buildRequirePackages=spec.getBuildRequiresAllPackages() |
|
106 |
- specObj.installRequiresAllPackages=spec.getRequiresAllPackages() |
|
107 |
- specObj.listPackages=spec.getPackageNames() |
|
108 |
- specObj.specFile=specFile |
|
109 |
- specObj.version=spec.getVersion() |
|
110 |
- specObj.release=spec.getRelease() |
|
111 |
- specObj.listSources=spec.getSourceNames() |
|
112 |
- specObj.listPatches=spec.getPatchNames() |
|
113 |
- specObj.securityHardening=spec.getSecurityHardeningOption() |
|
114 |
- for specPkg in specObj.listPackages: |
|
115 |
- specObj.installRequiresPackages[specPkg]=spec.getRequires(specPkg) |
|
116 |
- if (inputType == "pkg" and inputValue == specPkg): # all the first level dependencies to a dictionary and queue |
|
117 |
- packageFound = True |
|
118 |
- for depPkg in specObj.installRequiresPackages[specPkg]: |
|
119 |
- if False == allDeps.has_key(depPkg): |
|
120 |
- allDeps[depPkg] = 0 |
|
121 |
- parent[depPkg] = "" |
|
122 |
- depQue.put(depPkg) |
|
123 |
- elif (inputType == "who-needs" and (inputValue in specObj.installRequiresPackages[specPkg])): |
|
124 |
- whoNeedsList.append(specPkg) |
|
125 |
- elif (inputType == "who-needs-build"): |
|
126 |
- for bdrq in specObj.buildRequirePackages: |
|
127 |
- if (whoBuildDeps.has_key(bdrq)): |
|
128 |
- whoBuildDeps[bdrq].add(specPkg) |
|
129 |
- else: |
|
130 |
- whoBuildDeps[bdrq] = set() |
|
131 |
- whoBuildDeps[bdrq].add(specPkg) |
|
132 |
- if(inputValue == specPkg): |
|
133 |
- packageFound = True |
|
134 |
- for depPkg in specObj.listPackages: |
|
135 |
- depQue.put(depPkg) |
|
136 |
- |
|
137 |
- self.mapPackageToSpec[specPkg]=specName |
|
138 |
- self.mapSerializableSpecObjects[specName]=specObj |
|
139 |
- |
|
140 |
- # Generate dependencies for individual packages |
|
141 |
- if (inputType == "pkg"): |
|
142 |
- if (packageFound == True): |
|
143 |
- self.findTotalRequires(allDeps, depQue, parent, displayOption) |
|
144 |
- else: |
|
145 |
- print "No spec file builds a package named",inputValue |
|
146 |
- return |
|
147 |
- |
|
148 |
- # Generate dependencies for all packages in the given JSON input file |
|
149 |
- elif (inputType == "json"): |
|
150 |
- filePath = self.inputDataDir +"/"+ inputValue |
|
151 |
- data = self.get_all_package_names(filePath) |
|
152 |
- for pkg in data: |
|
153 |
- if False == allDeps.has_key(pkg): |
|
154 |
- spName = self.getSpecName(pkg) |
|
155 |
- if(spName != None): |
|
156 |
- allDeps[pkg] = 0 |
|
157 |
- parent[pkg] = "" |
|
158 |
- depQue.put(pkg) |
|
159 |
- self.findTotalRequires(allDeps, depQue, parent, displayOption) |
|
160 |
- else: |
|
161 |
- independentRPMS.append(pkg); |
|
162 |
- |
|
163 |
- #Generating the list of packages that requires the given input package at install time |
|
164 |
- elif (inputType == "who-needs"): |
|
165 |
- print whoNeedsList |
|
166 |
- return |
|
167 |
- |
|
168 |
- #Generating the list of packages that the modified package will affect at build time |
|
169 |
- elif (inputType == "who-needs-build"): |
|
170 |
- if (packageFound == True): |
|
171 |
- self.findTotalWhoNeedsToBuild(depQue, whoBuildDeps, whoBuildDepSet, displayOption) |
|
172 |
- print whoBuildDepSet |
|
173 |
- else: |
|
174 |
- print "No spec file builds a package named", inputValue |
|
175 |
- return |
|
176 |
- |
|
177 |
- # construct the sorted list of all packages (sorted by dependency) |
|
178 |
- sortedList = [] |
|
179 |
- for elem in sorted(allDeps.items(), key=operator.itemgetter(1), reverse=True): |
|
180 |
- sortedList.append(elem[0]) |
|
181 |
- sortedList.extend(independentRPMS) |
|
182 |
- |
|
183 |
- # construct all children nodes |
|
184 |
- if (displayOption == "tree"): |
|
185 |
- for k, v in parent.iteritems(): |
|
186 |
- children.setdefault(v, []).append(k) |
|
187 |
- if(inputType == "json"): |
|
188 |
- print "Dependency Mappings for", inputValue, ":", "\n----------------------------------------------------",children |
|
189 |
- print "----------------------------------------------------" |
|
190 |
- if (children.has_key("")): |
|
191 |
- for child in children[""]: |
|
192 |
- print child |
|
193 |
- self.printTree(allDeps, children, child, 1) |
|
194 |
- for pkg in independentRPMS: |
|
195 |
- print pkg |
|
196 |
- print "******************",len(sortedList), "packages in total ******************" |
|
197 |
- else: |
|
198 |
- if (inputType == "pkg" and len(children) > 0): |
|
199 |
- print "cyclic dependency detected, mappings: \n",children |
|
200 |
- |
|
201 |
- # To display a flat list of all packages |
|
202 |
- elif(displayOption == "list"): |
|
203 |
- print sortedList |
|
204 |
- |
|
205 |
- # To generate a new JSON file based on given input json file |
|
206 |
- elif(displayOption == "json" and inputType == "json"): |
|
207 |
- d = {} |
|
208 |
- d['packages'] = sortedList |
|
209 |
- outFilePath = self.jsonFilesOutPath + inputValue |
|
210 |
- with open(outFilePath, 'wb') as outfile: |
|
211 |
- json.dump(d, outfile) |
|
212 |
- return sortedList |
|
213 |
- |
|
214 |
- def getListSpecFiles(self,listSpecFiles,path): |
|
215 |
- for dirEntry in os.listdir(path): |
|
216 |
- dirEntryPath = os.path.join(path, dirEntry) |
|
217 |
- if os.path.isfile(dirEntryPath) and dirEntryPath.endswith(".spec"): |
|
218 |
- listSpecFiles.append(dirEntryPath) |
|
219 |
- elif os.path.isdir(dirEntryPath): |
|
220 |
- self.getListSpecFiles(listSpecFiles,dirEntryPath) |
|
221 |
- |
|
222 |
- def getBuildRequiresForPackage(self, package): |
|
223 |
- specName=self.getSpecName(package) |
|
224 |
- return self.mapSerializableSpecObjects[specName].buildRequirePackages |
|
225 |
- |
|
226 |
- def getRequiresForPackage(self, package): |
|
227 |
- specName=self.getSpecName(package) |
|
228 |
- if self.mapSerializableSpecObjects[specName].installRequiresPackages.has_key(package): |
|
229 |
- return self.mapSerializableSpecObjects[specName].installRequiresPackages[package] |
|
230 |
- return None |
|
231 |
- |
|
232 |
- def getRelease(self, package): |
|
233 |
- specName=self.getSpecName(package) |
|
234 |
- return self.mapSerializableSpecObjects[specName].release |
|
235 |
- |
|
236 |
- def getVersion(self, package): |
|
237 |
- specName=self.getSpecName(package) |
|
238 |
- return self.mapSerializableSpecObjects[specName].version |
|
239 |
- |
|
240 |
- def getSpecFile(self, package): |
|
241 |
- specName=self.getSpecName(package) |
|
242 |
- return self.mapSerializableSpecObjects[specName].specFile |
|
243 |
- |
|
244 |
- def getPatches(self, package): |
|
245 |
- specName=self.getSpecName(package) |
|
246 |
- return self.mapSerializableSpecObjects[specName].listPatches |
|
247 |
- |
|
248 |
- def getSources(self, package): |
|
249 |
- specName=self.getSpecName(package) |
|
250 |
- return self.mapSerializableSpecObjects[specName].listSources |
|
251 |
- |
|
252 |
- def getPackages(self, package): |
|
253 |
- specName=self.getSpecName(package) |
|
254 |
- return self.mapSerializableSpecObjects[specName].listPackages |
|
255 |
- |
|
256 |
- def getSpecName(self,package): |
|
257 |
- if self.mapPackageToSpec.has_key(package): |
|
258 |
- specName=self.mapPackageToSpec[package] |
|
259 |
- if self.mapSerializableSpecObjects.has_key(specName): |
|
260 |
- return specName |
|
261 |
- else: |
|
262 |
- print "SpecDeps: Could not able to find " + package + " package from specs" |
|
263 |
- raise Exception("Invalid package:" + package) |
|
264 |
- else: |
|
265 |
- return None |
|
266 |
- |
|
267 |
- def isRPMPackage(self,package): |
|
268 |
- if self.mapPackageToSpec.has_key(package): |
|
269 |
- specName=self.mapPackageToSpec[package] |
|
270 |
- if self.mapSerializableSpecObjects.has_key(specName): |
|
271 |
- return True |
|
272 |
- return False |
|
273 |
- |
|
274 |
- def getSecurityHardeningOption(self, package): |
|
275 |
- specName=self.getSpecName(package) |
|
276 |
- return self.mapSerializableSpecObjects[specName].securityHardening |
|
277 |
- |
|
278 |
- def getSpecDetails(self, name): |
|
279 |
- print self.mapSerializableSpecObjects[name].installRequiresAllPackages |
|
280 |
- |
281 | 1 |
deleted file mode 100755 |
... | ... |
@@ -1,57 +0,0 @@ |
1 |
-#! /usr/bin/python2 |
|
2 |
-# |
|
3 |
-# Copyright (C) 2015 vmware inc. |
|
4 |
-# |
|
5 |
-# Author: Harish Udaiya Kumar <hudaiyakumar@vmware.com> |
|
6 |
-from SpecUtils import Specutils |
|
7 |
-from SpecData import SerializableSpecObject |
|
8 |
-from SpecData import SerializedSpecObjects |
|
9 |
-import sys |
|
10 |
-import os |
|
11 |
-from optparse import OptionParser |
|
12 |
-from jsonwrapper import JsonWrapper |
|
13 |
- |
|
14 |
-DEFAULT_INPUT_TYPE = "pkg" |
|
15 |
-DEFAULT_DISPLAY_OPTION = "tree" |
|
16 |
-SPEC_FILE_DIR = "../../SPECS" |
|
17 |
-LOG_FILE_DIR = "../../stage/LOGS" |
|
18 |
- |
|
19 |
- |
|
20 |
-def main(): |
|
21 |
- usage = os.path.basename(__file__) + "--input-type=[json/pkg/who-needs/who-needs-build] --pkg=[pkg_name] --file=<JSON_FILE_NAME> --disp=[tree/list/json]" |
|
22 |
- parser = OptionParser(usage) |
|
23 |
- parser.add_option("-i", "--input-type", dest="input_type", default=DEFAULT_INPUT_TYPE) |
|
24 |
- parser.add_option("-p", "--pkg", dest="pkg") |
|
25 |
- parser.add_option("-f", "--file", dest="json_file", default="packages_minimal.json") |
|
26 |
- parser.add_option("-d", "--disp", dest="display_option", default=DEFAULT_DISPLAY_OPTION) |
|
27 |
- parser.add_option("-s", "--spec-dir", dest="spec_dir", default=SPEC_FILE_DIR) |
|
28 |
- parser.add_option("-t", "--stage-dir", dest="stage_dir", default="../../stage") |
|
29 |
- parser.add_option("-a", "--input-data-dir", dest="input_data_dir", default="../../common/data/") |
|
30 |
- (options, args) = parser.parse_args() |
|
31 |
- |
|
32 |
- if(False == options.input_data_dir.endswith('/')): |
|
33 |
- options.input_data_dir += '/' |
|
34 |
- |
|
35 |
- specDeps = SerializedSpecObjects(options.input_data_dir, options.stage_dir) |
|
36 |
- displayOption = options.display_option |
|
37 |
- abs_path = os.path.abspath(__file__) |
|
38 |
- dir_name = os.path.dirname(abs_path) |
|
39 |
- os.chdir(dir_name) |
|
40 |
- |
|
41 |
- # To display/print package dependencies on console |
|
42 |
- if(options.input_type == "pkg" or options.input_type == "who-needs" or options.input_type == "who-needs-build"): |
|
43 |
- targetName = options.pkg |
|
44 |
- specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, targetName, displayOption) |
|
45 |
- elif(options.input_type == "json"):# Generate the expanded package dependencies json file based on package_list_file |
|
46 |
- json_wrapper_option_list = JsonWrapper(options.json_file) |
|
47 |
- option_list_json = json_wrapper_option_list.read() |
|
48 |
- options_sorted = option_list_json.items() |
|
49 |
- for install_option in options_sorted: |
|
50 |
- if displayOption == "tree" and install_option[1]["title"] == "ISO Packages": |
|
51 |
- continue |
|
52 |
- specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, install_option[1]["file"], displayOption) |
|
53 |
- |
|
54 |
- sys.exit(0) |
|
55 |
- |
|
56 |
-if __name__=="__main__": |
|
57 |
- main() |
58 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,322 +0,0 @@ |
1 |
-import re |
|
2 |
-from StringUtils import StringUtils |
|
3 |
-from SpecStructures import * |
|
4 |
- |
|
5 |
-class SpecParser(object): |
|
6 |
- def __init__(self): |
|
7 |
- self.cleanMacro=rpmMacro().setName("clean") |
|
8 |
- self.prepMacro=rpmMacro().setName("prep") |
|
9 |
- self.buildMacro=rpmMacro().setName("build") |
|
10 |
- self.installMacro=rpmMacro().setName("install") |
|
11 |
- self.changelogMacro=rpmMacro().setName("changelog") |
|
12 |
- self.checkMacro=rpmMacro().setName("check") |
|
13 |
- self.packages={} |
|
14 |
- self.specAdditionalContent="" |
|
15 |
- self.globalSecurityHardening="" |
|
16 |
- |
|
17 |
- |
|
18 |
- def readPkgNameFromPackageMacro(self,data,basePkgName=None): |
|
19 |
- data=" ".join(data.split()) |
|
20 |
- pkgHeaderName=data.split(" ") |
|
21 |
- lenpkgHeaderName = len(pkgHeaderName) |
|
22 |
- |
|
23 |
- if (lenpkgHeaderName >= 3 and pkgHeaderName[1] != "-n"): |
|
24 |
- lenpkgHeaderName = 1 |
|
25 |
- if (lenpkgHeaderName == 2 or lenpkgHeaderName == 1 ) and basePkgName is None : |
|
26 |
- print "Invalid basePkgName" |
|
27 |
- return False,None |
|
28 |
- if lenpkgHeaderName == 3 : |
|
29 |
- return True,pkgHeaderName[2] |
|
30 |
- if lenpkgHeaderName == 2 : |
|
31 |
- return True,basePkgName + "-"+pkgHeaderName[1] |
|
32 |
- if lenpkgHeaderName == 1: |
|
33 |
- return True, basePkgName |
|
34 |
- |
|
35 |
- def parseSpecFile(self,specfile): |
|
36 |
- self.createDefaultPackage() |
|
37 |
- currentPkg="default" |
|
38 |
- specFile = open(specfile) |
|
39 |
- lines = specFile.readlines() |
|
40 |
- totalLines=len(lines) |
|
41 |
- i=0 |
|
42 |
- while i < totalLines: |
|
43 |
- line = lines[i].strip() |
|
44 |
- if self.isSpecMacro(line): |
|
45 |
- macro,i=self.readMacroFromFile(i, lines) |
|
46 |
- self.updateMacro(macro) |
|
47 |
- elif self.isPackageMacro(line): |
|
48 |
- defaultpkg = self.packages.get('default') |
|
49 |
- returnVal,packageName=self.readPkgNameFromPackageMacro(line, defaultpkg.name) |
|
50 |
- packageName=defaultpkg.decodeContents(packageName) |
|
51 |
- if not returnVal: |
|
52 |
- return False |
|
53 |
- if re.search('^'+'%package',line) : |
|
54 |
- pkg = Package(defaultpkg) |
|
55 |
- pkg.name=packageName |
|
56 |
- currentPkg=packageName |
|
57 |
- self.packages[pkg.name]=pkg |
|
58 |
- else: |
|
59 |
- if defaultpkg.name == packageName : |
|
60 |
- packageName = 'default' |
|
61 |
- if not self.packages.has_key(packageName): |
|
62 |
- return False |
|
63 |
- macro,i=self.readMacroFromFile(i, lines) |
|
64 |
- self.packages[packageName].updatePackageMacro(macro) |
|
65 |
- elif self.isPackageHeaders(line): |
|
66 |
- self.readPackageHeaders(line, self.packages[currentPkg]) |
|
67 |
- elif self.isGlobalSecurityHardening(line): |
|
68 |
- self.readSecurityHardening(line) |
|
69 |
- else: |
|
70 |
- self.specAdditionalContent+=line+"\n" |
|
71 |
- i=i+1 |
|
72 |
- specFile.close() |
|
73 |
- |
|
74 |
- def createDefaultPackage(self): |
|
75 |
- pkg = Package() |
|
76 |
- self.packages["default"]=pkg |
|
77 |
- |
|
78 |
- def readMacroFromFile(self,currentPos,lines): |
|
79 |
- macro = rpmMacro() |
|
80 |
- line = lines[currentPos] |
|
81 |
- macro.position = currentPos |
|
82 |
- macro.endposition=currentPos |
|
83 |
- endPos=len(lines) |
|
84 |
- line = " ".join(line.split()) |
|
85 |
- flagindex = line.find(" ") |
|
86 |
- if flagindex != -1: |
|
87 |
- macro.macroFlag=line[flagindex+1:] |
|
88 |
- macro.macroName=line[:flagindex] |
|
89 |
- else: |
|
90 |
- macro.macroName=line |
|
91 |
- |
|
92 |
- if currentPos+1 < len(lines) and self.isMacro(lines[currentPos+1]): |
|
93 |
- return macro,currentPos |
|
94 |
- |
|
95 |
- for j in range(currentPos+1,endPos): |
|
96 |
- content = lines[j] |
|
97 |
- if j+1 < endPos and self.isMacro(lines[j+1]): |
|
98 |
- return macro,j |
|
99 |
- macro.content += content +'\n' |
|
100 |
- macro.endposition=j |
|
101 |
- return macro,endPos |
|
102 |
- |
|
103 |
- |
|
104 |
- def updateMacro(self,macro): |
|
105 |
- if macro.macroName == "%clean": |
|
106 |
- self.cleanMacro=macro |
|
107 |
- return True |
|
108 |
- if macro.macroName == "%prep": |
|
109 |
- self.prepMacro=macro |
|
110 |
- return True |
|
111 |
- if macro.macroName == "%build": |
|
112 |
- self.buildMacro=macro |
|
113 |
- return True |
|
114 |
- if macro.macroName == "%install": |
|
115 |
- self.installMacro=macro |
|
116 |
- return True |
|
117 |
- if macro.macroName == "%changelog": |
|
118 |
- self.changelogMacro=macro |
|
119 |
- return True |
|
120 |
- if macro.macroName == "%check": |
|
121 |
- self.checkMacro=macro |
|
122 |
- return True |
|
123 |
- return False |
|
124 |
- |
|
125 |
- def isMacro(self,line): |
|
126 |
- return self.isPackageMacro(line) or self.isSpecMacro(line) |
|
127 |
- |
|
128 |
- def isSpecMacro(self,line): |
|
129 |
- if re.search('^'+'%clean',line) : |
|
130 |
- return True |
|
131 |
- elif re.search('^'+'%prep',line) : |
|
132 |
- return True |
|
133 |
- elif re.search('^'+'%build',line) : |
|
134 |
- return True |
|
135 |
- elif re.search('^'+'%install',line) : |
|
136 |
- return True |
|
137 |
- elif re.search('^'+'%changelog',line) : |
|
138 |
- return True |
|
139 |
- elif re.search('^'+'%check',line) : |
|
140 |
- return True |
|
141 |
- return False |
|
142 |
- |
|
143 |
- def isPackageMacro(self,line): |
|
144 |
- line=line.strip() |
|
145 |
-# What is the point of this function? |
|
146 |
-# Why does it track post/postun sections? |
|
147 |
-# if re.search('^'+'%post',line) : |
|
148 |
-# return True |
|
149 |
-# elif re.search('^'+'%postun',line) : |
|
150 |
-# return True |
|
151 |
- if re.search('^'+'%files',line) : |
|
152 |
- return True |
|
153 |
- elif re.search('^'+'%description',line) : |
|
154 |
- return True |
|
155 |
- elif re.search('^'+'%package',line) : |
|
156 |
- return True |
|
157 |
- return False |
|
158 |
- |
|
159 |
- def isPackageHeaders(self,line): |
|
160 |
- if re.search('^'+'summary:',line,flags=re.IGNORECASE) : |
|
161 |
- return True |
|
162 |
- elif re.search('^'+'name:',line,flags=re.IGNORECASE) : |
|
163 |
- return True |
|
164 |
- elif re.search('^'+'group:',line,flags=re.IGNORECASE) : |
|
165 |
- return True |
|
166 |
- elif re.search('^'+'license:',line,flags=re.IGNORECASE) : |
|
167 |
- return True |
|
168 |
- elif re.search('^'+'version:',line,flags=re.IGNORECASE) : |
|
169 |
- return True |
|
170 |
- elif re.search('^'+'release:',line,flags=re.IGNORECASE) : |
|
171 |
- return True |
|
172 |
- elif re.search('^'+'distribution:',line,flags=re.IGNORECASE) : |
|
173 |
- return True |
|
174 |
- elif re.search('^'+'requires:',line,flags=re.IGNORECASE) : |
|
175 |
- return True |
|
176 |
- elif re.search('^'+'provides:',line,flags=re.IGNORECASE) : |
|
177 |
- return True |
|
178 |
- elif re.search('^'+'obsoletes:',line,flags=re.IGNORECASE) : |
|
179 |
- return True |
|
180 |
- elif re.search('^'+'conflicts:',line,flags=re.IGNORECASE) : |
|
181 |
- return True |
|
182 |
- elif re.search('^'+'url:',line,flags=re.IGNORECASE) : |
|
183 |
- return True |
|
184 |
- elif re.search('^'+'source[0-9]*:',line,flags=re.IGNORECASE) : |
|
185 |
- return True |
|
186 |
- elif re.search('^'+'patch[0-9]*:',line,flags=re.IGNORECASE) : |
|
187 |
- return True |
|
188 |
- elif re.search('^'+'buildrequires:',line,flags=re.IGNORECASE) : |
|
189 |
- return True |
|
190 |
- elif re.search('^'+'buildprovides:',line,flags=re.IGNORECASE) : |
|
191 |
- return True |
|
192 |
- elif re.search('^'+'buildarch:',line,flags=re.IGNORECASE) : |
|
193 |
- return True |
|
194 |
- return False |
|
195 |
- |
|
196 |
- def isGlobalSecurityHardening(self,line): |
|
197 |
- if re.search('^%global *security_hardening',line,flags=re.IGNORECASE) : |
|
198 |
- return True |
|
199 |
- return False |
|
200 |
- |
|
201 |
- def readHeader(self,line): |
|
202 |
- headerSplitIndex=line.find(":") |
|
203 |
- if(headerSplitIndex+1 == len(line) ): |
|
204 |
- print line |
|
205 |
- print "Error:Invalid header" |
|
206 |
- return False, None,None |
|
207 |
- headerName=line[0:headerSplitIndex].lower() |
|
208 |
- headerContent=line[headerSplitIndex+1:].strip() |
|
209 |
- return True,headerName,headerContent |
|
210 |
- |
|
211 |
- |
|
212 |
- def readDependentPackageData(self,line): |
|
213 |
- strUtils = StringUtils() |
|
214 |
- listPackages=line.split(",") |
|
215 |
- listdependentpkgs=[] |
|
216 |
- for line in listPackages: |
|
217 |
- line=strUtils.getStringInBrackets(line) |
|
218 |
- listContents=line.split() |
|
219 |
- totalContents = len(listContents) |
|
220 |
- i=0 |
|
221 |
- while i < totalContents: |
|
222 |
- dpkg = dependentPackageData() |
|
223 |
- compare=None |
|
224 |
- if listContents[i].startswith("/"): |
|
225 |
- i=i+1 |
|
226 |
- continue |
|
227 |
- if i+2 < len(listContents): |
|
228 |
- if listContents[i+1] == ">=": |
|
229 |
- compare="gte" |
|
230 |
- elif listContents[i+1] == "<=": |
|
231 |
- compare="lte" |
|
232 |
- elif listContents[i+1] == "==": |
|
233 |
- compare="eq" |
|
234 |
- elif listContents[i+1] == "<": |
|
235 |
- compare="lt" |
|
236 |
- elif listContents[i+1] == ">": |
|
237 |
- compare="gt" |
|
238 |
- elif listContents[i+1] == "=": |
|
239 |
- compare="eq" |
|
240 |
- |
|
241 |
- if compare is not None: |
|
242 |
- dpkg.package=listContents[i] |
|
243 |
- dpkg.compare=compare |
|
244 |
- dpkg.version=listContents[i+2] |
|
245 |
- i=i+3 |
|
246 |
- else: |
|
247 |
- dpkg.package=listContents[i] |
|
248 |
- i=i+1 |
|
249 |
- listdependentpkgs.append(dpkg) |
|
250 |
- return listdependentpkgs |
|
251 |
- |
|
252 |
- def readPackageHeaders(self,line,pkg): |
|
253 |
- returnVal,headerName,headerContent=self.readHeader(line) |
|
254 |
- if not returnVal: |
|
255 |
- return False |
|
256 |
- |
|
257 |
- headerContent=pkg.decodeContents(headerContent) |
|
258 |
- if headerName == 'summary': |
|
259 |
- pkg.summary=headerContent |
|
260 |
- return True |
|
261 |
- if headerName == 'name': |
|
262 |
- pkg.name=headerContent |
|
263 |
- return True |
|
264 |
- if headerName == 'group': |
|
265 |
- pkg.group=headerContent |
|
266 |
- return True |
|
267 |
- if headerName == 'license': |
|
268 |
- pkg.license=headerContent |
|
269 |
- return True |
|
270 |
- if headerName == 'version': |
|
271 |
- pkg.version=headerContent |
|
272 |
- return True |
|
273 |
- if headerName == 'buildarch': |
|
274 |
- pkg.buildarch=headerContent |
|
275 |
- return True |
|
276 |
- if headerName == 'release': |
|
277 |
- pkg.release=headerContent |
|
278 |
- return True |
|
279 |
- if headerName == 'distribution': |
|
280 |
- pkg.distribution=headerContent |
|
281 |
- return True |
|
282 |
- if headerName == 'url': |
|
283 |
- pkg.URL=headerContent |
|
284 |
- return True |
|
285 |
- if headerName.find('source') != -1: |
|
286 |
- pkg.sources.append(headerContent) |
|
287 |
- return True |
|
288 |
- if headerName.find('patch') != -1: |
|
289 |
- pkg.patches.append(headerContent) |
|
290 |
- return True |
|
291 |
- if headerName == 'requires' or headerName == 'provides' or headerName == 'obsoletes' or headerName == 'conflicts' or headerName == 'buildrequires' or headerName == 'buildprovides': |
|
292 |
- dpkg=self.readDependentPackageData(headerContent) |
|
293 |
- if dpkg is None: |
|
294 |
- return False |
|
295 |
- if headerName == 'requires': |
|
296 |
- pkg.requires.extend(dpkg) |
|
297 |
- if headerName == 'provides': |
|
298 |
- pkg.provides.extend(dpkg) |
|
299 |
- if headerName == 'obsoletes': |
|
300 |
- pkg.obsoletes.extend(dpkg) |
|
301 |
- if headerName == 'conflicts': |
|
302 |
- pkg.conflicts.extend(dpkg) |
|
303 |
- if headerName == 'buildrequires': |
|
304 |
- pkg.buildrequires.extend(dpkg) |
|
305 |
- if headerName == 'buildprovides': |
|
306 |
- pkg.buildprovides.extend(dpkg) |
|
307 |
- |
|
308 |
- return True |
|
309 |
- return False |
|
310 |
- |
|
311 |
- def readSecurityHardening(self,line): |
|
312 |
- data = line.lower().strip(); |
|
313 |
- words=data.split(" ") |
|
314 |
- nrWords = len(words) |
|
315 |
- if (nrWords != 3): |
|
316 |
- print "Error: Unable to parse line: "+line |
|
317 |
- return False |
|
318 |
- if (words[2] != "none" and words[2] != "nonow") : |
|
319 |
- print "Error: Invalid security_hardening value: " + words[2] |
|
320 |
- return False |
|
321 |
- self.globalSecurityHardening = words[2] |
|
322 |
- return True; |
323 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,105 +0,0 @@ |
1 |
-class rpmMacro(object): |
|
2 |
- |
|
3 |
- def __init__(self): |
|
4 |
- self.macroName="" |
|
5 |
- self.macroFlag="" |
|
6 |
- self.content="" |
|
7 |
- self.position=-1 |
|
8 |
- self.endposition=-1 |
|
9 |
- |
|
10 |
- def setName(self,name): |
|
11 |
- self.macroName=name |
|
12 |
- |
|
13 |
- def displayMacro(self): |
|
14 |
- print "Macro:\n", self.macroName, " ",self.macroFlag," ",self.position," ",self.endposition |
|
15 |
- print self.content |
|
16 |
- |
|
17 |
-class dependentPackageData(object): |
|
18 |
- |
|
19 |
- def __init__(self): |
|
20 |
- self.package="" |
|
21 |
- self.version="" |
|
22 |
- self.compare="" |
|
23 |
- |
|
24 |
-class Package(object): |
|
25 |
- def __init__(self, basePkg=None): |
|
26 |
- self.summary="" |
|
27 |
- self.name="" |
|
28 |
- self.group="" |
|
29 |
- self.license="" |
|
30 |
- self.version="" |
|
31 |
- self.release="" |
|
32 |
- self.buildarch="x86_64" |
|
33 |
- self.distribution="" |
|
34 |
- self.basePkgName="" |
|
35 |
- |
|
36 |
- self.sources=[] |
|
37 |
- self.patches=[] |
|
38 |
- self.buildrequires=[] |
|
39 |
- self.buildprovides=[] |
|
40 |
- |
|
41 |
- |
|
42 |
- self.requires=[] |
|
43 |
- self.provides=[] |
|
44 |
- self.obsoletes=[] |
|
45 |
- self.conflicts=[] |
|
46 |
- |
|
47 |
- self.descriptionMacro= None |
|
48 |
- self.postMacro=None |
|
49 |
- self.postunMacro=None |
|
50 |
- self.filesMacro=None |
|
51 |
- self.packageMacro=None |
|
52 |
- |
|
53 |
- if basePkg is not None: |
|
54 |
- self.basePkgName=basePkg.name |
|
55 |
- self.group=basePkg.group |
|
56 |
- self.license=basePkg.license |
|
57 |
- self.version=basePkg.version |
|
58 |
- self.buildarch=basePkg.buildarch |
|
59 |
- self.release=basePkg.release |
|
60 |
- self.distribution=basePkg.distribution |
|
61 |
- |
|
62 |
- def decodeContents(self,content): |
|
63 |
- if content.find("%{name}") != -1: |
|
64 |
- if self.basePkgName == "": |
|
65 |
- content = content.replace('%{name}',self.name) |
|
66 |
- else: |
|
67 |
- content = content.replace('%{name}',self.basePkgName) |
|
68 |
- |
|
69 |
- if content.find("%{release}") != -1: |
|
70 |
- content = content.replace('%{release}',self.release) |
|
71 |
- |
|
72 |
- if content.find("%{version}") != -1: |
|
73 |
- content = content.replace('%{version}',self.version) |
|
74 |
- |
|
75 |
- if content.find("%{?dist}") != -1: |
|
76 |
- content = content.replace('%{?dist}',self.distribution) |
|
77 |
- |
|
78 |
- if content.find("%{dist}") != -1: |
|
79 |
- content = content.replace('%{dist}',self.distribution) |
|
80 |
- |
|
81 |
- # TODO: A temporary hack here. The reason is this macro |
|
82 |
- # can't be subsitute properly. |
|
83 |
- # At this file level, we won't be able to obtain any other |
|
84 |
- # packages' information. This macro requires the information |
|
85 |
- # of package linux. Besides, there is a huge diversion |
|
86 |
- # between package-builder and SpecDeps. |
|
87 |
- if content.find("%{?kernelsubrelease}") != -1: |
|
88 |
- content = content.replace('%{?kernelsubrelease}',"") |
|
89 |
- |
|
90 |
- return content |
|
91 |
- |
|
92 |
- def updatePackageMacro(self,macro): |
|
93 |
- if macro.macroName == "%post": |
|
94 |
- self.postMacro=macro |
|
95 |
- return True |
|
96 |
- if macro.macroName == "%postun": |
|
97 |
- self.postunMacro=macro |
|
98 |
- return True |
|
99 |
- if macro.macroName == "%files": |
|
100 |
- self.filesMacro=macro |
|
101 |
- return True |
|
102 |
- if macro.macroName == "%description": |
|
103 |
- self.descriptionMacro = macro |
|
104 |
- return True |
|
105 |
- return False |
106 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,243 +0,0 @@ |
1 |
-from SpecParser import SpecParser |
|
2 |
-from StringUtils import StringUtils |
|
3 |
-import os |
|
4 |
- |
|
5 |
-class Specutils(object): |
|
6 |
- |
|
7 |
- def __init__(self,specfile): |
|
8 |
- self.specfile="" |
|
9 |
- self.spec = SpecParser() |
|
10 |
- if self.isSpecFile(specfile): |
|
11 |
- self.specfile=specfile |
|
12 |
- self.spec.parseSpecFile(self.specfile) |
|
13 |
- |
|
14 |
- def isSpecFile(self,specfile): |
|
15 |
- if os.path.isfile(specfile) and specfile[-5:] == ".spec": |
|
16 |
- return True |
|
17 |
- return False |
|
18 |
- |
|
19 |
- def getSourceNames(self): |
|
20 |
- sourceNames=[] |
|
21 |
- strUtils = StringUtils() |
|
22 |
- pkg = self.spec.packages.get('default') |
|
23 |
- if pkg is None: |
|
24 |
- return None |
|
25 |
- for source in pkg.sources: |
|
26 |
- sourceName=strUtils.getFileNameFromURL(source) |
|
27 |
- sourceNames.append(sourceName) |
|
28 |
- return sourceNames |
|
29 |
- |
|
30 |
- def getSourceURLs(self): |
|
31 |
- sourceNames=[] |
|
32 |
- strUtils = StringUtils() |
|
33 |
- pkg = self.spec.packages.get('default') |
|
34 |
- if pkg is None: |
|
35 |
- return None |
|
36 |
- for source in pkg.sources: |
|
37 |
- sourceNames.append(source) |
|
38 |
- return sourceNames |
|
39 |
- |
|
40 |
- def getPatchNames(self): |
|
41 |
- patchNames=[] |
|
42 |
- strUtils = StringUtils() |
|
43 |
- pkg = self.spec.packages.get('default') |
|
44 |
- if pkg is None: |
|
45 |
- return None |
|
46 |
- for patch in pkg.patches: |
|
47 |
- patchName=strUtils.getFileNameFromURL(patch) |
|
48 |
- patchNames.append(patchName) |
|
49 |
- return patchNames |
|
50 |
- |
|
51 |
- def getPackageNames(self): |
|
52 |
- packageNames=[] |
|
53 |
- for key in self.spec.packages.keys(): |
|
54 |
- pkg = self.spec.packages.get(key) |
|
55 |
- packageNames.append(pkg.name) |
|
56 |
- return packageNames |
|
57 |
- |
|
58 |
- def getRPMNames(self): |
|
59 |
- rpmNames=[] |
|
60 |
- for key in self.spec.packages.keys(): |
|
61 |
- pkg = self.spec.packages.get(key) |
|
62 |
- rpmName=pkg.name+"-"+pkg.version+"-"+pkg.release |
|
63 |
- rpmNames.append(rpmName) |
|
64 |
- return rpmNames |
|
65 |
- |
|
66 |
- def getRPMName(self, pkgName): |
|
67 |
- rpmName=None |
|
68 |
- for key in self.spec.packages.keys(): |
|
69 |
- pkg = self.spec.packages.get(key) |
|
70 |
- if pkg.name == pkgName: |
|
71 |
- rpmName=pkg.name+"-"+pkg.version+"-"+pkg.release |
|
72 |
- break |
|
73 |
- return rpmName |
|
74 |
- |
|
75 |
- def getDebuginfoRPMName(self, pkgName): |
|
76 |
- rpmName=None |
|
77 |
- for key in self.spec.packages.keys(): |
|
78 |
- pkg = self.spec.packages.get(key) |
|
79 |
- if pkg.name == pkgName: |
|
80 |
- if pkg.basePkgName: |
|
81 |
- rpmName=pkg.basePkgName+"-debuginfo-"+pkg.version+"-"+pkg.release |
|
82 |
- break |
|
83 |
- else: |
|
84 |
- rpmName=pkg.name+"-debuginfo-"+pkg.version+"-"+pkg.release |
|
85 |
- break |
|
86 |
- return rpmName |
|
87 |
- |
|
88 |
- def getRPMVersion(self, pkgName): |
|
89 |
- version=None |
|
90 |
- for key in self.spec.packages.keys(): |
|
91 |
- pkg = self.spec.packages.get(key) |
|
92 |
- if pkg.name == pkgName: |
|
93 |
- version=pkg.version |
|
94 |
- break |
|
95 |
- return version |
|
96 |
- |
|
97 |
- def getRPMRelease(self, pkgName): |
|
98 |
- release=None |
|
99 |
- for key in self.spec.packages.keys(): |
|
100 |
- pkg = self.spec.packages.get(key) |
|
101 |
- if pkg.name == pkgName: |
|
102 |
- release=pkg.release |
|
103 |
- break |
|
104 |
- return release |
|
105 |
- |
|
106 |
- def getLicense(self, pkgName): |
|
107 |
- licenseInfo=None |
|
108 |
- for key in self.spec.packages.keys(): |
|
109 |
- pkg = self.spec.packages.get(key) |
|
110 |
- if pkg.name == pkgName: |
|
111 |
- licenseInfo=pkg.license |
|
112 |
- break |
|
113 |
- return licenseInfo |
|
114 |
- |
|
115 |
- def getURL(self, pkgName): |
|
116 |
- url=None |
|
117 |
- for key in self.spec.packages.keys(): |
|
118 |
- pkg = self.spec.packages.get(key) |
|
119 |
- if pkg.name == pkgName: |
|
120 |
- url=pkg.URL |
|
121 |
- break |
|
122 |
- return url |
|
123 |
- |
|
124 |
- def getBuildArch(self, pkgName): |
|
125 |
- buildArch="x86_64" |
|
126 |
- for key in self.spec.packages.keys(): |
|
127 |
- pkg = self.spec.packages.get(key) |
|
128 |
- if pkg.name == pkgName: |
|
129 |
- buildArch=pkg.buildarch |
|
130 |
- break |
|
131 |
- return buildArch |
|
132 |
- |
|
133 |
- def getRequiresAllPackages(self): |
|
134 |
- depedentPackages=[] |
|
135 |
- for key in self.spec.packages.keys(): |
|
136 |
- pkg = self.spec.packages.get(key) |
|
137 |
- for dpkg in pkg.requires: |
|
138 |
- depedentPackages.append(dpkg.package) |
|
139 |
- depedentPackages=list(set(depedentPackages)) |
|
140 |
- packageNames=self.getPackageNames() |
|
141 |
- for pkgName in packageNames: |
|
142 |
- if pkgName in depedentPackages: |
|
143 |
- depedentPackages.remove(pkgName) |
|
144 |
- return depedentPackages |
|
145 |
- |
|
146 |
- def getRequiresAllPackagesForGiven(self, pkgName): |
|
147 |
- dependentPackages=[] |
|
148 |
- for key in self.spec.packages.keys(): |
|
149 |
- pkg = self.spec.packages.get(key) |
|
150 |
- if pkg.name == pkgName: |
|
151 |
- for dpkg in pkg.requires: |
|
152 |
- dependentPackages.append(dpkg.package) |
|
153 |
- #if (pkgName == "mono-extras"): |
|
154 |
- # print "4given packages:", self.spec.packages |
|
155 |
- # print "4given dep packages: ", dependentPackages |
|
156 |
- return dependentPackages |
|
157 |
- |
|
158 |
- def getBuildRequiresAllPackages(self): |
|
159 |
- depedentPackages=[] |
|
160 |
- for key in self.spec.packages.keys(): |
|
161 |
- pkg = self.spec.packages.get(key) |
|
162 |
- #if(pkg.name == "mono"): |
|
163 |
- #print "build dendent packages len 4 mono-devel:", len(pkg.buildrequires) |
|
164 |
- for dpkg in pkg.buildrequires: |
|
165 |
- depedentPackages.append(dpkg.package) |
|
166 |
- depedentPackages=list(set(depedentPackages)) |
|
167 |
- packageNames=self.getPackageNames() |
|
168 |
- for pkgName in packageNames: |
|
169 |
- if pkgName in depedentPackages: |
|
170 |
- depedentPackages.remove(pkgName) |
|
171 |
- return depedentPackages |
|
172 |
- |
|
173 |
- |
|
174 |
- def getRequires(self,pkgName): |
|
175 |
- dependentPackages=[] |
|
176 |
- #if( pkgName == "mono-devel"): |
|
177 |
- #print "packages:", self.spec.packages |
|
178 |
- for key in self.spec.packages.keys(): |
|
179 |
- pkg = self.spec.packages.get(key) |
|
180 |
- if pkg.name == pkgName: |
|
181 |
- #if( pkgName == "mono-devel"): |
|
182 |
- #print "dendent packages len 4 mono-devel:", len(pkg.requires), pkg.requires[0].package |
|
183 |
- for dpkg in pkg.requires: |
|
184 |
- dependentPackages.append(dpkg.package) |
|
185 |
- return dependentPackages |
|
186 |
- |
|
187 |
- def getBuildRequires(self,pkgName): |
|
188 |
- dependentPackages=[] |
|
189 |
- for key in self.spec.packages.keys(): |
|
190 |
- pkg = self.spec.packages.get(key) |
|
191 |
- if pkg.name == pkgName: |
|
192 |
- #if( pkgName == "mono-devel"): |
|
193 |
- #print "build dendent packages len 4 mono-devel:", len(pkg.buildrequires), pkg.buildrequires[0].package |
|
194 |
- for dpkg in pkg.buildrequires: |
|
195 |
- dependentPackages.append(dpkg.package) |
|
196 |
- return dependentPackages |
|
197 |
- |
|
198 |
- def getProvides(self,packageName): |
|
199 |
- depedentPackages=[] |
|
200 |
- defaultPkgName=self.spec.packages['default'].name |
|
201 |
- pkg = None |
|
202 |
- if self.spec.packages.has_key(packageName): |
|
203 |
- pkg = self.spec.packages.get(packageName) |
|
204 |
- if defaultPkgName == packageName: |
|
205 |
- pkg=self.spec.packages['default'] |
|
206 |
- if pkg is not None: |
|
207 |
- for dpkg in pkg.provides: |
|
208 |
- depedentPackages.append(dpkg.package) |
|
209 |
- else: |
|
210 |
- print "package not found" |
|
211 |
- return depedentPackages |
|
212 |
- |
|
213 |
- def getVersion(self): |
|
214 |
- pkg = self.spec.packages.get('default') |
|
215 |
- return pkg.version |
|
216 |
- |
|
217 |
- def getRelease(self): |
|
218 |
- pkg = self.spec.packages.get('default') |
|
219 |
- return pkg.release |
|
220 |
- |
|
221 |
- def getBasePackageName(self): |
|
222 |
- pkg = self.spec.packages.get('default') |
|
223 |
- return pkg.name |
|
224 |
- |
|
225 |
- def getSecurityHardeningOption(self): |
|
226 |
- return self.spec.globalSecurityHardening |
|
227 |
- |
|
228 |
-def main(): |
|
229 |
- spec = Specutils("/workspace1/myrepos/photon/SPECS/docker/docker.spec") |
|
230 |
- print "packages",spec.getPackageNames() |
|
231 |
- print "packages",spec.getRPMNames() |
|
232 |
- print "sources",spec.getSourceNames() |
|
233 |
- print "patches",spec.getPatchNames() |
|
234 |
- print "requires",spec.getRequires('libltdl-devel') |
|
235 |
- print "requires",spec.getRequires('libtool') |
|
236 |
- |
|
237 |
- print "provides",spec.getProvides('libtool') |
|
238 |
- print "all-requires",spec.getRequiresAllPackages() |
|
239 |
- print "all-build-requires",spec.getBuildRequiresAllPackages() |
|
240 |
- |
|
241 |
-if __name__ == '__main__': |
|
242 |
- main() |
|
243 |
- |
244 | 1 |
deleted file mode 100755 |
... | ... |
@@ -1,74 +0,0 @@ |
1 |
-#!/usr/bin/python2 |
|
2 |
-# |
|
3 |
-#Copyright (C) 2015 vmware inc. |
|
4 |
-# |
|
5 |
-#Author: Harish Udaiya Kumar <hudaiyakumar@vmware.com> |
|
6 |
-from SpecUtils import Specutils |
|
7 |
-from SpecData import SerializableSpecObject |
|
8 |
-from SpecData import SerializedSpecObjects |
|
9 |
-from RepoDeps import RepoQueryDependency |
|
10 |
-import sys |
|
11 |
-import os |
|
12 |
-from optparse import OptionParser |
|
13 |
-from jsonwrapper import JsonWrapper |
|
14 |
- |
|
15 |
-DEFAULT_INPUT_TYPE = "json" |
|
16 |
-DEFAULT_DISPLAY_OPTION = "tree" |
|
17 |
-SPEC_FILE_DIR = "../../SPECS" |
|
18 |
-INPUT_DATA_DIR = "../../common/data" |
|
19 |
- |
|
20 |
-def reportMissing(pkg,specDepList, repoDepList, excludeList): |
|
21 |
- missingList = []; |
|
22 |
- if None != repoDepList: |
|
23 |
- for repoItem in repoDepList: |
|
24 |
- if repoItem not in excludeList and (None == specDepList or repoItem not in specDepList): |
|
25 |
- missingList.append(repoItem) |
|
26 |
- if missingList: |
|
27 |
- if len(pkg) <= 7: |
|
28 |
- print pkg, "missing\t\t->", missingList |
|
29 |
- else: |
|
30 |
- print pkg, "missing\t->", missingList |
|
31 |
- |
|
32 |
-def main(): |
|
33 |
- usage = os.path.basename(__file__) + "--input-type=[json/pkg] --pkg=[pkg_name] --file=<JSON_FILE_NAME> --repo-file=<photon>.repo" |
|
34 |
- parser = OptionParser(usage) |
|
35 |
- parser.add_option("-i", "--input-type", dest="input_type", default=DEFAULT_INPUT_TYPE) |
|
36 |
- parser.add_option("-p", "--pkg", dest="pkg") |
|
37 |
- parser.add_option("-f", "--file", dest="json_file", default="packages_full.json") |
|
38 |
- parser.add_option("-s", "--spec-dir", dest="spec_dir", default=SPEC_FILE_DIR) |
|
39 |
- parser.add_option("-a", "--input-data-dir", dest="input_data_dir", default=INPUT_DATA_DIR) |
|
40 |
- parser.add_option("-r", "--repo-file", dest = "repo_file", default="") |
|
41 |
- excludeList = ["bash","glibc","libgcc","pkg-config","filesystem"] |
|
42 |
- (options, args) = parser.parse_args() |
|
43 |
- |
|
44 |
- if(options.repo_file == ""): |
|
45 |
- print "Error! repo file not provided" |
|
46 |
- print usage |
|
47 |
- return |
|
48 |
- |
|
49 |
- if(False == options.input_data_dir.endswith('/')): |
|
50 |
- options.input_data_dir += '/' |
|
51 |
- |
|
52 |
- specDeps = SerializedSpecObjects(options.input_data_dir, "") |
|
53 |
- repoDeps = RepoQueryDependency(options.repo_file) |
|
54 |
- displayOption = None |
|
55 |
- abs_path = os.path.abspath(__file__) |
|
56 |
- dir_name = os.path.dirname(abs_path) |
|
57 |
- os.chdir(dir_name) |
|
58 |
- |
|
59 |
- if(options.input_type == "pkg"): |
|
60 |
- targetName = options.pkg |
|
61 |
- specDepList = specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, targetName, displayOption) |
|
62 |
- repoDepList = repoDeps.getRequiresList(targetName) |
|
63 |
- reportMissing(targetName,specDepList,repoDepList,excludeList) |
|
64 |
- elif(options.input_type == "json"): |
|
65 |
- filePath = options.input_data_dir + options.json_file |
|
66 |
- data = specDeps.get_all_package_names(filePath) |
|
67 |
- for pkg in data: |
|
68 |
- specDepList = specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, "pkg" , pkg, displayOption) |
|
69 |
- repoDepList = repoDeps.getRequiresList(pkg) |
|
70 |
- reportMissing(pkg,specDepList,repoDepList,excludeList) |
|
71 |
- sys.exit(0) |
|
72 |
- |
|
73 |
-if __name__=="__main__": |
|
74 |
- main() |
75 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,21 +0,0 @@ |
1 |
-import re |
|
2 |
- |
|
3 |
-class StringUtils(object): |
|
4 |
- |
|
5 |
- def getStringInBrackets(self, inputstring): |
|
6 |
- inputstring=inputstring.strip() |
|
7 |
- m = re.search(r"^\(([A-Za-z0-9_.-]+)\)", inputstring) |
|
8 |
- if m is None: |
|
9 |
- return inputstring |
|
10 |
- return m.group(1) |
|
11 |
- |
|
12 |
- def getFileNameFromURL(self,inputstring): |
|
13 |
- index=inputstring.rfind("/") |
|
14 |
- return inputstring[index+1:] |
|
15 |
- |
|
16 |
- def getSpecNameFromPackageName(self, pkgName): |
|
17 |
- id = pkgName.rfind("-") |
|
18 |
- if (id != -1): |
|
19 |
- return pkgName[0:id]; |
|
20 |
- else: |
|
21 |
- return pkgName; |
22 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,25 +0,0 @@ |
1 |
-#!/usr/bin/python2 |
|
2 |
-# |
|
3 |
-# Copyright (C) 2015 vmware inc. |
|
4 |
-# |
|
5 |
-# Author: Sharath George <sharathg@vmware.com> |
|
6 |
- |
|
7 |
- |
|
8 |
-import json |
|
9 |
-import collections |
|
10 |
- |
|
11 |
-class JsonWrapper(object): |
|
12 |
- |
|
13 |
- def __init__(self, filename): |
|
14 |
- self.filename = filename |
|
15 |
- |
|
16 |
- def read(self): |
|
17 |
- json_data = open(self.filename) |
|
18 |
- self.data = json.load(json_data, object_pairs_hook=collections.OrderedDict) |
|
19 |
- json_data.close() |
|
20 |
- return self.data |
|
21 |
- |
|
22 |
- def write(self, data): |
|
23 |
- self.data = data |
|
24 |
- outfile = open(self.filename, 'wb') |
|
25 |
- json.dump(data, outfile) |
... | ... |
@@ -38,7 +38,7 @@ PHOTON_CLOUD_IMAGE_BUILDER_DIR=$(SRCROOT)/support/cloud-image-builder |
38 | 38 |
|
39 | 39 |
PHOTON_INSTALLER_DIR=$(SRCROOT)/installer |
40 | 40 |
PHOTON_INSTALLER=$(PHOTON_INSTALLER_DIR)/photonInstaller.py |
41 |
-PHOTON_SPECDEPS_DIR=$(SRCROOT)/support/SpecDeps |
|
41 |
+PHOTON_SPECDEPS_DIR=$(SRCROOT)/support/package-builder |
|
42 | 42 |
PHOTON_SPECDEPS=$(PHOTON_SPECDEPS_DIR)/SpecDeps.py |
43 | 43 |
PHOTON_PACKAGE_BUILDER=$(PHOTON_PKG_BUILDER_DIR)/builder.py |
44 | 44 |
ifdef PHOTON_PULLSOURCES_CONFIG |
... | ... |
@@ -7,6 +7,7 @@ import sys |
7 | 7 |
from constants import constants |
8 | 8 |
import shutil |
9 | 9 |
import docker |
10 |
+from SpecData import SPECS |
|
10 | 11 |
|
11 | 12 |
class BuildContainer(object): |
12 | 13 |
|
... | ... |
@@ -105,8 +106,8 @@ class BuildContainer(object): |
105 | 105 |
outputMap[threadName] = False |
106 | 106 |
|
107 | 107 |
def checkIfPackageIsAlreadyBuilt(self, package): |
108 |
- basePkg = constants.specData.getSpecName(package) |
|
109 |
- listRPMPackages = constants.specData.getRPMPackages(basePkg) |
|
108 |
+ basePkg = SPECS.getData().getSpecName(package) |
|
109 |
+ listRPMPackages = SPECS.getData().getRPMPackages(basePkg) |
|
110 | 110 |
packageIsAlreadyBuilt = True |
111 | 111 |
pkgUtils = PackageUtils(self.logName,self.logPath) |
112 | 112 |
for pkg in listRPMPackages: |
... | ... |
@@ -193,15 +194,15 @@ class BuildContainer(object): |
193 | 193 |
containerID.remove(force=True) |
194 | 194 |
|
195 | 195 |
def findRunTimeRequiredRPMPackages(self, rpmPackage): |
196 |
- listRequiredPackages = constants.specData.getRequiresForPackage(rpmPackage) |
|
196 |
+ listRequiredPackages = SPECS.getData().getRequiresForPackage(rpmPackage) |
|
197 | 197 |
return listRequiredPackages |
198 | 198 |
|
199 | 199 |
def findBuildTimeRequiredPackages(self, package): |
200 |
- listRequiredPackages = constants.specData.getBuildRequiresForPackage(package) |
|
200 |
+ listRequiredPackages = SPECS.getData().getBuildRequiresForPackage(package) |
|
201 | 201 |
return listRequiredPackages |
202 | 202 |
|
203 | 203 |
def findBuildTimeCheckRequiredPackages(self,package): |
204 |
- listRequiredPackages=constants.specData.getCheckBuildRequiresForPackage(package) |
|
204 |
+ listRequiredPackages=SPECS.getData().getCheckBuildRequiresForPackage(package) |
|
205 | 205 |
return listRequiredPackages |
206 | 206 |
|
207 | 207 |
def installPackage(self, pkgUtils, package, containerID, destLogPath, listInstalledPackages, listInstalledRPMs): |
... | ... |
@@ -2,6 +2,7 @@ from Logger import Logger |
2 | 2 |
from constants import constants |
3 | 3 |
from sets import Set |
4 | 4 |
import copy |
5 |
+from SpecData import SPECS |
|
5 | 6 |
|
6 | 7 |
|
7 | 8 |
|
... | ... |
@@ -46,7 +47,7 @@ class PackageBuildDataGenerator(object): |
46 | 46 |
sortListForPkg=[] |
47 | 47 |
|
48 | 48 |
for p in runTimeDepPkgList: |
49 |
- basePkg=constants.specData.getSpecName(p) |
|
49 |
+ basePkg=SPECS.getData().getSpecName(p) |
|
50 | 50 |
for bPkg in self.__sortedBuildDependencyGraph[basePkg]: |
51 | 51 |
if bPkg not in sortListForPkg: |
52 | 52 |
sortListForPkg.append(bPkg) |
... | ... |
@@ -121,7 +122,7 @@ class PackageBuildDataGenerator(object): |
121 | 121 |
self.__sortedPackageList=sortedList |
122 | 122 |
|
123 | 123 |
def __constructBuildAndRunTimeDependencyGraph(self,package): |
124 |
- basePackage=constants.specData.getSpecName(package) |
|
124 |
+ basePackage=SPECS.getData().getSpecName(package) |
|
125 | 125 |
|
126 | 126 |
addBuildTimeGraph=True |
127 | 127 |
addRunTimeGraph=True |
... | ... |
@@ -132,19 +133,19 @@ class PackageBuildDataGenerator(object): |
132 | 132 |
|
133 | 133 |
nextPackagesToConstructGraph=[] |
134 | 134 |
if addBuildTimeGraph: |
135 |
- listDependentRpmPackages=constants.specData.getBuildRequiresForPackage(basePackage) |
|
135 |
+ listDependentRpmPackages=SPECS.getData().getBuildRequiresForPackage(basePackage) |
|
136 | 136 |
listDependentPackages=[] |
137 | 137 |
for rpmPkg in listDependentRpmPackages: |
138 |
- basePkg=constants.specData.getSpecName(rpmPkg) |
|
138 |
+ basePkg=SPECS.getData().getSpecName(rpmPkg) |
|
139 | 139 |
if basePkg not in listDependentPackages: |
140 | 140 |
listDependentPackages.append(basePkg) |
141 | 141 |
self.__buildDependencyGraph[basePackage]=listDependentPackages |
142 | 142 |
nextPackagesToConstructGraph.extend(listDependentPackages) |
143 | 143 |
|
144 | 144 |
if addRunTimeGraph: |
145 |
- listRpmPackages=constants.specData.getPackages(basePackage) |
|
145 |
+ listRpmPackages=SPECS.getData().getPackages(basePackage) |
|
146 | 146 |
for rpmPkg in listRpmPackages: |
147 |
- listDependentRpmPackages=constants.specData.getRequiresAllForPackage(rpmPkg) |
|
147 |
+ listDependentRpmPackages=SPECS.getData().getRequiresAllForPackage(rpmPkg) |
|
148 | 148 |
self.__runTimeDependencyGraph[rpmPkg]=listDependentRpmPackages[:] |
149 | 149 |
nextPackagesToConstructGraph.extend(listDependentRpmPackages) |
150 | 150 |
|
... | ... |
@@ -284,4 +285,4 @@ class PackageBuildDataGenerator(object): |
284 | 284 |
|
285 | 285 |
|
286 | 286 |
|
287 |
- |
|
288 | 287 |
\ No newline at end of file |
288 |
+ |
... | ... |
@@ -6,6 +6,7 @@ from CommandUtils import CommandUtils |
6 | 6 |
import os.path |
7 | 7 |
from constants import constants |
8 | 8 |
import shutil |
9 |
+from SpecData import SPECS |
|
9 | 10 |
|
10 | 11 |
class PackageBuilder(object): |
11 | 12 |
|
... | ... |
@@ -72,8 +73,8 @@ class PackageBuilder(object): |
72 | 72 |
outputMap[threadName]=False |
73 | 73 |
|
74 | 74 |
def checkIfPackageIsAlreadyBuilt(self, package): |
75 |
- basePkg=constants.specData.getSpecName(package) |
|
76 |
- listRPMPackages=constants.specData.getRPMPackages(basePkg) |
|
75 |
+ basePkg=SPECS.getData().getSpecName(package) |
|
76 |
+ listRPMPackages=SPECS.getData().getRPMPackages(basePkg) |
|
77 | 77 |
packageIsAlreadyBuilt=True |
78 | 78 |
pkgUtils = PackageUtils(self.logName,self.logPath) |
79 | 79 |
for pkg in listRPMPackages: |
... | ... |
@@ -136,15 +137,15 @@ class PackageBuilder(object): |
136 | 136 |
|
137 | 137 |
|
138 | 138 |
def findRunTimeRequiredRPMPackages(self,rpmPackage): |
139 |
- listRequiredPackages=constants.specData.getRequiresForPackage(rpmPackage) |
|
139 |
+ listRequiredPackages=SPECS.getData().getRequiresForPackage(rpmPackage) |
|
140 | 140 |
return listRequiredPackages |
141 | 141 |
|
142 | 142 |
def findBuildTimeRequiredPackages(self,package): |
143 |
- listRequiredPackages=constants.specData.getBuildRequiresForPackage(package) |
|
143 |
+ listRequiredPackages=SPECS.getData().getBuildRequiresForPackage(package) |
|
144 | 144 |
return listRequiredPackages |
145 | 145 |
|
146 | 146 |
def findBuildTimeCheckRequiredPackages(self,package): |
147 |
- listRequiredPackages=constants.specData.getCheckBuildRequiresForPackage(package) |
|
147 |
+ listRequiredPackages=SPECS.getData().getCheckBuildRequiresForPackage(package) |
|
148 | 148 |
return listRequiredPackages |
149 | 149 |
|
150 | 150 |
def installPackage(self,pkgUtils,package,chrootID,destLogPath,listInstalledPackages): |
... | ... |
@@ -4,6 +4,7 @@ from constants import constants |
4 | 4 |
import os.path |
5 | 5 |
from CommandUtils import CommandUtils |
6 | 6 |
from PackageUtils import PackageUtils |
7 |
+from SpecData import SPECS |
|
7 | 8 |
|
8 | 9 |
class PackageInfo(object): |
9 | 10 |
|
... | ... |
@@ -18,14 +19,14 @@ class PackageInfo(object): |
18 | 18 |
self.pkgList = {} |
19 | 19 |
|
20 | 20 |
def loadPackagesData(self): |
21 |
- listPackages = constants.specData.getListPackages() |
|
21 |
+ listPackages = SPECS.getData().getListPackages() |
|
22 | 22 |
listPackages.sort() |
23 | 23 |
listRPMFiles = [] |
24 | 24 |
cmdUtils = CommandUtils() |
25 | 25 |
for package in listPackages: |
26 |
- release = constants.specData.getRelease(package) |
|
27 |
- version = constants.specData.getVersion(package) |
|
28 |
- listRPMPackages = constants.specData.getRPMPackages(package) |
|
26 |
+ release = SPECS.getData().getRelease(package) |
|
27 |
+ version = SPECS.getData().getVersion(package) |
|
28 |
+ listRPMPackages = SPECS.getData().getRPMPackages(package) |
|
29 | 29 |
srpmFileName = package+"-"+version+"-"+release+".src.rpm" |
30 | 30 |
srpmFiles = cmdUtils.findFile(srpmFileName, constants.sourceRpmPath) |
31 | 31 |
srpmFile = None |
... | ... |
@@ -10,6 +10,7 @@ from PackageUtils import PackageUtils |
10 | 10 |
from ToolChainUtils import ToolChainUtils |
11 | 11 |
from Scheduler import Scheduler |
12 | 12 |
from ThreadPool import ThreadPool |
13 |
+from SpecData import SPECS |
|
13 | 14 |
|
14 | 15 |
class PackageManager(object): |
15 | 16 |
|
... | ... |
@@ -63,17 +64,17 @@ class PackageManager(object): |
63 | 63 |
pkgUtils = PackageUtils(self.logName,self.logPath) |
64 | 64 |
for rpmfile in listRPMFiles: |
65 | 65 |
package,version,release = pkgUtils.findPackageInfoFromRPMFile(rpmfile) |
66 |
- if constants.specData.isRPMPackage(package): |
|
67 |
- specVersion=constants.specData.getVersion(package) |
|
68 |
- specRelease=constants.specData.getRelease(package) |
|
66 |
+ if SPECS.getData().isRPMPackage(package): |
|
67 |
+ specVersion=SPECS.getData().getVersion(package) |
|
68 |
+ specRelease=SPECS.getData().getRelease(package) |
|
69 | 69 |
if version == specVersion and release == specRelease: |
70 | 70 |
listFoundRPMPackages.append(package) |
71 | 71 |
#Mark package available only if all sub packages are available |
72 | 72 |
for package in listFoundRPMPackages: |
73 |
- basePkg = constants.specData.getSpecName(package) |
|
73 |
+ basePkg = SPECS.getData().getSpecName(package) |
|
74 | 74 |
if basePkg in listAvailablePackages: |
75 | 75 |
continue; |
76 |
- listRPMPackages = constants.specData.getRPMPackages(basePkg) |
|
76 |
+ listRPMPackages = SPECS.getData().getRPMPackages(basePkg) |
|
77 | 77 |
packageIsAlreadyBuilt = True |
78 | 78 |
for rpmpkg in listRPMPackages: |
79 | 79 |
if rpmpkg not in listFoundRPMPackages: |
... | ... |
@@ -102,7 +103,7 @@ class PackageManager(object): |
102 | 102 |
updateBuiltRPMSList = True |
103 | 103 |
listOfPackagesAlreadyBuilt = self.listOfPackagesAlreadyBuilt[:] |
104 | 104 |
for pkg in listOfPackagesAlreadyBuilt: |
105 |
- listDependentRpmPackages = constants.specData.getRequiresAllForPackage(pkg) |
|
105 |
+ listDependentRpmPackages = SPECS.getData().getRequiresAllForPackage(pkg) |
|
106 | 106 |
needToRebuild = False |
107 | 107 |
for dependentPkg in listDependentRpmPackages: |
108 | 108 |
if dependentPkg not in self.listOfPackagesAlreadyBuilt: |
... | ... |
@@ -8,6 +8,7 @@ from time import sleep |
8 | 8 |
import PullSources |
9 | 9 |
import json |
10 | 10 |
import collections |
11 |
+from SpecData import SPECS |
|
11 | 12 |
|
12 | 13 |
class PackageUtils(object): |
13 | 14 |
|
... | ... |
@@ -110,7 +111,7 @@ class PackageUtils(object): |
110 | 110 |
def verifyShaAndGetSourcePath(self, source, package): |
111 | 111 |
cmdUtils = CommandUtils() |
112 | 112 |
# Fetch/verify sources if sha1 not None. |
113 |
- sha1 = constants.specData.getSHA1(package, source) |
|
113 |
+ sha1 = SPECS.getData().getSHA1(package, source) |
|
114 | 114 |
if sha1 is not None: |
115 | 115 |
PullSources.get(source, sha1, constants.sourcePath, constants.pullsourcesConfig, self.logger) |
116 | 116 |
|
... | ... |
@@ -171,10 +172,10 @@ class PackageUtils(object): |
171 | 171 |
def buildRPMSForGivenPackage(self,package,chrootID,listBuildOptionPackages,pkgBuildOptionFile,destLogPath=None): |
172 | 172 |
self.logger.info("Building rpm's for package:"+package) |
173 | 173 |
|
174 |
- listSourcesFiles = constants.specData.getSources(package) |
|
175 |
- listPatchFiles = constants.specData.getPatches(package) |
|
176 |
- specFile = constants.specData.getSpecFile(package) |
|
177 |
- specName = constants.specData.getSpecName(package) + ".spec" |
|
174 |
+ listSourcesFiles = SPECS.getData().getSources(package) |
|
175 |
+ listPatchFiles = SPECS.getData().getPatches(package) |
|
176 |
+ specFile = SPECS.getData().getSpecFile(package) |
|
177 |
+ specName = SPECS.getData().getSpecName(package) + ".spec" |
|
178 | 178 |
|
179 | 179 |
chrootSourcePath=chrootID+constants.topDirPath+"/SOURCES/" |
180 | 180 |
chrootSpecPath=constants.topDirPath+"/SPECS/" |
... | ... |
@@ -193,7 +194,7 @@ class PackageUtils(object): |
193 | 193 |
self.copyAdditionalBuildFiles(listAdditionalFiles,chrootID) |
194 | 194 |
|
195 | 195 |
#Adding rpm macros |
196 |
- listRPMMacros = constants.specData.getRPMMacros() |
|
196 |
+ listRPMMacros = SPECS.getData().getRPMMacros() |
|
197 | 197 |
for macroName in listRPMMacros.keys(): |
198 | 198 |
macros.append(macroName+" "+listRPMMacros[macroName]) |
199 | 199 |
|
... | ... |
@@ -207,7 +208,7 @@ class PackageUtils(object): |
207 | 207 |
raise e |
208 | 208 |
finally: |
209 | 209 |
if destLogPath is not None: |
210 |
- if constants.rpmCheck and package in constants.testForceRPMS and constants.specData.isCheckAvailable(package): |
|
210 |
+ if constants.rpmCheck and package in constants.testForceRPMS and SPECS.getData().isCheckAvailable(package): |
|
211 | 211 |
cmd="sed -i '/^Executing(%check):/,/^Processing files:/{//!b};d' "+ chrootLogsFilePath |
212 | 212 |
logFile = destLogPath+"/adjustTestFile.log" |
213 | 213 |
returnVal = CommandUtils().runCommandInShell(cmd, logFile) |
... | ... |
@@ -230,7 +231,7 @@ class PackageUtils(object): |
230 | 230 |
|
231 | 231 |
if constants.rpmCheck and package in constants.testForceRPMS: |
232 | 232 |
self.logger.info("#"*(68+2*len(package))) |
233 |
- if not constants.specData.isCheckAvailable(package): |
|
233 |
+ if not SPECS.getData().isCheckAvailable(package): |
|
234 | 234 |
self.logger.info("####### "+package+" MakeCheck is not available. Skipping MakeCheck TEST for "+package+ " #######") |
235 | 235 |
rpmBuildcmd=self.rpmbuildBinary+" --clean" |
236 | 236 |
else: |
... | ... |
@@ -249,7 +250,7 @@ class PackageUtils(object): |
249 | 249 |
self.logger.info(rpmBuildcmd) |
250 | 250 |
returnVal = cmdUtils.runCommandInShell(rpmBuildcmd, logFile, chrootCmd) |
251 | 251 |
if constants.rpmCheck and package in constants.testForceRPMS: |
252 |
- if not constants.specData.isCheckAvailable(package): |
|
252 |
+ if not SPECS.getData().isCheckAvailable(package): |
|
253 | 253 |
constants.testLogger.info(package+" : N/A") |
254 | 254 |
elif returnVal: |
255 | 255 |
constants.testLogger.info(package+" : PASS") |
... | ... |
@@ -282,8 +283,8 @@ class PackageUtils(object): |
282 | 282 |
|
283 | 283 |
def findRPMFileForGivenPackage(self,package): |
284 | 284 |
cmdUtils = CommandUtils() |
285 |
- version = constants.specData.getVersion(package) |
|
286 |
- release = constants.specData.getRelease(package) |
|
285 |
+ version = SPECS.getData().getVersion(package) |
|
286 |
+ release = SPECS.getData().getRelease(package) |
|
287 | 287 |
listFoundRPMFiles = sum([cmdUtils.findFile(package+"-"+version+"-"+release+".x86_64.rpm",constants.rpmPath), |
288 | 288 |
cmdUtils.findFile(package+"-"+version+"-"+release+".noarch.rpm",constants.rpmPath)], []) |
289 | 289 |
if constants.inputRPMSPath is not None: |
... | ... |
@@ -337,7 +338,7 @@ class PackageUtils(object): |
337 | 337 |
return result |
338 | 338 |
|
339 | 339 |
def adjustGCCSpecs(self, package, chrootID, logPath): |
340 |
- opt = " " + constants.specData.getSecurityHardeningOption(package) |
|
340 |
+ opt = " " + SPECS.getData().getSecurityHardeningOption(package) |
|
341 | 341 |
cmdUtils=CommandUtils() |
342 | 342 |
cpcmd="cp "+ self.adjustGCCSpecScript+" "+chrootID+"/tmp/"+self.adjustGCCSpecScript |
343 | 343 |
cmd = "/tmp/"+self.adjustGCCSpecScript+opt |
... | ... |
@@ -492,7 +493,7 @@ class PackageUtils(object): |
492 | 492 |
return result |
493 | 493 |
|
494 | 494 |
def adjustGCCSpecsInContainer(self, package, containerID, logPath): |
495 |
- opt = " " + constants.specData.getSecurityHardeningOption(package) |
|
495 |
+ opt = " " + SPECS.getData().getSecurityHardeningOption(package) |
|
496 | 496 |
adjustCmd = "/" + self.adjustGCCSpecScript + opt |
497 | 497 |
adjustCmd = "/bin/bash -l -c '" + adjustCmd + "'" |
498 | 498 |
logFile = logPath + "/adjustGCCSpecScript.log" |
... | ... |
@@ -515,10 +516,10 @@ class PackageUtils(object): |
515 | 515 |
pkgBuildOptionFile, destLogPath=None): |
516 | 516 |
self.logger.info("Building rpm's for package " + package + " in container " + containerID.short_id) |
517 | 517 |
|
518 |
- listSourcesFiles = constants.specData.getSources(package) |
|
519 |
- listPatchFiles = constants.specData.getPatches(package) |
|
520 |
- specFile = constants.specData.getSpecFile(package) |
|
521 |
- specName = constants.specData.getSpecName(package) + ".spec" |
|
518 |
+ listSourcesFiles = SPECS.getData().getSources(package) |
|
519 |
+ listPatchFiles = SPECS.getData().getPatches(package) |
|
520 |
+ specFile = SPECS.getData().getSpecFile(package) |
|
521 |
+ specName = SPECS.getData().getSpecName(package) + ".spec" |
|
522 | 522 |
sourcePath = constants.topDirPath + "/SOURCES/" |
523 | 523 |
specPath = constants.topDirPath + "/SPECS/" |
524 | 524 |
rpmLogFile = constants.topDirPath + "/LOGS/" + package + ".log" |
... | ... |
@@ -545,7 +546,7 @@ class PackageUtils(object): |
545 | 545 |
self.copyAdditionalBuildFilesToContainer(listAdditionalFiles, containerID) |
546 | 546 |
|
547 | 547 |
# Add rpm macros |
548 |
- listRPMMacros = constants.specData.getRPMMacros() |
|
548 |
+ listRPMMacros = SPECS.getData().getRPMMacros() |
|
549 | 549 |
for macroName in listRPMMacros.keys(): |
550 | 550 |
macros.append(macroName + " " + listRPMMacros[macroName]) |
551 | 551 |
|
... | ... |
@@ -567,7 +568,7 @@ class PackageUtils(object): |
567 | 567 |
finally: |
568 | 568 |
if destLogPath is not None: |
569 | 569 |
rpmLog = destLogPath + "/" + package + ".log" |
570 |
- if constants.rpmCheck and package in constants.testForceRPMS and constants.specData.isCheckAvailable(package): |
|
570 |
+ if constants.rpmCheck and package in constants.testForceRPMS and SPECS.getData().isCheckAvailable(package): |
|
571 | 571 |
cmd="sed -i '/^Executing(%check):/,/^Processing files:/{//!b};d' "+ rpmLog |
572 | 572 |
logFile = destLogPath+"/adjustTestFile.log" |
573 | 573 |
returnVal = CommandUtils().runCommandInShell(cmd, logFile) |
... | ... |
@@ -600,7 +601,7 @@ class PackageUtils(object): |
600 | 600 |
|
601 | 601 |
if constants.rpmCheck and package in constants.testForceRPMS: |
602 | 602 |
self.logger.info("#"*(68+2*len(package))) |
603 |
- if not constants.specData.isCheckAvailable(package): |
|
603 |
+ if not SPECS.getData().isCheckAvailable(package): |
|
604 | 604 |
self.logger.info("####### "+package+" MakeCheck is not available. Skipping MakeCheck TEST for "+package+ " #######") |
605 | 605 |
rpmBuildCmd=self.rpmbuildBinary+" --clean" |
606 | 606 |
else: |
... | ... |
@@ -628,7 +629,7 @@ class PackageUtils(object): |
628 | 628 |
raise Exception("RPM Build failed") |
629 | 629 |
|
630 | 630 |
if constants.rpmCheck and package in constants.testForceRPMS: |
631 |
- if not constants.specData.isCheckAvailable(package): |
|
631 |
+ if not SPECS.getData().isCheckAvailable(package): |
|
632 | 632 |
constants.testLogger.info(package+" : N/A") |
633 | 633 |
elif returnVal: |
634 | 634 |
constants.testLogger.info(package+" : PASS") |
635 | 635 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,14 @@ |
0 |
+import commands |
|
1 |
+ |
|
2 |
+class RepoQueryDependency(object): |
|
3 |
+ def __init__(self, repoFile): |
|
4 |
+ self.repo_file = repoFile |
|
5 |
+ def getRequiresList(self,pkg): |
|
6 |
+ cmd = "repoquery -c "+self.repo_file+" -R -q "+pkg+" | xargs repoquery -c "+self.repo_file+" --whatprovides -q | sed 's/-[0-9]/ /g' | cut -f 1 -d ' ' | sort | uniq " |
|
7 |
+ status,output = commands.getstatusoutput(cmd) |
|
8 |
+ if status == 0: |
|
9 |
+ outList = output.split('\n') |
|
10 |
+ if "" in outList: outList.remove("") |
|
11 |
+ if "Options:" in outList: outList.remove("Options:") |
|
12 |
+ if "Usage:" in outList: outList.remove("Usage:") |
|
13 |
+ return outList |
... | ... |
@@ -4,6 +4,7 @@ from constants import constants |
4 | 4 |
from Logger import Logger |
5 | 5 |
import threading |
6 | 6 |
from Queue import PriorityQueue |
7 |
+from SpecData import SPECS |
|
7 | 8 |
|
8 | 9 |
class Scheduler(object): |
9 | 10 |
|
... | ... |
@@ -34,12 +35,12 @@ class Scheduler(object): |
34 | 34 |
@staticmethod |
35 | 35 |
def getBuildRequiredPackages(package): |
36 | 36 |
listRequiredRPMPackages = [] |
37 |
- listRequiredRPMPackages.extend(constants.specData.getBuildRequiresForPackage(package)) |
|
37 |
+ listRequiredRPMPackages.extend(SPECS.getData().getBuildRequiresForPackage(package)) |
|
38 | 38 |
|
39 | 39 |
listRequiredPackages = [] |
40 | 40 |
|
41 | 41 |
for pkg in listRequiredRPMPackages: |
42 |
- basePkg = constants.specData.getSpecName(pkg) |
|
42 |
+ basePkg = SPECS.getData().getSpecName(pkg) |
|
43 | 43 |
if basePkg not in listRequiredPackages: |
44 | 44 |
listRequiredPackages.append(basePkg) |
45 | 45 |
|
... | ... |
@@ -148,13 +149,13 @@ class Scheduler(object): |
148 | 148 |
@staticmethod |
149 | 149 |
def getRequiredPackages(package): |
150 | 150 |
listRequiredRPMPackages=[] |
151 |
- listRequiredRPMPackages.extend(constants.specData.getBuildRequiresForPackage(package)) |
|
152 |
- listRequiredRPMPackages.extend(constants.specData.getRequiresAllForPackage(package)) |
|
151 |
+ listRequiredRPMPackages.extend(SPECS.getData().getBuildRequiresForPackage(package)) |
|
152 |
+ listRequiredRPMPackages.extend(SPECS.getData().getRequiresAllForPackage(package)) |
|
153 | 153 |
|
154 | 154 |
listRequiredPackages=[] |
155 | 155 |
|
156 | 156 |
for pkg in listRequiredRPMPackages: |
157 |
- basePkg=constants.specData.getSpecName(pkg) |
|
157 |
+ basePkg=SPECS.getData().getSpecName(pkg) |
|
158 | 158 |
if basePkg not in listRequiredPackages: |
159 | 159 |
listRequiredPackages.append(basePkg) |
160 | 160 |
|
... | ... |
@@ -2,6 +2,10 @@ from SpecUtils import Specutils |
2 | 2 |
import os |
3 | 3 |
from Logger import Logger |
4 | 4 |
from distutils.version import StrictVersion |
5 |
+import Queue |
|
6 |
+import json |
|
7 |
+import operator |
|
8 |
+from constants import constants |
|
5 | 9 |
|
6 | 10 |
class SerializableSpecObject(object): |
7 | 11 |
def __init__(self): |
... | ... |
@@ -266,3 +270,322 @@ class SerializableSpecObjectsUtils(object): |
266 | 266 |
self.logger.info("security_hardening: " + specObj.securityHardening) |
267 | 267 |
self.logger.info("------------------------------------------------") |
268 | 268 |
|
269 |
+class SPECS(object): |
|
270 |
+ __instance = None |
|
271 |
+ specData = None |
|
272 |
+ |
|
273 |
+ @staticmethod |
|
274 |
+ def getData(): |
|
275 |
+ """ Static access method. """ |
|
276 |
+ if SPECS.__instance == None: |
|
277 |
+ SPECS() |
|
278 |
+ return SPECS.__instance.specData |
|
279 |
+ |
|
280 |
+ def __init__(self): |
|
281 |
+ """ Virtually private constructor. """ |
|
282 |
+ if SPECS.__instance != None: |
|
283 |
+ raise Exception("This class is a singleton!") |
|
284 |
+ else: |
|
285 |
+ SPECS.__instance = self |
|
286 |
+ self.initialize() |
|
287 |
+ |
|
288 |
+ def initialize(self): |
|
289 |
+ self.specData = SerializableSpecObjectsUtils(constants.logPath) |
|
290 |
+ self.specData.readSpecsAndConvertToSerializableObjects(constants.specPath) |
|
291 |
+ |
|
292 |
+ #adding distribution rpm macro |
|
293 |
+ self.specData.addMacro("dist",constants.dist) |
|
294 |
+ |
|
295 |
+ #adding buildnumber rpm macro |
|
296 |
+ self.specData.addMacro("photon_build_number",constants.buildNumber) |
|
297 |
+ |
|
298 |
+ #adding releasenumber rpm macro |
|
299 |
+ self.specData.addMacro("photon_release_version",constants.releaseVersion) |
|
300 |
+ |
|
301 |
+ #adding kernelversion rpm macro |
|
302 |
+ kernelversion = self.specData.getVersion("linux") |
|
303 |
+ self.specData.addMacro("KERNEL_VERSION",kernelversion) |
|
304 |
+ |
|
305 |
+ #adding openjre8 version rpm macro |
|
306 |
+ java8version = self.specData.getVersion("openjre8") |
|
307 |
+ self.specData.addMacro("JAVA8_VERSION",java8version) |
|
308 |
+ |
|
309 |
+ #adding kernelrelease rpm macro |
|
310 |
+ kernelrelease = self.specData.getRelease("linux") |
|
311 |
+ self.specData.addMacro("KERNEL_RELEASE",kernelrelease) |
|
312 |
+ |
|
313 |
+ #adding kernelsubrelease rpm macro |
|
314 |
+ a,b,c = kernelversion.split(".") |
|
315 |
+ kernelsubrelease = '%02d%02d%03d%03d' % (int(a),int(b),int(c),int(kernelrelease.replace(constants.dist,""))) |
|
316 |
+ if kernelsubrelease: |
|
317 |
+ kernelsubrelease = "."+kernelsubrelease |
|
318 |
+ self.specData.addMacro("kernelsubrelease",kernelsubrelease) |
|
319 |
+ |
|
320 |
+ #adding check rpm macro |
|
321 |
+ if constants.rpmCheck: |
|
322 |
+ self.specData.addMacro("with_check","1") |
|
323 |
+ else: |
|
324 |
+ self.specData.addMacro("with_check","0") |
|
325 |
+ |
|
326 |
+ |
|
327 |
+ |
|
328 |
+# Little bit of duplication |
|
329 |
+# Used by SpecVerify and SpecDeps only |
|
330 |
+class SerializedSpecObjects(object): |
|
331 |
+ |
|
332 |
+ def __init__(self, inputDataDir, stageDir): |
|
333 |
+ self.mapSerializableSpecObjects={} |
|
334 |
+ self.mapPackageToSpec={} |
|
335 |
+ self.jsonFilesOutPath = stageDir + "/common/data/" |
|
336 |
+ self.inputDataDir = inputDataDir |
|
337 |
+ |
|
338 |
+ def findTotalRequires(self, allDeps, depQue, parent, displayOption): |
|
339 |
+ while not depQue.empty(): |
|
340 |
+ specPkg = depQue.get() |
|
341 |
+ specName = self.getSpecName(specPkg) |
|
342 |
+ if specName is None: |
|
343 |
+ print specPkg + " is missing" |
|
344 |
+ specObj = self.mapSerializableSpecObjects[specName] |
|
345 |
+ for depPkg in specObj.installRequiresPackages[specPkg]: |
|
346 |
+ if True == allDeps.has_key(depPkg): |
|
347 |
+ if(allDeps[depPkg] < allDeps[specPkg] + 1): |
|
348 |
+ allDeps[depPkg] = allDeps[specPkg] + 1 |
|
349 |
+ parent[depPkg] = specPkg |
|
350 |
+ self.updateLevels(allDeps, depPkg, parent, allDeps[depPkg]) |
|
351 |
+ else: |
|
352 |
+ allDeps[depPkg] = allDeps[specPkg] + 1 |
|
353 |
+ parent[depPkg] = specPkg |
|
354 |
+ depQue.put(depPkg) |
|
355 |
+ |
|
356 |
+ def findTotalWhoNeedsToBuild(self, depQue, whoBuildDeps, whoBuildDepSet, displayOption): |
|
357 |
+ while not depQue.empty(): |
|
358 |
+ specPkg = depQue.get() |
|
359 |
+ specName = self.getSpecName(specPkg) |
|
360 |
+ spec=Specutils(self.getSpecFile(specPkg)) |
|
361 |
+ RPMName=spec.getRPMName(specPkg) |
|
362 |
+ debuginfoRPMName=spec.getDebuginfoRPMName(specPkg) |
|
363 |
+ whoBuildDepSet.add(RPMName) |
|
364 |
+ whoBuildDepSet.add(debuginfoRPMName) |
|
365 |
+ if specName is None: |
|
366 |
+ print specPkg + " is missing" |
|
367 |
+ if not whoBuildDeps.has_key(specPkg): |
|
368 |
+ continue |
|
369 |
+ for depPkg in whoBuildDeps[specPkg]: |
|
370 |
+ depQue.put(depPkg) |
|
371 |
+ |
|
372 |
+ def printTree(self, allDeps, children, curParent , depth): |
|
373 |
+ if (children.has_key(curParent)): |
|
374 |
+ for child in children[curParent]: |
|
375 |
+ print "\t" * depth, child |
|
376 |
+ self.printTree(allDeps, children, child, depth+1) |
|
377 |
+ |
|
378 |
+ def get_all_package_names(self, jsonFilePath): |
|
379 |
+ base_path = os.path.dirname(jsonFilePath) |
|
380 |
+ jsonData = open(jsonFilePath) |
|
381 |
+ option_list_json = json.load(jsonData) |
|
382 |
+ jsonData.close() |
|
383 |
+ packages = option_list_json["packages"] |
|
384 |
+ return packages |
|
385 |
+ |
|
386 |
+ def updateLevels(self, allDeps, inPkg, parent, level): |
|
387 |
+ specName = self.getSpecName(inPkg) |
|
388 |
+ specObj = self.mapSerializableSpecObjects[specName] |
|
389 |
+ for depPkg in specObj.installRequiresPackages[inPkg]: |
|
390 |
+ if (allDeps.has_key(depPkg) and allDeps[depPkg] < level + 1): |
|
391 |
+ allDeps[depPkg] = level + 1 |
|
392 |
+ parent[depPkg] = inPkg |
|
393 |
+ self.updateLevels(allDeps, depPkg, parent, allDeps[depPkg]) |
|
394 |
+ |
|
395 |
+ def readSpecsAndConvertToSerializableObjects(self, specFilesPath, inputType, inputValue, displayOption): |
|
396 |
+ children = {} |
|
397 |
+ listSpecFiles=[] |
|
398 |
+ whoNeedsList=[] |
|
399 |
+ whoBuildDepSet= set() |
|
400 |
+ independentRPMS=[] # list of all RPMS not built from photon and that must be blindly copied. |
|
401 |
+ whoBuildDeps = {} |
|
402 |
+ allDeps={} |
|
403 |
+ parent={} |
|
404 |
+ depQue = Queue.Queue() |
|
405 |
+ packageFound = False |
|
406 |
+ self.getListSpecFiles(listSpecFiles,specFilesPath) |
|
407 |
+ for specFile in listSpecFiles: |
|
408 |
+ spec=Specutils(specFile) |
|
409 |
+ specName=spec.getBasePackageName() |
|
410 |
+ specObj=SerializableSpecObject() |
|
411 |
+ specObj.name=specName |
|
412 |
+ specObj.buildRequirePackages=spec.getBuildRequiresAllPackages() |
|
413 |
+ specObj.installRequiresAllPackages=spec.getRequiresAllPackages() |
|
414 |
+ specObj.listPackages=spec.getPackageNames() |
|
415 |
+ specObj.specFile=specFile |
|
416 |
+ specObj.version=spec.getVersion() |
|
417 |
+ specObj.release=spec.getRelease() |
|
418 |
+ specObj.listSources=spec.getSourceNames() |
|
419 |
+ specObj.listPatches=spec.getPatchNames() |
|
420 |
+ specObj.securityHardening=spec.getSecurityHardeningOption() |
|
421 |
+ for specPkg in specObj.listPackages: |
|
422 |
+ specObj.installRequiresPackages[specPkg]=spec.getRequires(specPkg) |
|
423 |
+ if (inputType == "pkg" and inputValue == specPkg): # all the first level dependencies to a dictionary and queue |
|
424 |
+ packageFound = True |
|
425 |
+ for depPkg in specObj.installRequiresPackages[specPkg]: |
|
426 |
+ if False == allDeps.has_key(depPkg): |
|
427 |
+ allDeps[depPkg] = 0 |
|
428 |
+ parent[depPkg] = "" |
|
429 |
+ depQue.put(depPkg) |
|
430 |
+ elif (inputType == "who-needs" and (inputValue in specObj.installRequiresPackages[specPkg])): |
|
431 |
+ whoNeedsList.append(specPkg) |
|
432 |
+ elif (inputType == "who-needs-build"): |
|
433 |
+ for bdrq in specObj.buildRequirePackages: |
|
434 |
+ if (whoBuildDeps.has_key(bdrq)): |
|
435 |
+ whoBuildDeps[bdrq].add(specPkg) |
|
436 |
+ else: |
|
437 |
+ whoBuildDeps[bdrq] = set() |
|
438 |
+ whoBuildDeps[bdrq].add(specPkg) |
|
439 |
+ if(inputValue == specPkg): |
|
440 |
+ packageFound = True |
|
441 |
+ for depPkg in specObj.listPackages: |
|
442 |
+ depQue.put(depPkg) |
|
443 |
+ |
|
444 |
+ self.mapPackageToSpec[specPkg]=specName |
|
445 |
+ self.mapSerializableSpecObjects[specName]=specObj |
|
446 |
+ |
|
447 |
+ # Generate dependencies for individual packages |
|
448 |
+ if (inputType == "pkg"): |
|
449 |
+ if (packageFound == True): |
|
450 |
+ self.findTotalRequires(allDeps, depQue, parent, displayOption) |
|
451 |
+ else: |
|
452 |
+ print "No spec file builds a package named",inputValue |
|
453 |
+ return |
|
454 |
+ |
|
455 |
+ # Generate dependencies for all packages in the given JSON input file |
|
456 |
+ elif (inputType == "json"): |
|
457 |
+ filePath = self.inputDataDir +"/"+ inputValue |
|
458 |
+ data = self.get_all_package_names(filePath) |
|
459 |
+ for pkg in data: |
|
460 |
+ if False == allDeps.has_key(pkg): |
|
461 |
+ spName = self.getSpecName(pkg) |
|
462 |
+ if(spName != None): |
|
463 |
+ allDeps[pkg] = 0 |
|
464 |
+ parent[pkg] = "" |
|
465 |
+ depQue.put(pkg) |
|
466 |
+ self.findTotalRequires(allDeps, depQue, parent, displayOption) |
|
467 |
+ else: |
|
468 |
+ independentRPMS.append(pkg); |
|
469 |
+ |
|
470 |
+ #Generating the list of packages that requires the given input package at install time |
|
471 |
+ elif (inputType == "who-needs"): |
|
472 |
+ print whoNeedsList |
|
473 |
+ return |
|
474 |
+ |
|
475 |
+ #Generating the list of packages that the modified package will affect at build time |
|
476 |
+ elif (inputType == "who-needs-build"): |
|
477 |
+ if (packageFound == True): |
|
478 |
+ self.findTotalWhoNeedsToBuild(depQue, whoBuildDeps, whoBuildDepSet, displayOption) |
|
479 |
+ print whoBuildDepSet |
|
480 |
+ else: |
|
481 |
+ print "No spec file builds a package named", inputValue |
|
482 |
+ return |
|
483 |
+ |
|
484 |
+ # construct the sorted list of all packages (sorted by dependency) |
|
485 |
+ sortedList = [] |
|
486 |
+ for elem in sorted(allDeps.items(), key=operator.itemgetter(1), reverse=True): |
|
487 |
+ sortedList.append(elem[0]) |
|
488 |
+ sortedList.extend(independentRPMS) |
|
489 |
+ |
|
490 |
+ # construct all children nodes |
|
491 |
+ if (displayOption == "tree"): |
|
492 |
+ for k, v in parent.iteritems(): |
|
493 |
+ children.setdefault(v, []).append(k) |
|
494 |
+ if(inputType == "json"): |
|
495 |
+ print "Dependency Mappings for", inputValue, ":", "\n----------------------------------------------------",children |
|
496 |
+ print "----------------------------------------------------" |
|
497 |
+ if (children.has_key("")): |
|
498 |
+ for child in children[""]: |
|
499 |
+ print child |
|
500 |
+ self.printTree(allDeps, children, child, 1) |
|
501 |
+ for pkg in independentRPMS: |
|
502 |
+ print pkg |
|
503 |
+ print "******************",len(sortedList), "packages in total ******************" |
|
504 |
+ else: |
|
505 |
+ if (inputType == "pkg" and len(children) > 0): |
|
506 |
+ print "cyclic dependency detected, mappings: \n",children |
|
507 |
+ |
|
508 |
+ # To display a flat list of all packages |
|
509 |
+ elif(displayOption == "list"): |
|
510 |
+ print sortedList |
|
511 |
+ |
|
512 |
+ # To generate a new JSON file based on given input json file |
|
513 |
+ elif(displayOption == "json" and inputType == "json"): |
|
514 |
+ d = {} |
|
515 |
+ d['packages'] = sortedList |
|
516 |
+ outFilePath = self.jsonFilesOutPath + inputValue |
|
517 |
+ with open(outFilePath, 'wb') as outfile: |
|
518 |
+ json.dump(d, outfile) |
|
519 |
+ return sortedList |
|
520 |
+ |
|
521 |
+ def getListSpecFiles(self,listSpecFiles,path): |
|
522 |
+ for dirEntry in os.listdir(path): |
|
523 |
+ dirEntryPath = os.path.join(path, dirEntry) |
|
524 |
+ if os.path.isfile(dirEntryPath) and dirEntryPath.endswith(".spec"): |
|
525 |
+ listSpecFiles.append(dirEntryPath) |
|
526 |
+ elif os.path.isdir(dirEntryPath): |
|
527 |
+ self.getListSpecFiles(listSpecFiles,dirEntryPath) |
|
528 |
+ |
|
529 |
+ def getBuildRequiresForPackage(self, package): |
|
530 |
+ specName=self.getSpecName(package) |
|
531 |
+ return self.mapSerializableSpecObjects[specName].buildRequirePackages |
|
532 |
+ |
|
533 |
+ def getRequiresForPackage(self, package): |
|
534 |
+ specName=self.getSpecName(package) |
|
535 |
+ if self.mapSerializableSpecObjects[specName].installRequiresPackages.has_key(package): |
|
536 |
+ return self.mapSerializableSpecObjects[specName].installRequiresPackages[package] |
|
537 |
+ return None |
|
538 |
+ |
|
539 |
+ def getRelease(self, package): |
|
540 |
+ specName=self.getSpecName(package) |
|
541 |
+ return self.mapSerializableSpecObjects[specName].release |
|
542 |
+ |
|
543 |
+ def getVersion(self, package): |
|
544 |
+ specName=self.getSpecName(package) |
|
545 |
+ return self.mapSerializableSpecObjects[specName].version |
|
546 |
+ |
|
547 |
+ def getSpecFile(self, package): |
|
548 |
+ specName=self.getSpecName(package) |
|
549 |
+ return self.mapSerializableSpecObjects[specName].specFile |
|
550 |
+ |
|
551 |
+ def getPatches(self, package): |
|
552 |
+ specName=self.getSpecName(package) |
|
553 |
+ return self.mapSerializableSpecObjects[specName].listPatches |
|
554 |
+ |
|
555 |
+ def getSources(self, package): |
|
556 |
+ specName=self.getSpecName(package) |
|
557 |
+ return self.mapSerializableSpecObjects[specName].listSources |
|
558 |
+ |
|
559 |
+ def getPackages(self, package): |
|
560 |
+ specName=self.getSpecName(package) |
|
561 |
+ return self.mapSerializableSpecObjects[specName].listPackages |
|
562 |
+ |
|
563 |
+ def getSpecName(self,package): |
|
564 |
+ if self.mapPackageToSpec.has_key(package): |
|
565 |
+ specName=self.mapPackageToSpec[package] |
|
566 |
+ if self.mapSerializableSpecObjects.has_key(specName): |
|
567 |
+ return specName |
|
568 |
+ else: |
|
569 |
+ print "SpecDeps: Could not able to find " + package + " package from specs" |
|
570 |
+ raise Exception("Invalid package:" + package) |
|
571 |
+ else: |
|
572 |
+ return None |
|
573 |
+ |
|
574 |
+ def isRPMPackage(self,package): |
|
575 |
+ if self.mapPackageToSpec.has_key(package): |
|
576 |
+ specName=self.mapPackageToSpec[package] |
|
577 |
+ if self.mapSerializableSpecObjects.has_key(specName): |
|
578 |
+ return True |
|
579 |
+ return False |
|
580 |
+ |
|
581 |
+ def getSecurityHardeningOption(self, package): |
|
582 |
+ specName=self.getSpecName(package) |
|
583 |
+ return self.mapSerializableSpecObjects[specName].securityHardening |
|
584 |
+ |
|
585 |
+ def getSpecDetails(self, name): |
|
586 |
+ print self.mapSerializableSpecObjects[name].installRequiresAllPackages |
|
587 |
+ |
269 | 588 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,57 @@ |
0 |
+#! /usr/bin/python2 |
|
1 |
+# |
|
2 |
+# Copyright (C) 2015 vmware inc. |
|
3 |
+# |
|
4 |
+# Author: Harish Udaiya Kumar <hudaiyakumar@vmware.com> |
|
5 |
+from SpecUtils import Specutils |
|
6 |
+from SpecData import SerializableSpecObject |
|
7 |
+from SpecData import SerializedSpecObjects |
|
8 |
+import sys |
|
9 |
+import os |
|
10 |
+from optparse import OptionParser |
|
11 |
+from jsonwrapper import JsonWrapper |
|
12 |
+ |
|
13 |
+DEFAULT_INPUT_TYPE = "pkg" |
|
14 |
+DEFAULT_DISPLAY_OPTION = "tree" |
|
15 |
+SPEC_FILE_DIR = "../../SPECS" |
|
16 |
+LOG_FILE_DIR = "../../stage/LOGS" |
|
17 |
+ |
|
18 |
+ |
|
19 |
+def main(): |
|
20 |
+ usage = os.path.basename(__file__) + "--input-type=[json/pkg/who-needs/who-needs-build] --pkg=[pkg_name] --file=<JSON_FILE_NAME> --disp=[tree/list/json]" |
|
21 |
+ parser = OptionParser(usage) |
|
22 |
+ parser.add_option("-i", "--input-type", dest="input_type", default=DEFAULT_INPUT_TYPE) |
|
23 |
+ parser.add_option("-p", "--pkg", dest="pkg") |
|
24 |
+ parser.add_option("-f", "--file", dest="json_file", default="packages_minimal.json") |
|
25 |
+ parser.add_option("-d", "--disp", dest="display_option", default=DEFAULT_DISPLAY_OPTION) |
|
26 |
+ parser.add_option("-s", "--spec-dir", dest="spec_dir", default=SPEC_FILE_DIR) |
|
27 |
+ parser.add_option("-t", "--stage-dir", dest="stage_dir", default="../../stage") |
|
28 |
+ parser.add_option("-a", "--input-data-dir", dest="input_data_dir", default="../../common/data/") |
|
29 |
+ (options, args) = parser.parse_args() |
|
30 |
+ |
|
31 |
+ if(False == options.input_data_dir.endswith('/')): |
|
32 |
+ options.input_data_dir += '/' |
|
33 |
+ |
|
34 |
+ specDeps = SerializedSpecObjects(options.input_data_dir, options.stage_dir) |
|
35 |
+ displayOption = options.display_option |
|
36 |
+ abs_path = os.path.abspath(__file__) |
|
37 |
+ dir_name = os.path.dirname(abs_path) |
|
38 |
+ os.chdir(dir_name) |
|
39 |
+ |
|
40 |
+ # To display/print package dependencies on console |
|
41 |
+ if(options.input_type == "pkg" or options.input_type == "who-needs" or options.input_type == "who-needs-build"): |
|
42 |
+ targetName = options.pkg |
|
43 |
+ specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, targetName, displayOption) |
|
44 |
+ elif(options.input_type == "json"):# Generate the expanded package dependencies json file based on package_list_file |
|
45 |
+ json_wrapper_option_list = JsonWrapper(options.json_file) |
|
46 |
+ option_list_json = json_wrapper_option_list.read() |
|
47 |
+ options_sorted = option_list_json.items() |
|
48 |
+ for install_option in options_sorted: |
|
49 |
+ if displayOption == "tree" and install_option[1]["title"] == "ISO Packages": |
|
50 |
+ continue |
|
51 |
+ specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, install_option[1]["file"], displayOption) |
|
52 |
+ |
|
53 |
+ sys.exit(0) |
|
54 |
+ |
|
55 |
+if __name__=="__main__": |
|
56 |
+ main() |
... | ... |
@@ -1,6 +1,7 @@ |
1 | 1 |
import re |
2 | 2 |
from StringUtils import StringUtils |
3 | 3 |
from SpecStructures import * |
4 |
+from constants import constants |
|
4 | 5 |
|
5 | 6 |
class SpecParser(object): |
6 | 7 |
def __init__(self): |
... | ... |
@@ -185,6 +186,8 @@ class SpecParser(object): |
185 | 185 |
return True |
186 | 186 |
elif re.search('^'+'requires:',line,flags=re.IGNORECASE) : |
187 | 187 |
return True |
188 |
+ elif re.search('^'+'requires\((pre|post|preun|postun)\):',line,flags=re.IGNORECASE) : |
|
189 |
+ return True |
|
188 | 190 |
elif re.search('^'+'provides:',line,flags=re.IGNORECASE) : |
189 | 191 |
return True |
190 | 192 |
elif re.search('^'+'obsoletes:',line,flags=re.IGNORECASE) : |
... | ... |
@@ -245,16 +248,21 @@ class SpecParser(object): |
245 | 245 |
listPackages=line.split(",") |
246 | 246 |
listdependentpkgs=[] |
247 | 247 |
for line in listPackages: |
248 |
- line=strUtils.getStringInBrackets(line) |
|
248 |
+ line=strUtils.getStringInConditionalBrackets(line) |
|
249 | 249 |
listContents=line.split() |
250 | 250 |
totalContents = len(listContents) |
251 | 251 |
i=0 |
252 | 252 |
while i < totalContents: |
253 | 253 |
dpkg = dependentPackageData() |
254 | 254 |
compare=None |
255 |
+ packageName=listContents[i] |
|
255 | 256 |
if listContents[i].startswith("/"): |
257 |
+ provider=constants.providedBy.get(listContents[i], None) |
|
256 | 258 |
i=i+1 |
257 |
- continue |
|
259 |
+ if provider is not None: |
|
260 |
+ packageName=provider |
|
261 |
+ else: |
|
262 |
+ continue |
|
258 | 263 |
if i+2 < len(listContents): |
259 | 264 |
if listContents[i+1] == ">=": |
260 | 265 |
compare="gte" |
... | ... |
@@ -270,12 +278,12 @@ class SpecParser(object): |
270 | 270 |
compare="eq" |
271 | 271 |
|
272 | 272 |
if compare is not None: |
273 |
- dpkg.package=listContents[i] |
|
273 |
+ dpkg.package=packageName |
|
274 | 274 |
dpkg.compare=compare |
275 | 275 |
dpkg.version=listContents[i+2] |
276 | 276 |
i=i+3 |
277 | 277 |
else: |
278 |
- dpkg.package=listContents[i] |
|
278 |
+ dpkg.package=packageName |
|
279 | 279 |
i=i+1 |
280 | 280 |
listdependentpkgs.append(dpkg) |
281 | 281 |
return listdependentpkgs |
... | ... |
@@ -319,11 +327,11 @@ class SpecParser(object): |
319 | 319 |
if headerName.find('patch') != -1: |
320 | 320 |
pkg.patches.append(headerContent) |
321 | 321 |
return True |
322 |
- if headerName == 'requires' or headerName == 'provides' or headerName == 'obsoletes' or headerName == 'conflicts' or headerName == 'buildrequires' or headerName == 'buildprovides': |
|
322 |
+ if headerName.startswith('requires') or headerName == 'provides' or headerName == 'obsoletes' or headerName == 'conflicts' or headerName == 'buildrequires' or headerName == 'buildprovides': |
|
323 | 323 |
dpkg=self.readDependentPackageData(headerContent) |
324 | 324 |
if dpkg is None: |
325 | 325 |
return False |
326 |
- if headerName == 'requires': |
|
326 |
+ if headerName.startswith('requires'): |
|
327 | 327 |
pkg.requires.extend(dpkg) |
328 | 328 |
if headerName == 'provides': |
329 | 329 |
pkg.provides.extend(dpkg) |
330 | 330 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,73 @@ |
0 |
+#!/usr/bin/python2 |
|
1 |
+# |
|
2 |
+#Copyright (C) 2015 vmware inc. |
|
3 |
+# |
|
4 |
+#Author: Harish Udaiya Kumar <hudaiyakumar@vmware.com> |
|
5 |
+from SpecUtils import Specutils |
|
6 |
+from SpecData import SerializableSpecObject |
|
7 |
+from SpecData import SerializedSpecObjects |
|
8 |
+from RepoDeps import RepoQueryDependency |
|
9 |
+import sys |
|
10 |
+import os |
|
11 |
+from optparse import OptionParser |
|
12 |
+ |
|
13 |
+DEFAULT_INPUT_TYPE = "json" |
|
14 |
+DEFAULT_DISPLAY_OPTION = "tree" |
|
15 |
+SPEC_FILE_DIR = "../../SPECS" |
|
16 |
+INPUT_DATA_DIR = "../../common/data" |
|
17 |
+ |
|
18 |
+def reportMissing(pkg,specDepList, repoDepList, excludeList): |
|
19 |
+ missingList = []; |
|
20 |
+ if None != repoDepList: |
|
21 |
+ for repoItem in repoDepList: |
|
22 |
+ if repoItem not in excludeList and (None == specDepList or repoItem not in specDepList): |
|
23 |
+ missingList.append(repoItem) |
|
24 |
+ if missingList: |
|
25 |
+ if len(pkg) <= 7: |
|
26 |
+ print pkg, "missing\t\t->", missingList |
|
27 |
+ else: |
|
28 |
+ print pkg, "missing\t->", missingList |
|
29 |
+ |
|
30 |
+def main(): |
|
31 |
+ usage = os.path.basename(__file__) + "--input-type=[json/pkg] --pkg=[pkg_name] --file=<JSON_FILE_NAME> --repo-file=<photon>.repo" |
|
32 |
+ parser = OptionParser(usage) |
|
33 |
+ parser.add_option("-i", "--input-type", dest="input_type", default=DEFAULT_INPUT_TYPE) |
|
34 |
+ parser.add_option("-p", "--pkg", dest="pkg") |
|
35 |
+ parser.add_option("-f", "--file", dest="json_file", default="packages_full.json") |
|
36 |
+ parser.add_option("-s", "--spec-dir", dest="spec_dir", default=SPEC_FILE_DIR) |
|
37 |
+ parser.add_option("-a", "--input-data-dir", dest="input_data_dir", default=INPUT_DATA_DIR) |
|
38 |
+ parser.add_option("-r", "--repo-file", dest = "repo_file", default="") |
|
39 |
+ excludeList = ["bash","glibc","libgcc","pkg-config","filesystem"] |
|
40 |
+ (options, args) = parser.parse_args() |
|
41 |
+ |
|
42 |
+ if(options.repo_file == ""): |
|
43 |
+ print "Error! repo file not provided" |
|
44 |
+ print usage |
|
45 |
+ return |
|
46 |
+ |
|
47 |
+ if(False == options.input_data_dir.endswith('/')): |
|
48 |
+ options.input_data_dir += '/' |
|
49 |
+ |
|
50 |
+ specDeps = SerializedSpecObjects(options.input_data_dir, "") |
|
51 |
+ repoDeps = RepoQueryDependency(options.repo_file) |
|
52 |
+ displayOption = None |
|
53 |
+ abs_path = os.path.abspath(__file__) |
|
54 |
+ dir_name = os.path.dirname(abs_path) |
|
55 |
+ os.chdir(dir_name) |
|
56 |
+ |
|
57 |
+ if(options.input_type == "pkg"): |
|
58 |
+ targetName = options.pkg |
|
59 |
+ specDepList = specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, targetName, displayOption) |
|
60 |
+ repoDepList = repoDeps.getRequiresList(targetName) |
|
61 |
+ reportMissing(targetName,specDepList,repoDepList,excludeList) |
|
62 |
+ elif(options.input_type == "json"): |
|
63 |
+ filePath = options.input_data_dir + options.json_file |
|
64 |
+ data = specDeps.get_all_package_names(filePath) |
|
65 |
+ for pkg in data: |
|
66 |
+ specDepList = specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, "pkg" , pkg, displayOption) |
|
67 |
+ repoDepList = repoDeps.getRequiresList(pkg) |
|
68 |
+ reportMissing(pkg,specDepList,repoDepList,excludeList) |
|
69 |
+ sys.exit(0) |
|
70 |
+ |
|
71 |
+if __name__=="__main__": |
|
72 |
+ main() |
... | ... |
@@ -2,12 +2,17 @@ import re |
2 | 2 |
|
3 | 3 |
class StringUtils(object): |
4 | 4 |
|
5 |
- def getStringInBrackets(self, inputstring): |
|
5 |
+ # Opens conditional brackets from |
|
6 |
+ # (aaa <= 3.1 or bbb) ccc (ddd or fff > 4.5.6) |
|
7 |
+ # into |
|
8 |
+ # aaa <= 3.1 ccc ddd |
|
9 |
+ def getStringInConditionalBrackets(self,inputstring): |
|
6 | 10 |
inputstring=inputstring.strip() |
7 |
- m = re.search(r"^\(([A-Za-z0-9_.-]+)\)", inputstring) |
|
8 |
- if m is None: |
|
9 |
- return inputstring |
|
10 |
- return m.group(1) |
|
11 |
+ items = re.findall(r"([(][A-Za-z0-9 _\.\-<>=]+[)])", inputstring) |
|
12 |
+ for m in items: |
|
13 |
+ out = m[m.find("(")+1 : m.find(" or ")].strip() |
|
14 |
+ inputstring = inputstring.replace(m, out); |
|
15 |
+ return inputstring |
|
11 | 16 |
|
12 | 17 |
def getFileNameFromURL(self,inputstring): |
13 | 18 |
index=inputstring.rfind("/") |
... | ... |
@@ -8,6 +8,7 @@ from constants import constants |
8 | 8 |
from PackageManager import PackageManager |
9 | 9 |
import json |
10 | 10 |
import sys |
11 |
+from SpecData import SPECS |
|
11 | 12 |
from SpecUtils import Specutils |
12 | 13 |
from StringUtils import StringUtils |
13 | 14 |
import collections |
... | ... |
@@ -135,6 +136,8 @@ def main(): |
135 | 135 |
|
136 | 136 |
try: |
137 | 137 |
constants.initialize(options) |
138 |
+ # parse SPECS folder |
|
139 |
+ SPECS(); |
|
138 | 140 |
if package == "packages_list": |
139 | 141 |
buildPackagesList(options.buildRootPath+"/../packages_list.csv") |
140 | 142 |
elif options.generatePkgYamlFiles: |
... | ... |
@@ -162,15 +165,15 @@ def main(): |
162 | 162 |
def buildPackagesList(csvFilename): |
163 | 163 |
csvFile = open(csvFilename, "w") |
164 | 164 |
csvFile.write("Package,Version,License,URL,Sources,Patches\n") |
165 |
- listPackages = constants.specData.getListPackages() |
|
165 |
+ listPackages = SPECS.getData().getListPackages() |
|
166 | 166 |
listPackages.sort() |
167 | 167 |
for package in listPackages: |
168 | 168 |
name = package |
169 |
- version = constants.specData.getVersion(package) |
|
170 |
- license = constants.specData.getLicense(package) |
|
171 |
- listPatches = constants.specData.getPatches(package) |
|
172 |
- url = constants.specData.getURL(package) |
|
173 |
- listSourceNames = constants.specData.getSources(package) |
|
169 |
+ version = SPECS.getData().getVersion(package) |
|
170 |
+ license = SPECS.getData().getLicense(package) |
|
171 |
+ listPatches = SPECS.getData().getPatches(package) |
|
172 |
+ url = SPECS.getData().getURL(package) |
|
173 |
+ listSourceNames = SPECS.getData().getSources(package) |
|
174 | 174 |
sources = "" |
175 | 175 |
patches = "" |
176 | 176 |
if listPatches is not None: |
... | ... |
@@ -196,27 +199,27 @@ def buildSourcesList(yamlDir, blackListPkgs, logger, singleFile=True): |
196 | 196 |
cmdUtils.runCommandInShell("mkdir -p "+yamlSourceDir) |
197 | 197 |
if singleFile: |
198 | 198 |
yamlFile = open(yamlSourceDir+"/sources_list.yaml", "w") |
199 |
- listPackages = constants.specData.getListPackages() |
|
199 |
+ listPackages = SPECS.getData().getListPackages() |
|
200 | 200 |
listPackages.sort() |
201 | 201 |
import PullSources |
202 | 202 |
for package in listPackages: |
203 | 203 |
if package in blackListPkgs: |
204 | 204 |
continue |
205 | 205 |
ossname = package |
206 |
- ossversion = constants.specData.getVersion(package) |
|
206 |
+ ossversion = SPECS.getData().getVersion(package) |
|
207 | 207 |
modified = False |
208 |
- listPatches = constants.specData.getPatches(package) |
|
208 |
+ listPatches = SPECS.getData().getPatches(package) |
|
209 | 209 |
if listPatches is not None and len(listPatches) > 0 : |
210 | 210 |
modified = True |
211 |
- url = constants.specData.getSourceURL(package) |
|
211 |
+ url = SPECS.getData().getSourceURL(package) |
|
212 | 212 |
if url is None: |
213 |
- url = constants.specData.getURL(package) |
|
213 |
+ url = SPECS.getData().getURL(package) |
|
214 | 214 |
|
215 | 215 |
sourceName = None |
216 |
- listSourceNames = constants.specData.getSources(package) |
|
216 |
+ listSourceNames = SPECS.getData().getSources(package) |
|
217 | 217 |
if len(listSourceNames) >0: |
218 | 218 |
sourceName=listSourceNames[0] |
219 |
- sha1 = constants.specData.getSHA1(package, sourceName) |
|
219 |
+ sha1 = SPECS.getData().getSHA1(package, sourceName) |
|
220 | 220 |
if sha1 is not None: |
221 | 221 |
PullSources.get(sourceName, sha1, yamlSourceDir, constants.pullsourcesConfig, logger) |
222 | 222 |
|
... | ... |
@@ -247,14 +250,14 @@ def buildSRPMList(srpmPath, yamlDir, blackListPkgs, logger, singleFile=True): |
247 | 247 |
cmdUtils.runCommandInShell("mkdir -p "+yamlSrpmDir) |
248 | 248 |
if singleFile: |
249 | 249 |
yamlFile = open(yamlSrpmDir+"/srpm_list.yaml", "w") |
250 |
- listPackages = constants.specData.getListPackages() |
|
250 |
+ listPackages = SPECS.getData().getListPackages() |
|
251 | 251 |
listPackages.sort() |
252 | 252 |
for package in listPackages: |
253 | 253 |
if package in blackListPkgs: |
254 | 254 |
continue |
255 | 255 |
ossname = package |
256 |
- ossversion = constants.specData.getVersion(package) |
|
257 |
- ossrelease = constants.specData.getRelease(package) |
|
256 |
+ ossversion = SPECS.getData().getVersion(package) |
|
257 |
+ ossrelease = SPECS.getData().getRelease(package) |
|
258 | 258 |
|
259 | 259 |
listFoundSRPMFiles = cmdUtils.findFile(ossname+"-"+ossversion+"-"+ossrelease+".src.rpm",srpmPath) |
260 | 260 |
srpmName = None |
... | ... |
@@ -295,7 +298,7 @@ def buildAPackage(package, listBuildOptionPackages, pkgBuildOptionFile, buildThr |
295 | 295 |
pkgManager.buildPackages(listPackages, listBuildOptionPackages, pkgBuildOptionFile, buildThreads, pkgBuildType) |
296 | 296 |
|
297 | 297 |
def buildPackagesForAllSpecs(listBuildOptionPackages, pkgBuildOptionFile, logger, buildThreads, pkgInfoJsonFile, pkgBuildType): |
298 |
- listPackages = constants.specData.getListPackages() |
|
298 |
+ listPackages = SPECS.getData().getListPackages() |
|
299 | 299 |
|
300 | 300 |
logger.info("List of packages to build:") |
301 | 301 |
logger.info(listPackages) |
... | ... |
@@ -1,4 +1,3 @@ |
1 |
-from SpecData import SerializableSpecObjectsUtils |
|
2 | 1 |
from Logger import Logger |
3 | 2 |
|
4 | 3 |
class constants(object): |
... | ... |
@@ -10,7 +9,6 @@ class constants(object): |
10 | 10 |
buildNumber="0000000" |
11 | 11 |
releaseVersion="NNNnNNN" |
12 | 12 |
topDirPath="" |
13 |
- specData=None |
|
14 | 13 |
buildRootPath="/mnt" |
15 | 14 |
prevPublishRPMRepo="" |
16 | 15 |
prevPublishXRPMRepo="" |
... | ... |
@@ -335,6 +333,15 @@ class constants(object): |
335 | 335 |
"gdb", |
336 | 336 |
"glibc" ] |
337 | 337 |
|
338 |
+ # .spec file might contain lines such as |
|
339 |
+ # Requires(post):/sbin/useradd |
|
340 |
+ # Build system should interpret it as |
|
341 |
+ # Requires: shadow |
|
342 |
+ providedBy={ |
|
343 |
+ "/sbin/useradd":"shadow", |
|
344 |
+ "/sbin/groupadd":"shadow" |
|
345 |
+ } |
|
346 |
+ |
|
338 | 347 |
@staticmethod |
339 | 348 |
def initialize(options): |
340 | 349 |
constants.dist = options.dist |
... | ... |
@@ -349,8 +356,6 @@ class constants(object): |
349 | 349 |
constants.prevPublishRPMRepo = options.publishRPMSPath |
350 | 350 |
constants.prevPublishXRPMRepo = options.publishXRPMSPath |
351 | 351 |
constants.buildRootPath=options.buildRootPath |
352 |
- constants.specData = SerializableSpecObjectsUtils(constants.logPath) |
|
353 |
- constants.specData.readSpecsAndConvertToSerializableObjects(constants.specPath) |
|
354 | 352 |
constants.pullsourcesConfig = options.pullsourcesConfig |
355 | 353 |
constants.inputRPMSPath=options.inputRPMSPath |
356 | 354 |
constants.testForceRPMS=[] |
... | ... |
@@ -361,44 +366,4 @@ class constants(object): |
361 | 361 |
constants.tmpDirPath = "/dev/shm" |
362 | 362 |
if constants.rpmCheck: |
363 | 363 |
constants.testLogger=Logger.getLogger("MakeCheckTest",constants.logPath) |
364 |
- constants.updateRPMMacros() |
|
365 |
- |
|
366 |
- @staticmethod |
|
367 |
- def updateRPMMacros(): |
|
368 |
- #adding distribution rpm macro |
|
369 |
- constants.specData.addMacro("dist",constants.dist) |
|
370 |
- |
|
371 |
- #adding buildnumber rpm macro |
|
372 |
- constants.specData.addMacro("photon_build_number",constants.buildNumber) |
|
373 |
- |
|
374 |
- #adding releasenumber rpm macro |
|
375 |
- constants.specData.addMacro("photon_release_version",constants.releaseVersion) |
|
376 |
- |
|
377 |
- #adding kernelversion rpm macro |
|
378 |
- kernelversion = constants.specData.getVersion("linux") |
|
379 |
- constants.specData.addMacro("KERNEL_VERSION",kernelversion) |
|
380 | 364 |
|
381 |
- #adding openjre8 version rpm macro |
|
382 |
- java8version = constants.specData.getVersion("openjre8") |
|
383 |
- constants.specData.addMacro("JAVA8_VERSION",java8version) |
|
384 |
- |
|
385 |
- #adding kernelrelease rpm macro |
|
386 |
- kernelrelease = constants.specData.getRelease("linux") |
|
387 |
- constants.specData.addMacro("KERNEL_RELEASE",kernelrelease) |
|
388 |
- |
|
389 |
- #adding kernelsubrelease rpm macro |
|
390 |
- a,b,c = kernelversion.split(".") |
|
391 |
- kernelsubrelease = '%02d%02d%03d%03d' % (int(a),int(b),int(c),int(kernelrelease.replace(constants.dist,""))) |
|
392 |
- if kernelsubrelease: |
|
393 |
- kernelsubrelease = "."+kernelsubrelease |
|
394 |
- constants.specData.addMacro("kernelsubrelease",kernelsubrelease) |
|
395 |
- |
|
396 |
- #adding check rpm macro |
|
397 |
- if constants.rpmCheck: |
|
398 |
- constants.specData.addMacro("with_check","1") |
|
399 |
- else: |
|
400 |
- constants.specData.addMacro("with_check","0") |
|
401 |
- |
|
402 |
- @staticmethod |
|
403 |
- def setTestForceRPMS(listsPackages): |
|
404 |
- constants.testForceRPMS=listsPackages |
405 | 365 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,25 @@ |
0 |
+#!/usr/bin/python2 |
|
1 |
+# |
|
2 |
+# Copyright (C) 2015 vmware inc. |
|
3 |
+# |
|
4 |
+# Author: Sharath George <sharathg@vmware.com> |
|
5 |
+ |
|
6 |
+ |
|
7 |
+import json |
|
8 |
+import collections |
|
9 |
+ |
|
10 |
+class JsonWrapper(object): |
|
11 |
+ |
|
12 |
+ def __init__(self, filename): |
|
13 |
+ self.filename = filename |
|
14 |
+ |
|
15 |
+ def read(self): |
|
16 |
+ json_data = open(self.filename) |
|
17 |
+ self.data = json.load(json_data, object_pairs_hook=collections.OrderedDict) |
|
18 |
+ json_data.close() |
|
19 |
+ return self.data |
|
20 |
+ |
|
21 |
+ def write(self, data): |
|
22 |
+ self.data = data |
|
23 |
+ outfile = open(self.filename, 'wb') |
|
24 |
+ json.dump(data, outfile) |