Browse code

Adding support to generate YAML files for OSS

Change-Id: I28814029ce9b12f590454a90b4c8f2cf7062465a
Reviewed-on: http://photon-jenkins.eng.vmware.com/753
Tested-by: jenkins-photon <wangnan2015@hotmail.com>
Reviewed-by: Sharath George

dthaluru authored on 2016/04/26 08:50:52
Showing 2 changed files
... ...
@@ -30,6 +30,10 @@ class Specutils(object):
30 30
     def getChecksums(self):
31 31
         pkg = self.spec.packages.get('default')
32 32
         return pkg.checksums
33
+
34
+    def getChecksumForSource(self,source):
35
+        pkg = self.spec.packages.get('default')
36
+        return pkg.checksums.get(source)
33 37
     
34 38
     def getSourceURLs(self):
35 39
         sourceNames=[]
... ...
@@ -117,7 +117,13 @@ def main():
117 117
         if package == "packages_list":
118 118
             buildPackagesList(options.specPath, options.buildRootPath+"/../packages_list.csv")
119 119
         elif package == "sources_list":
120
-            buildSourcesList(options.specPath, options.buildRootPath+"/../")
120
+            if not os.path.isdir("../../stage/yaml_sources"):
121
+                cmdUtils.runCommandInShell("mkdir -p ../../stage/yaml_sources")
122
+            buildSourcesList(options.specPath,"../../stage/yaml_sources", options.buildRootPath+"/../",logger)
123
+        elif package == "srpms_list":
124
+            if not os.path.isdir("../../stage/yaml_srpms"):
125
+                cmdUtils.runCommandInShell("mkdir -p ../../stage/yaml_srpms")
126
+            buildSRPMList(options.specPath,options.sourceRpmPath,"../../stage/yaml_srpms",logger)
121 127
         elif options.toolChainStage == "stage1":
122 128
             pkgManager = PackageManager()
123 129
             pkgManager.buildToolChain()
... ...
@@ -175,12 +181,13 @@ def buildPackagesList(specPath, csvFilename):
175 175
                     csvFile.write(name+","+version+","+license+","+url+","+sources+","+patches+"\n")
176 176
     csvFile.close()
177 177
 
178
-def buildSourcesList(specPath, yamlDir, singleFile=False):
178
+def buildSourcesList(specPath,sourcePath, yamlDir, logger, singleFile=False):
179 179
     strUtils = StringUtils()
180 180
     if singleFile:
181 181
         yamlFile = open(yamlDir+"sources_list.yaml", "w")
182 182
     lst = os.listdir(specPath)
183 183
     lst.sort()
184
+    import PullSources
184 185
     for dirEntry in lst:
185 186
         specDir = os.path.join(specPath, dirEntry)
186 187
         if os.path.isdir(specDir):
... ...
@@ -193,6 +200,14 @@ def buildSourcesList(specPath, yamlDir, singleFile=False):
193 193
                     ossname = spec.getBasePackageName()
194 194
                     ossversion = spec.getVersion()
195 195
                     url = None
196
+                    listSourceNames = spec.getSourceNames()
197
+                    sourceName = None
198
+                    if len(listSourceNames) >0:
199
+                        sourceName=listSourceNames[0]
200
+                        sha1 = spec.getChecksumForSource(sourceName)                       
201
+                        if sha1 is not None:
202
+                            PullSources.get(sourceName, sha1, sourcePath, constants.pullsourcesConfig)
203
+
196 204
                     if len(listSourceURLs) > 0:
197 205
                         sourceURL = listSourceURLs[0]
198 206
                         if sourceURL.startswith("http") or sourceURL.startswith("ftp"):
... ...
@@ -200,13 +215,15 @@ def buildSourcesList(specPath, yamlDir, singleFile=False):
200 200
                         else:
201 201
                             url=spec.getURL(ossname)
202 202
                     if not singleFile:
