summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-08-01 14:19:06 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-08-19 15:11:18 +0100
commitde581b4362278f1e958d083a12f7eed39b99e033 (patch)
treea217b5f0a6bd8ad5bf1fe30645981417353571c8
parent1da1a78501b568e02a91efeb52554a82e2fa4043 (diff)
downloadmorph-de581b4362278f1e958d083a12f7eed39b99e033.tar.gz
Allow inserting data in the build directory
Add staging_area.copy_file_to_build_dir() function. Use with care!
-rw-r--r--morphlib/stagingarea.py8
-rw-r--r--morphlib/stagingarea_tests.py15
2 files changed, 22 insertions, 1 deletions
diff --git a/morphlib/stagingarea.py b/morphlib/stagingarea.py
index 0126b4d9..8a10b278 100644
--- a/morphlib/stagingarea.py
+++ b/morphlib/stagingarea.py
@@ -271,6 +271,13 @@ class StagingArea(object):
self.do_unmounts()
+ def copy_file_to_build_dir(self, data, target_relpath):
+ # FIXME: should give progress info
+ target_abspath = os.path.join(self.builddirname, target_relpath)
+ logging.debug('Writing %s to %s', data, target_abspath)
+ with open(target_abspath, 'wb') as f:
+ shutil.copyfileobj(data, f)
+
def runcmd(self, argv, **kwargs): # pragma: no cover
'''Run a command in a chroot in the staging area.'''
assert 'env' not in kwargs
@@ -334,4 +341,3 @@ class StagingArea(object):
'failed', os.path.basename(self.dirname))
os.rename(self.dirname, dest_dir)
self.dirname = dest_dir
-
diff --git a/morphlib/stagingarea_tests.py b/morphlib/stagingarea_tests.py
index 52f495eb..0d101db4 100644
--- a/morphlib/stagingarea_tests.py
+++ b/morphlib/stagingarea_tests.py
@@ -17,6 +17,7 @@
import cliapp
import os
import shutil
+import StringIO
import tarfile
import tempfile
import unittest
@@ -45,6 +46,7 @@ class FakeApplication(object):
self.settings = {
'cachedir': cachedir,
'tempdir': tempdir,
+ 'no-ccache': True
}
for leaf in ('chunks',):
d = os.path.join(tempdir, leaf)
@@ -140,3 +142,16 @@ class StagingAreaTests(unittest.TestCase):
object(), self.staging, self.build_env, use_chroot=False)
filename = os.path.join(self.staging, 'foobar')
self.assertEqual(sa.relative(filename), filename)
+
+ def test_supports_inserting_files_into_build(self):
+ sa = self.sa
+ source = FakeSource()
+ sa.chroot_open(source, False)
+
+ data = StringIO.StringIO('test content')
+ sa.copy_file_to_build_dir(data, 'test-data.txt')
+
+ builddir = '%s.build' % source.morphology['name']
+ test_data_file = os.path.join(self.staging, builddir, 'test-data.txt')
+ with open(test_data_file) as f:
+ self.assertEqual(f.read(), data.getvalue())