summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-10-17 20:25:59 +0100
committerLars Wirzenius <liw@liw.fi>2011-10-17 20:25:59 +0100
commit7cba0a33cee244379cb2078b7c286c4de5c4f341 (patch)
treea8e9e7d264336f5adc495e3de0e7d665ccfe0ed0 /morphlib
parent0d62665119d13a113f92de18f918e850f4596f69 (diff)
downloadmorph-7cba0a33cee244379cb2078b7c286c4de5c4f341.tar.gz
Add functions for creating and unpacking strata.
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/bins.py22
-rw-r--r--morphlib/bins_tests.py24
2 files changed, 46 insertions, 0 deletions
diff --git a/morphlib/bins.py b/morphlib/bins.py
index de946020..06956cd3 100644
--- a/morphlib/bins.py
+++ b/morphlib/bins.py
@@ -47,3 +47,25 @@ def unpack_chunk(chunk_filename, dirname):
tar.extractall(path=dirname)
tar.close()
+
+def create_stratum(rootdir, stratum_filename):
+ '''Create a stratum from the contents of a directory.'''
+ logging.debug('Creating stratum file %s from %s' %
+ (stratum_filename, rootdir))
+ tar = tarfile.open(name=stratum_filename, mode='w:gz')
+ tar.add(rootdir, arcname='.')
+ tar.close()
+
+
+def unpack_stratum(stratum_filename, dirname):
+ '''Unpack a stratum into a directory.
+
+ The directory must exist already.
+
+ '''
+
+ logging.debug('Unpacking stratum %s into %s' % (stratum_filename, dirname))
+ tar = tarfile.open(name=stratum_filename)
+ tar.extractall(path=dirname)
+ tar.close()
+
diff --git a/morphlib/bins_tests.py b/morphlib/bins_tests.py
index b3c13a64..30076120 100644
--- a/morphlib/bins_tests.py
+++ b/morphlib/bins_tests.py
@@ -76,3 +76,27 @@ class ChunkTests(unittest.TestCase):
self.assertEqual(recursive_lstat(self.instdir),
recursive_lstat(self.unpacked))
+
+class StratumTests(unittest.TestCase):
+
+ def setUp(self):
+ self.tempdir = tempfile.mkdtemp()
+ self.instdir = os.path.join(self.tempdir, 'inst')
+ self.stratum_file = os.path.join(self.tempdir, 'stratum')
+ self.unpacked = os.path.join(self.tempdir, 'unpacked')
+
+ def tearDown(self):
+ shutil.rmtree(self.tempdir)
+
+ def populate_instdir(self):
+ os.mkdir(self.instdir)
+ os.mkdir(os.path.join(self.instdir, 'bin'))
+
+ def test_creates_and_unpacks_stratum_exactly(self):
+ self.populate_instdir()
+ morphlib.bins.create_stratum(self.instdir, self.stratum_file)
+ os.mkdir(self.unpacked)
+ morphlib.bins.unpack_stratum(self.stratum_file, self.unpacked)
+ self.assertEqual(recursive_lstat(self.instdir),
+ recursive_lstat(self.unpacked))
+