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
"%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)
+