203
-                        yamlFile = open(yamlDir+ossname+"-"+ossversion+".yaml", "w")
203
+                        yamlFile = open(yamlDir+"/"+ossname+"-"+ossversion+".yaml", "w")
204 204
                     yamlFile.write("vmwsource:"+ossname+":"+ossversion+":\n")
205 205
                     yamlFile.write("  repository: VMWsource\n")
206 206
                     yamlFile.write("  name: '"+ossname+"'\n")
207 207
                     yamlFile.write("  version: '"+ossversion+"'\n")
208 208
                     yamlFile.write("  url: "+str(url)+"\n")
209 209
                     yamlFile.write("  license: UNKNOWN\n")
210
+                    if sourceName is not None:
211
+                        yamlFile.write("  vmwsource-distribution: "+str(sourceName)+"\n")
210 212
                     if modified:
211 213
                         yamlFile.write("  modified: true\n")
212 214
                     yamlFile.write("\n")
... ...
@@ -214,6 +231,51 @@ def buildSourcesList(specPath, yamlDir, singleFile=False):
214 214
                         yamlFile.close()
215 215
     if singleFile:
216 216
         yamlFile.close()
217
+    logger.info("Generated source yaml files for all packages")
218
+
219
+def buildSRPMList(specPath,srpmPath, yamlDir, logger, singleFile=False):
220
+    strUtils = StringUtils()
221
+    if singleFile:
222
+        yamlFile = open(yamlDir+"srpm_list.yaml", "w")
223
+    lst = os.listdir(specPath)
224
+    lst.sort()
225
+    cmdUtils = CommandUtils()
226
+    for dirEntry in lst:
227
+        specDir = os.path.join(specPath, dirEntry)
228
+        if os.path.isdir(specDir):
229
+            for specEntry in os.listdir(specDir):
230
+                specFile = os.path.join(specDir, specEntry)
231
+                if os.path.isfile(specFile) and specFile.endswith(".spec"):
232
+                    spec=Specutils(specFile)
233
+                    ossname = spec.getBasePackageName()
234
+                    ossversion = spec.getVersion()
235
+                    ossrelease = spec.getRelease()
236
+                    listFoundSRPMFiles = cmdUtils.findFile(ossname+"-"+ossversion+"-"+ossrelease+".src.rpm",srpmPath)
237
+                    srpmName = None
238
+                    if len(listFoundSRPMFiles) == 1:
239
+                        srpmFullPath = listFoundSRPMFiles[0];
240
+                        srpmName = os.path.basename(srpmFullPath)
241
+                        cpcmd = "cp "+ srpmFullPath +" "+yamlDir+"/"
242
+                        returnVal = cmdUtils.runCommandInShell(cpcmd)
243
+                        if not returnVal:
244
+                            logger.error("Copy SRPM File is failed for package:"+ossname)
245
+                    else:
246
+                         logger.error("SRPM file is not found:" +ossname)
247
+                    if not singleFile:
248
+                        yamlFile = open(yamlDir+"/"+ossname+"-"+ossversion+"-"+ossrelease+".yaml", "w")
249
+                    yamlFile.write("baseos:"+ossname+":"+ossversion+"-"+ossrelease+":\n")
250
+                    yamlFile.write("  repository: BaseOS\n")
251
+                    yamlFile.write("  name: '"+ossname+"'\n")
252
+                    yamlFile.write("  version: '"+ossversion+"-"+ossrelease+"'\n")
253
+                    yamlFile.write("  baseos-style: rpm\n")
254
+                    yamlFile.write("  baseos-source: '"+str(srpmName)+"'\n")
255
+                    yamlFile.write("  baseos-osname: 'Photon OS'\n")
256
+                    yamlFile.write("\n")
257
+                    if not singleFile:
258
+                        yamlFile.close()
259
+    if singleFile:
260
+        yamlFile.close()
261
+    logger.info("Generated srpm yaml files for all packages")
217 262
 
218 263
 def buildAPackage(package, listBuildOptionPackages, pkgBuildOptionFile, buildThreads):
219 264
     listPackages=[]