Browse code

Updated spec dependency generation to also include lightwave RPMS

Harish Udaiya Kumar authored on 2015/09/11 04:02:55
Showing 4 changed files
... ...
@@ -146,10 +146,14 @@ iso: check $(PHOTON_STAGE) $(PHOTON_PACKAGES) ostree-repo
146 146
                 -f > \
147 147
                 $(PHOTON_LOGS_DIR)/installer.log 2>&1
148 148
 
149
-deptree:
149
+pkgtree:
150 150
 	@cd $(PHOTON_SPECDEPS_DIR) && \
151 151
 		$(PHOTON_SPECDEPS) -s $(PHOTON_SPECS_DIR) -i pkg -p $(pkg)
152 152
 
153
+jsontree:
154
+	@cd $(PHOTON_SPECDEPS_DIR) && \
155
+		$(PHOTON_SPECDEPS) -s $(PHOTON_SPECS_DIR) -i json -f $(PHOTON_DATA_DIR)/build_install_options_$(json).json
156
+
153 157
 who-needs:
154 158
 	@cd $(PHOTON_SPECDEPS_DIR) && \
155 159
 		$(PHOTON_SPECDEPS) -s $(PHOTON_SPECS_DIR) -i who-needs -p $(pkg) 
... ...
@@ -169,12 +173,12 @@ packages: check $(PHOTON_STAGE) $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES) $(CONTA
169 169
 		-d $(PHOTON_DIST_TAG) \
170 170
                 -t ${THREADS}
171 171
 
172
-build-updated-packages: check $(PHOTON_STAGE) $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES) $(CONTAIN) generate-dep-lists
172
+updated-packages: check $(PHOTON_STAGE) $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES) $(CONTAIN) generate-dep-lists
173 173
 	@echo "Building only updated RPMS..."
174 174
 	@cd $(PHOTON_PKG_BUILDER_DIR) && \
175 175
         $(PHOTON_PACKAGE_BUILDER) -o full \
176 176
                 -s $(PHOTON_SPECS_DIR) \
177
-                -r $(PHOTON_RPMS_DIR) \
177
+                -r $(PHOTON_UPDATED_RPMS_DIR) \
178 178
                 -x $(PHOTON_SRCS_DIR) \
179 179
                 -b $(PHOTON_CHROOT_PATH) \
180 180
                 -l $(PHOTON_LOGS_DIR) \
... ...
@@ -252,6 +256,9 @@ $(PHOTON_STAGE):
252 252
 	@echo "Building RPMS folders..."
253 253
 	@test -d $(PHOTON_RPMS_DIR_NOARCH) || $(MKDIR) -p $(PHOTON_RPMS_DIR_NOARCH)
254 254
 	@test -d $(PHOTON_RPMS_DIR_X86_64) || $(MKDIR) -p $(PHOTON_RPMS_DIR_X86_64)
255
+	@echo "Building UPDATED_RPMS folders..."
256
+	@test -d $(PHOTON_UPDATED_RPMS_DIR_NOARCH) || $(MKDIR) -p $(PHOTON_UPDATED_RPMS_DIR_NOARCH)
257
+	@test -d $(PHOTON_UPDATED_RPMS_DIR_X86_64) || $(MKDIR) -p $(PHOTON_UPDATED_RPMS_DIR_X86_64)
255 258
 	@echo "Building SOURCES folder..."
256 259
 	@test -d $(PHOTON_SRCS_DIR) || $(MKDIR) -p $(PHOTON_SRCS_DIR)
257 260
 	@echo "Building LOGS folder..."
... ...
@@ -22,55 +22,55 @@ class SerializableSpecObject(object):
22 22
 
23 23
 class SerializedSpecObjects(object):
24 24
     
25
-    def __init__(self, inputDataDir, stageDir):
26
-        self.mapSerializableSpecObjects={}
27
-        self.mapPackageToSpec={}
28
-	self.jsonFilesOutPath = stageDir + "/common/data/"
29
-	self.inputDataDir = inputDataDir
25
+	def __init__(self, inputDataDir, stageDir):
26
+		self.mapSerializableSpecObjects={}
27
+		self.mapPackageToSpec={}
28
+		self.jsonFilesOutPath = stageDir + "/common/data/"
29
+		self.inputDataDir = inputDataDir
30 30
 	
