[scm-wrapper] Reduce code duplication in RPM wrapper
The logic for expanding the list of patterns into a list of actual RPM paths was duplicated for both exporting a directory and file. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
770ca9c202
commit
6daf43f72e
@ -154,24 +154,17 @@ class GitWrapper(ScmBase):
|
|||||||
|
|
||||||
|
|
||||||
class RpmScmWrapper(ScmBase):
|
class RpmScmWrapper(ScmBase):
|
||||||
|
def _list_rpms(self, pats):
|
||||||
|
for pat in force_list(pats):
|
||||||
|
for rpm in glob.glob(pat):
|
||||||
|
yield rpm
|
||||||
|
|
||||||
def export_dir(self, scm_root, scm_dir, target_dir, scm_branch=None, tmp_dir=None, log_file=None):
|
def export_dir(self, scm_root, scm_dir, target_dir, scm_branch=None, tmp_dir=None, log_file=None):
|
||||||
# if scm_root is a list, recursively process all RPMs
|
for rpm in self._list_rpms(scm_root):
|
||||||
if isinstance(scm_root, list):
|
|
||||||
for i in scm_root:
|
|
||||||
self.export_dir(i, scm_dir, target_dir, scm_branch, tmp_dir, log_file)
|
|
||||||
return
|
|
||||||
|
|
||||||
# if scm_root is a glob, recursively process all RPMs
|
|
||||||
rpms = glob.glob(scm_root)
|
|
||||||
if len(rpms) > 1 or (rpms and rpms[0] != scm_root):
|
|
||||||
for i in rpms:
|
|
||||||
self.export_dir(i, scm_dir, target_dir, scm_branch, tmp_dir, log_file)
|
|
||||||
return
|
|
||||||
|
|
||||||
scm_dir = scm_dir.lstrip("/")
|
scm_dir = scm_dir.lstrip("/")
|
||||||
tmp_dir = self._create_temp_dir(tmp_dir=tmp_dir)
|
tmp_dir = self._create_temp_dir(tmp_dir=tmp_dir)
|
||||||
self.log_debug("Extracting directory %s from RPM package %s..." % (scm_dir, scm_root))
|
self.log_debug("Extracting directory %s from RPM package %s..." % (scm_dir, rpm))
|
||||||
explode_rpm_package(scm_root, tmp_dir)
|
explode_rpm_package(rpm, tmp_dir)
|
||||||
|
|
||||||
makedirs(target_dir)
|
makedirs(target_dir)
|
||||||
# "dir" includes the whole directory while "dir/" includes it's content
|
# "dir" includes the whole directory while "dir/" includes it's content
|
||||||
@ -182,24 +175,12 @@ class RpmScmWrapper(ScmBase):
|
|||||||
self._delete_temp_dir(tmp_dir)
|
self._delete_temp_dir(tmp_dir)
|
||||||
|
|
||||||
def export_file(self, scm_root, scm_file, target_dir, scm_branch=None, tmp_dir=None, log_file=None):
|
def export_file(self, scm_root, scm_file, target_dir, scm_branch=None, tmp_dir=None, log_file=None):
|
||||||
# if scm_root is a list, recursively process all RPMs
|
for rpm in self._list_rpms(scm_root):
|
||||||
if isinstance(scm_root, list):
|
|
||||||
for i in scm_root:
|
|
||||||
self.export_file(i, scm_file, target_dir, scm_branch, tmp_dir, log_file)
|
|
||||||
return
|
|
||||||
|
|
||||||
# if scm_root is a glob, recursively process all RPMs
|
|
||||||
rpms = glob.glob(scm_root)
|
|
||||||
if len(rpms) > 1 or (rpms and rpms[0] != scm_root):
|
|
||||||
for i in rpms:
|
|
||||||
self.export_file(i, scm_file, target_dir, scm_branch, tmp_dir, log_file)
|
|
||||||
return
|
|
||||||
|
|
||||||
scm_file = scm_file.lstrip("/")
|
scm_file = scm_file.lstrip("/")
|
||||||
tmp_dir = self._create_temp_dir(tmp_dir=tmp_dir)
|
tmp_dir = self._create_temp_dir(tmp_dir=tmp_dir)
|
||||||
|
|
||||||
self.log_debug("Exporting file %s from RPM file %s..." % (scm_file, scm_root))
|
self.log_debug("Exporting file %s from RPM file %s..." % (scm_file, rpm))
|
||||||
explode_rpm_package(scm_root, tmp_dir)
|
explode_rpm_package(rpm, tmp_dir)
|
||||||
|
|
||||||
makedirs(target_dir)
|
makedirs(target_dir)
|
||||||
for src in glob.glob(os.path.join(tmp_dir, scm_file)):
|
for src in glob.glob(os.path.join(tmp_dir, scm_file)):
|
||||||
|
Loading…
Reference in New Issue
Block a user