summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2019-03-23 20:34:26 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2019-03-25 17:58:50 +0000
commit8b4924f45cf238271a67b7b62a874b2d012fb029 (patch)
tree96d8af6a0271cc48d7a5572355a4844de9c9a0af
parent07c0f7282fc7f42d1c6b2231b23b3e2abcc318f8 (diff)
cerbero: Share code for creating android and dist tarballs
_create_tarball() does the same thing in both classes.
-rw-r--r--cerbero/packages/android.py26
-rw-r--r--cerbero/packages/disttarball.py14
2 files changed, 10 insertions, 30 deletions
diff --git a/cerbero/packages/android.py b/cerbero/packages/android.py
index e2d4103f..7c388fb8 100644
--- a/cerbero/packages/android.py
+++ b/cerbero/packages/android.py
@@ -29,37 +29,15 @@ class AndroidPackager(DistTarball):
''' Creates a distribution tarball for Android '''
def __init__(self, config, package, store):
- DistTarball.__init__(self, config, package, store)
+ super().__init__(config, package, store)
def _create_tarball(self, output_dir, package_type, files, force,
package_prefix):
- filenames = []
-
# Filter out some unwanted directories for the development package
if package_type == PackageType.DEVEL:
for filt in ['bin/', 'share/aclocal']:
files = [x for x in files if not x.startswith(filt)]
-
- # Create the bz2 file first
- filename = os.path.join(output_dir, self._get_name(package_type))
- if os.path.exists(filename):
- if force:
- os.remove(filename)
- else:
- raise UsageError("File %s already exists" % filename)
-
- try:
- with tarfile.open(filename, "w:bz2") as tar:
- for f in files:
- filepath = os.path.join(self.prefix, f)
- tar.add(filepath, os.path.join(package_prefix, f))
- except OSError:
- os.replace(filename, filename + '.partial')
- raise
-
- filenames.append(filename)
-
- return ' '.join(filenames)
+ return super()._create_tarball(output_dir, package_type, files, force, package_prefix)
def _get_name(self, package_type, ext='tar.bz2'):
if package_type == PackageType.DEVEL:
diff --git a/cerbero/packages/disttarball.py b/cerbero/packages/disttarball.py
index abf5be04..e5f4bbc4 100644
--- a/cerbero/packages/disttarball.py
+++ b/cerbero/packages/disttarball.py
@@ -92,12 +92,14 @@ class DistTarball(PackagerBase):
else:
raise UsageError("File %s already exists" % filename)
- tar = tarfile.open(filename, "w:bz2")
-
- for f in files:
- filepath = os.path.join(self.prefix, f)
- tar.add(filepath, os.path.join(package_prefix, f))
- tar.close()
+ try:
+ with tarfile.open(filename, "w:bz2") as tar:
+ for f in files:
+ filepath = os.path.join(self.prefix, f)
+ tar.add(filepath, os.path.join(package_prefix, f))
+ except OSError:
+ os.replace(filename, filename + '.partial')
+ raise
return filename