31
-    def findTotalRequires(self, allDeps, depQue, parent, displayOption):
32
-        
33
-        while not depQue.empty():
34
-		specPkg = depQue.get()
35
-                specName = self.getSpecName(specPkg) 
36
-		specObj = self.mapSerializableSpecObjects[specName]
37
-		for depPkg in specObj.installRequiresPackages[specPkg]:
38
-			if True == allDeps.has_key(depPkg): 
39
-				if(allDeps[depPkg] < allDeps[specPkg] + 1): 
31
+	def findTotalRequires(self, allDeps, depQue, parent, displayOption):
32
+		while not depQue.empty():
33
+			specPkg = depQue.get()
34
+			specName = self.getSpecName(specPkg)
35
+			specObj = self.mapSerializableSpecObjects[specName]
36
+			for depPkg in specObj.installRequiresPackages[specPkg]:
37
+				if True == allDeps.has_key(depPkg): 
38
+					if(allDeps[depPkg] < allDeps[specPkg] + 1): 
39
+						allDeps[depPkg] = allDeps[specPkg] + 1
40
+						parent[depPkg] = specPkg
41
+						self.updateLevels(allDeps, depPkg, parent, allDeps[depPkg])
42
+				else:
40 43
 					allDeps[depPkg] = allDeps[specPkg] + 1
41 44
 					parent[depPkg] = specPkg
42
-					self.updateLevels(allDeps, depPkg, parent, allDeps[depPkg])
43
-			else:
44
-				allDeps[depPkg] = allDeps[specPkg] + 1
45
-				parent[depPkg] = specPkg
46
-				depQue.put(depPkg)
45
+					depQue.put(depPkg)
47 46
 	
48
-    def printTree(self, allDeps, children, curParent , depth):    
47
+	def printTree(self, allDeps, children, curParent , depth):    
49 48
 		if (children.has_key(curParent)):
50 49
 			for child in children[curParent]:
51 50
 				print "\t" * depth, child
52 51
 				self.printTree(allDeps, children, child, depth+1)
53 52
 	
54
-    def get_all_package_names(self, jsonFilePath):
55
-    	base_path = os.path.dirname(jsonFilePath)
56
-    	jsonData = open(jsonFilePath)
57
-    	option_list_json = json.load(jsonData)
58
-    	jsonData.close()
59
-    	packages = option_list_json["packages"]
60
-    	return packages
53
+	def get_all_package_names(self, jsonFilePath):
54
+		base_path = os.path.dirname(jsonFilePath)
55
+		jsonData = open(jsonFilePath)
56
+		option_list_json = json.load(jsonData)
57
+		jsonData.close()
58
+		packages = option_list_json["packages"]
59
+		return packages
61 60
 
62
-    def updateLevels(self, allDeps, inPkg, parent, level):
63
-        specName = self.getSpecName(inPkg) 
64
-        specObj  = self.mapSerializableSpecObjects[specName]
65
-        for depPkg in specObj.installRequiresPackages[inPkg]:
66
-		if (allDeps.has_key(depPkg) and allDeps[depPkg] < level + 1): 
67
-	   		allDeps[depPkg] = level + 1
68
-			parent[depPkg] = inPkg
61
+	def updateLevels(self, allDeps, inPkg, parent, level):
62
+		specName = self.getSpecName(inPkg) 
63
+		specObj  = self.mapSerializableSpecObjects[specName]
64
+		for depPkg in specObj.installRequiresPackages[inPkg]:
65
+			if (allDeps.has_key(depPkg) and allDeps[depPkg] < level + 1): 
66
+				allDeps[depPkg] = level + 1
67
+				parent[depPkg] = inPkg
69 68
 			                 
70
-    def readSpecsAndConvertToSerializableObjects(self, specFilesPath, inputType, inputValue, displayOption):
69
+	def readSpecsAndConvertToSerializableObjects(self, specFilesPath, inputType, inputValue, displayOption):
71 70
 		children = {}
72 71
 		listSpecFiles=[]
73 72
 		whoNeedsList=[]
73
+		independentRPMS=[] # list of all RPMS not built from photon and that must be blindly copied.
74 74
 		allDeps={}
75 75
 		parent={}
76 76
 		depQue = Queue.Queue()
... ...
@@ -92,124 +92,146 @@ class SerializedSpecObjects(object):
92 92
 			specObj.securityHardening=spec.getSecurityHardeningOption()
93 93
 			for specPkg in specObj.listPackages:
94 94
 				specObj.installRequiresPackages[specPkg]=spec.getRequires(specPkg)
