Add repo manifest file for ABS 58/71558/1
authorhyokeun <hyokeun.jeon@samsung.com>
Thu, 26 May 2016 01:58:18 +0000 (10:58 +0900)
committerhyokeun <hyokeun.jeon@samsung.com>
Thu, 26 May 2016 01:58:18 +0000 (10:58 +0900)
Change-Id: Ib8aac2c21b06d8d3500446b9344754f67f792dab

common/repomaker.py
job_create_snapshot.py

index abfacbd..8106c8b 100644 (file)
@@ -23,6 +23,7 @@ RepoMaker - creates download repos
 import os
 import shutil
 from hashlib import sha256 # pylint: disable-msg=E0611
+import rpm
 
 from common.builddata import BuildData, BuildDataError
 from common.imagedata import ImageData
@@ -343,3 +344,78 @@ class RepoMaker(object):
                                "%s_%s.xml"  %(self.build_id, name)),
                   'w') as manifest_fh:
             manifest_fh.write(manifest_string)
+
+    def get_rpm_vcs_from(self, rpm_file):
+        """Returns rpm information by querying a rpm"""
+        ts = rpm.ts()
+        fdno = os.open(rpm_file, os.O_RDONLY)
+        try:
+            hdr = ts.hdrFromFdno(fdno)
+        except rpm.error:
+            fdno = os.open(rpm_file, os.O_RDONLY)
+            ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
+            hdr = ts.hdrFromFdno(fdno)
+        os.close(fdno)
+        try:
+            vcs_path = hdr['vcs'].split('#')
+            vcs_from = hdr['description'].split('\n')[0].split('#')
+            if vcs_path[0] == vcs_from[0] and len(vcs_from[1]) == 40:
+                return vcs_from
+            else:
+                return None
+        except:
+            return None
+
+    def gen_manifest_info_app_from_rpm(self, name, gerrit_fetch_url, gerrit_review_url, in_dir, archs=()):
+        """
+        Generate manifest for ABS outputs(tpk) using rpms
+        """
+        if not os.path.exists(in_dir):
+            raise RepoMakerError("Directory %s doesn't exist" % in_dir)
+
+        wrong_archs = set(archs).intersection(set(ARCH_MAP))
+        if wrong_archs:
+            raise RepoMakerError("Wrong output architecture(s) specified: %s" \
+                                 % ", ".join(wrong_archs))
+
+        repo_dir = os.path.join(self.outdir, "repos", name)
+        if name not in self.repos:
+            self.repos[name] = {'archs': list(set(archs))}
+
+        # translate unified archs name 'ia23' to 'i586' 'i686' matched
+        # with OBS archs
+        if set(archs).intersection(set(ARCH_MAP.values())):
+            new_archs = [arch for arch in ARCH_MAP
+                            if ARCH_MAP.get(arch) in archs]
+            archs = new_archs + \
+                    list(set(archs).difference(set(ARCH_MAP.values())))
+
+        # Create directory structure
+        repo_dirs = create_dirs(repo_dir, archs)
+
+        # tuple set in (gitprj, git_path, revision)
+        data = set([])
+        for _rtype, _rarch, rpath in repo_dirs:
+            #Add list if _rtype == binary
+            if _rtype == 'binary':
+                for i in find_files(rpath):
+                    vcs_from = self.get_rpm_vcs_from(i)
+                    if vcs_from is not None:
+                        data.add((vcs_from[0], vcs_from[0], vcs_from[1]))
+
+        if len(data) == 0:
+            return
+
+        manifest_dir = os.path.join(self.outdir, 'builddata', 'manifest')
+
+        if not os.path.exists(manifest_dir):
+            os.makedirs(manifest_dir)
+
+        manifest_string = manifest.gen_repo_manifest(sorted(data),
+                                            gerrit_fetch_url,
+                                            gerrit_review_url)
+        with open(os.path.join(manifest_dir,
+                               "%s_%s_preloadapp.xml"  %(self.build_id, name)),
+                  'w') as manifest_fh:
+            manifest_fh.write(manifest_string)
+
index 869779b..ddbdc8c 100755 (executable)
@@ -143,6 +143,10 @@ def make_repo(project, backenddb, base_path, live_repo_base):
         repomaker.gen_manifest_info(repo['Name'],
                                     os.getenv('GERRIT_FETCH_URL'),
                                     os.getenv('GERRIT_REVIEW_URL'))
+        repomaker.gen_manifest_info_app_from_rpm(repo['Name'],
+                                    os.getenv('GERRIT_FETCH_URL'),
+                                    os.getenv('GERRIT_REVIEW_URL'),
+                                    live_repo_path, repo['Architectures'])
 
     return {'project': project,
             'repo': repos,