|
|
@@ -78,6 +78,7 @@ |
|
|
import zipfile
|
|
|
|
|
|
import apt_inst
|
|
|
+import libarchive
|
|
|
|
|
|
from snapcraft.internal import common
|
|
|
from snapcraft import file_utils
|
|
|
@@ -421,6 +422,42 @@ def provision(self, dst, clean_target=True, keep_deb=False): |
|
|
if not keep_deb:
|
|
|
os.remove(deb_file)
|
|
|
|
|
|
+class Rpm(FileBase):
|
|
|
+
|
|
|
+ def __init__(self, source, source_dir, source_tag=None,
|
|
|
+ source_branch=None, source_depth=None):
|
|
|
+ super().__init__(source, source_dir, source_tag,
|
|
|
+ source_branch, source_depth)
|
|
|
+ if source_tag:
|
|
|
+ raise IncompatibleOptionsError(
|
|
|
+ 'can\'t specify a source-tag for a rpm source')
|
|
|
+ elif source_branch:
|
|
|
+ raise IncompatibleOptionsError(
|
|
|
+ 'can\'t specify a source-branch for a rpm source')
|
|
|
+
|
|
|
+ def provision(self, dst, clean_target=True, keep_rpm=False):
|
|
|
+ rpm_file = os.path.join(self.source_dir, os.path.basename(self.source))
|
|
|
+
|
|
|
+ if clean_target:
|
|
|
+ tmp_rpm = tempfile.NamedTemporaryFile().name
|
|
|
+ shutil.move(rpm_file, tmp_rpm)
|
|
|
+ shutil.rmtree(dst)
|
|
|
+ os.makedirs(dst)
|
|
|
+ shutil.move(tmp_rpm, rpm_file)
|
|
|
+ # Open the RPM file and extract it to destination
|
|
|
+ with libarchive.file_reader(rpm_file) as rpm:
|
|
|
+ rpm_files = []
|
|
|
+ for rpm_file_entry in rpm:
|
|
|
+ if str(rpm_file_entry.pathname).startswith("./"):
|
|
|
+ if dst.endswith("/"):
|
|
|
+ rpm_file_entry.pathname = dst + rpm_file_entry.pathname[1:]
|
|
|
+ else:
|
|
|
+ rpm_file_entry.pathname = dst + rpm_file_entry.pathname[2:]
|
|
|
+ rpm_files.append(rpm_file_entry)
|
|
|
+ libarchive.extract.extract_entries(rpm_files)
|
|
|
+
|
|
|
+ if not keep_rpm:
|
|
|
+ os.remove(rpm_file)
|
|
|
|
|
|
class Local(Base):
|
|
|
|
|
|
|
0 comments on commit
c960914