95
-				if( inputType == "pkg" and inputValue == specPkg): # all all the first level dependencies to a dictionary and queue 
96
-				    packageFound = True
97
-				    for depPkg in specObj.installRequiresPackages[specPkg]:
98
-					if False == allDeps.has_key(depPkg):
99
-								allDeps[depPkg] = 0
100
-								parent[depPkg] = ""
101
-								depQue.put(depPkg)
102
-				if (inputType == "who-needs"):
103
-					if (inputValue in specObj.installRequiresPackages[specPkg]):
104
-						whoNeedsList.append(specPkg)
95
+				if (inputType == "pkg" and inputValue == specPkg): # all the first level dependencies to a dictionary and queue 
96
+					packageFound = True
97
+					for depPkg in specObj.installRequiresPackages[specPkg]:
98
+						if False == allDeps.has_key(depPkg):
99
+							allDeps[depPkg] = 0
100
+							parent[depPkg] = ""
101
+							depQue.put(depPkg)
102
+				if (inputType == "who-needs" and (inputValue in specObj.installRequiresPackages[specPkg])):
103
+					whoNeedsList.append(specPkg)
105 104
 				self.mapPackageToSpec[specPkg]=specName
106 105
 			self.mapSerializableSpecObjects[specName]=specObj		
106
+	    
107
+		# Generate dependencies for individual packages
107 108
 		if (inputType == "pkg"):
108 109
 			if (packageFound == True):
109 110
 				self.findTotalRequires(allDeps, depQue, parent, displayOption)
110 111
 			else:
111 112
 				print "No spec file builds a package named",inputValue
112
-  	  			return
113
+				return
114
+
115
+		# Generate dependencies for all packages in the given JSON input file
113 116
 		elif (inputType == "json"):
114 117
 			filePath = self.inputDataDir +"/"+ inputValue
115 118
 			data = self.get_all_package_names(filePath)
116
-			#print data
117 119
 			for pkg in data:
118 120
 				if False == allDeps.has_key(pkg):
119
-					allDeps[pkg] = 0 
120
-					parent[pkg] = ""
121
-					depQue.put(pkg)
122
-					self.findTotalRequires(allDeps, depQue, parent, displayOption)
121
+					spName = self.getSpecName(pkg)
122
+					if(spName != None):			
123
+						allDeps[pkg] = 0 
124
+						parent[pkg] = ""
125
+						depQue.put(pkg)
126
+						self.findTotalRequires(allDeps, depQue, parent, displayOption)
127
+					else:
128
+						independentRPMS.append(pkg); 
129
+
130
+		#Generating the list of packages that requires the given input package at install time
123 131
 		elif (inputType == "who-needs"):
124 132
 			print whoNeedsList
133
+			return
134
+
125 135
 		# construct the sorted list of all packages (sorted by dependency)
126 136
 		sortedList = []
127 137
 		for elem in sorted(allDeps.items(), key=operator.itemgetter(1), reverse=True):
128 138
 			sortedList.append(elem[0])
129
-		# construct all children nodes
139
+		sortedList.extend(independentRPMS)
140
+
141
+	    # construct all children nodes
130 142
 		if (displayOption == "tree"):
131
-			#print "parent:" ,parent
132 143
 			for k, v in parent.iteritems():
133 144
 				children.setdefault(v, []).append(k)
134 145
 			if(inputType == "json"):
135
-				print "Dependency Mappings:\n", children
146
+				print "Dependency Mappings for", inputValue, ":", "\n----------------------------------------------------",children
147
+				print "----------------------------------------------------"				
136 148
 			if (children.has_key("")):
137 149
 				for child in children[""]:
138 150
 					print child
139 151
 					self.printTree(allDeps, children, child, 1)
152
+				for pkg in independentRPMS:
153
+					print pkg
154
+				print "******************",len(sortedList), "packages in total ******************"
140 155
 			else:
141 156
 				if (inputType == "pkg" and len(children) > 0):
142
-					print "cyclic dependency mappings: \n",children
157
+					print "cyclic dependency detected, mappings: \n",children 
158
+
159
+		# To display a flat list of all packages
143 160
 		elif(displayOption == "list"):
144 161
 			print sortedList
162
+
163
+		# To generate a new JSON file based on given input json file
145 164
 		elif(displayOption == "json" and inputType == "json"):
146 165
 			d = {}
147 166
 			d['packages'] = sortedList
148 167
 			outFilePath = self.jsonFilesOutPath + inputValue
149 168
 			with open(outFilePath, 'wb') as outfile:
150
-    				json.dump(d, outfile)		
169
+				json.dump(d, outfile)		
151 170
 	
