Permalink
Browse files

sources: Add RPM source

  • Loading branch information...
1 parent a309efa commit c960914b97440e2dca7a66c22c07438d809590fc @Conan-Kudo committed Oct 18, 2016
Showing with 38 additions and 0 deletions.
  1. +37 −0 snapcraft/internal/sources.py
  2. +1 −0 snapcraft/sources.py
@@ -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):
View
@@ -18,6 +18,7 @@
from snapcraft.internal.sources import Script # noqa
from snapcraft.internal.sources import Bazaar # noqa
from snapcraft.internal.sources import Deb # noqa
+from snapcraft.internal.sources import Rpm # noqa
from snapcraft.internal.sources import Git # noqa
from snapcraft.internal.sources import Mercurial # noqa
from snapcraft.internal.sources import Subversion # noqa

0 comments on commit c960914

Please sign in to comment.