summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-06-14 14:25:49 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-06-14 14:25:49 +0000
commitdfd9cae3248b36d489f638c5b1c3c3aa6c54c050 (patch)
treec3026c8980ad8d11b4f576fe0bff89b7c72f9f49 /scripts
parentf7790e2ec52b3cc3f8b58f3e447da37361ff9580 (diff)
downloadmorph-dfd9cae3248b36d489f638c5b1c3c3aa6c54c050.tar.gz
tests: fix some that expected tarball strata
This required functionality to create a tarball from a json file. This should probably be rewritten as a morph plugin and refactor it to consolidate the creation logic, so e.g. the stratum metadata is kept.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/assemble-stratum53
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/assemble-stratum b/scripts/assemble-stratum
new file mode 100755
index 00000000..fa4a0390
--- /dev/null
+++ b/scripts/assemble-stratum
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2011-2012 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# This is a program to convert the json dump of the overlaps between artifacts
+# in a format more suited to shell programs, or human reading
+
+import json
+import tarfile
+import os
+
+import cliapp
+
+class AssembleStratum(cliapp.Application):
+
+ def add_settings(self):
+ self.settings.string(['cachedir'],
+ 'Where the cache basedir is')
+ self.settings.string(['tarformat'],
+ 'What format to write tar to',
+ default='')
+
+ def process_args(self, args):
+ chunklist = json.load(open(args[0]))
+ tarformat = 'w'
+ if self.settings['tarformat'] != "":
+ tarformat += self.settings['tarformat']
+ outfile = tarfile.open(args[1], tarformat)
+ for chunk in chunklist:
+ path = os.path.join(self.settings['cachedir'], 'artifacts', chunk)
+ chunktar = tarfile.open(path, mode='r:*')
+ for tarinfo in chunktar:
+ if tarinfo.isfile():
+ outfile.addfile(tarinfo, chunktar.extractfile(tarinfo))
+ else:
+ outfile.addfile(tarinfo)
+ chunktar.close()
+ outfile.close()
+
+AssembleStratum().run()