152
-    def getListSpecFiles(self,listSpecFiles,path):
153
-        for dirEntry in os.listdir(path):
154
-            dirEntryPath = os.path.join(path, dirEntry)
155
-            if os.path.isfile(dirEntryPath) and dirEntryPath.endswith(".spec"):
156
-                listSpecFiles.append(dirEntryPath)
157
-            elif os.path.isdir(dirEntryPath):
158
-                self.getListSpecFiles(listSpecFiles,dirEntryPath)
171
+	def getListSpecFiles(self,listSpecFiles,path):
172
+		for dirEntry in os.listdir(path):
173
+			dirEntryPath = os.path.join(path, dirEntry)
174
+			if os.path.isfile(dirEntryPath) and dirEntryPath.endswith(".spec"):
175
+				listSpecFiles.append(dirEntryPath)
176
+			elif os.path.isdir(dirEntryPath):
177
+				self.getListSpecFiles(listSpecFiles,dirEntryPath)
159 178
     
160
-    def getBuildRequiresForPackage(self, package):
161
-        specName=self.getSpecName(package)
162
-        return self.mapSerializableSpecObjects[specName].buildRequirePackages
179
+	def getBuildRequiresForPackage(self, package):
180
+		specName=self.getSpecName(package)
181
+		return self.mapSerializableSpecObjects[specName].buildRequirePackages
163 182
         
164
-    def getRequiresForPackage(self, package):
165
-        specName=self.getSpecName(package)
166
-        if self.mapSerializableSpecObjects[specName].installRequiresPackages.has_key(package):
167
-            return self.mapSerializableSpecObjects[specName].installRequiresPackages[package]
168
-        return None
183
+	def getRequiresForPackage(self, package):
184
+		specName=self.getSpecName(package)
185
+		if self.mapSerializableSpecObjects[specName].installRequiresPackages.has_key(package):
186
+			return self.mapSerializableSpecObjects[specName].installRequiresPackages[package]
187
+		return None
169 188
     
170
-    def getRelease(self, package):
171
-        specName=self.getSpecName(package)
172
-        return self.mapSerializableSpecObjects[specName].release
189
+	def getRelease(self, package):
190
+		specName=self.getSpecName(package)
191
+		return self.mapSerializableSpecObjects[specName].release
173 192
         
174
-    def getVersion(self, package):
175
-        specName=self.getSpecName(package)
176
-        return self.mapSerializableSpecObjects[specName].version
193
+	def getVersion(self, package):
194
+		specName=self.getSpecName(package)
195
+		return self.mapSerializableSpecObjects[specName].version
177 196
         
178
-    def getSpecFile(self, package):
179
-        specName=self.getSpecName(package)
180
-        return self.mapSerializableSpecObjects[specName].specFile
197
+	def getSpecFile(self, package):
198
+		specName=self.getSpecName(package)
199
+		return self.mapSerializableSpecObjects[specName].specFile
181 200
         
182
-    def getPatches(self, package):
183
-        specName=self.getSpecName(package)
184
-        return self.mapSerializableSpecObjects[specName].listPatches
201
+	def getPatches(self, package):
202
+		specName=self.getSpecName(package)
203
+		return self.mapSerializableSpecObjects[specName].listPatches
185 204
         
186
-    def getSources(self, package):
187
-        specName=self.getSpecName(package)
188
-        return self.mapSerializableSpecObjects[specName].listSources
205
+	def getSources(self, package):
206
+		specName=self.getSpecName(package)
207
+		return self.mapSerializableSpecObjects[specName].listSources
189 208
         
190
-    def getPackages(self, package):
191
-        specName=self.getSpecName(package)
192
-        return self.mapSerializableSpecObjects[specName].listPackages
209
+	def getPackages(self, package):
210
+		specName=self.getSpecName(package)
211
+		return self.mapSerializableSpecObjects[specName].listPackages
193 212
         
194
-    def getSpecName(self,package):
195
-        if self.mapPackageToSpec.has_key(package):
196
-            specName=self.mapPackageToSpec[package]
197
-            if self.mapSerializableSpecObjects.has_key(specName):
198
-                return specName
199
-        print "SpecDeps: Could not able to find "+package+" package from specs"
200
-        raise Exception("Invalid package:"+package)
213
+	def getSpecName(self,package):
214
+		if self.mapPackageToSpec.has_key(package):
215
+			specName=self.mapPackageToSpec[package]
216
+			if self.mapSerializableSpecObjects.has_key(specName):
217
+				return specName
218
+			else:
219
+				print "SpecDeps: Could not able to find " + package + " package from specs"
220
+				raise Exception("Invalid package:" + package)
221
+		else:
222
+			return None			
201 223
     
202
-    def isRPMPackage(self,package):
203
-        if self.mapPackageToSpec.has_key(package):
204
-            specName=self.mapPackageToSpec[package]
205
-            if self.mapSerializableSpecObjects.has_key(specName):
206
-                return True
207
-        return False
224
+	def isRPMPackage(self,package):
225
+		if self.mapPackageToSpec.has_key(package):
226
+			specName=self.mapPackageToSpec[package]
227
+			if self.mapSerializableSpecObjects.has_key(specName):
228
+				return True
229
+		return False
208 230
     
209
-    def getSecurityHardeningOption(self, package):
210
-        specName=self.getSpecName(package)
211
-        return self.mapSerializableSpecObjects[specName].securityHardening
231
+	def getSecurityHardeningOption(self, package):
232
+		specName=self.getSpecName(package)
233
+		return self.mapSerializableSpecObjects[specName].securityHardening
212 234
         
213
-    def getSpecDetails(self, name):
214
-    	print self.mapSerializableSpecObjects[name].installRequiresAllPackages 
235
+	def getSpecDetails(self, name):
236
+		print self.mapSerializableSpecObjects[name].installRequiresAllPackages 
215 237
 
... ...
@@ -29,30 +29,27 @@ def main():
29 29
 	parser.add_option("-a", "--input-data-dir", dest="input_data_dir", default="../../common/data/")
30 30
 	(options,  args) = parser.parse_args() 
31 31
 
32
-
33 32
 	if(False == options.input_data_dir.endswith('/')):
34 33
 		options.input_data_dir += '/'
35
-	
36
-		
37 34
 
38 35
 	specDeps = SerializedSpecObjects(options.input_data_dir, options.stage_dir)
39 36
 	displayOption = options.display_option
40 37
 	abs_path = os.path.abspath(__file__)
41 38
 	dir_name = os.path.dirname(abs_path)
42 39
 	os.chdir(dir_name)
43
-	
40
+
44 41
 	if(options.input_type == "pkg" or options.input_type == "who-needs"): # To display/print package dependencies on console
45 42
 		targetName = options.pkg
46 43
 		specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, targetName, displayOption)
47
-	elif(options.input_type == "json"):
48
-		 # Generate the expanded package dependencies json file based on package_list_file 
44
+	elif(options.input_type == "json"):# Generate the expanded package dependencies json file based on package_list_file 
49 45
 		json_wrapper_option_list = JsonWrapper(options.json_file)
50 46
 		option_list_json = json_wrapper_option_list.read()
51 47
 		options_sorted = option_list_json.items()
52 48
 		for install_option in options_sorted:
53
-			if install_option[1]["file"] != "iso":
54
-				specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, install_option[1]["file"], displayOption)
55
-	
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
+
56 53
 	sys.exit(0)
57 54
 
58 55
 if __name__=="__main__":
... ...
@@ -21,6 +21,7 @@ MAKEROOT := $(realpath $(MAKEROOT))
21 21
 PHOTON_STAGE?=$(SRCROOT)/stage
22 22
 PHOTON_LOGS_DIR=$(PHOTON_STAGE)/LOGS
23 23
 PHOTON_RPMS_DIR=$(PHOTON_STAGE)/RPMS
24
+PHOTON_UPDATED_RPMS_DIR?=$(PHOTON_STAGE)/UPDATED_RPMS
24 25
 PHOTON_SPECS_DIR?=$(SRCROOT)/SPECS
25 26
 PHOTON_COMMON_DIR?=$(SRCROOT)/common
26 27
 PHOTON_DATA_DIR?=$(PHOTON_COMMON_DIR)/data
... ...
@@ -44,6 +45,8 @@ PHOTON_CLOUD_IMAGE_BUILDER=$(PHOTON_CLOUD_IMAGE_BUILDER_DIR)/cloud-image-build.s
44 44
 PHOTON_CHROOT_CLEANER=$(PHOTON_PKG_BUILDER_DIR)/cleanup-build-root.sh
45 45
 PHOTON_RPMS_DIR_NOARCH=$(PHOTON_RPMS_DIR)/noarch
46 46
 PHOTON_RPMS_DIR_X86_64=$(PHOTON_RPMS_DIR)/x86_64
47
+PHOTON_UPDATED_RPMS_DIR_NOARCH?=$(PHOTON_UPDATED_RPMS_DIR)/noarch
48
+PHOTON_UPDATED_RPMS_DIR_X86_64?=$(PHOTON_UPDATED_RPMS_DIR)/x86_64
47 49
 PHOTON_PACKER_TEMPLATES=$(SRCROOT)/support/packer-templates
48 50
 
49 51
 PHOTON_CHROOT_PATH:=$(PHOTON_STAGE)/photonroot