summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmorphlib/app.py91
-rw-r--r--morphlib/plugins/trebuchet_plugin.py111
-rw-r--r--without-test-modules1
3 files changed, 112 insertions, 91 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index e2460f68..f3f10975 100755
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -579,97 +579,6 @@ class Morph(cliapp.Application):
category=DeprecationWarning)
return self.cache_repo_and_submodules(*args)
- def cmd_make_patch(self, args):
- '''Create a Trebuchet patch between two system images.'''
-
- logging.debug('cmd_make_patch starting')
-
- if len(args) != 7:
- raise cliapp.AppException('make-patch requires arguments: '
- 'name of output file plus two triplest')
-
- output = args[0]
- repo_name1, ref1, filename1 = args[1:4]
- repo_name2, ref2, filename2 = args[4:7]
-
- self.settings.require('cachedir')
- cachedir = self.settings['cachedir']
- build_env = morphlib.buildenvironment.BuildEnvironment(self.settings)
- ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
- lac = morphlib.localartifactcache.LocalArtifactCache(
- os.path.join(cachedir, 'artifacts'))
- repo_resolver = morphlib.repoaliasresolver.RepoAliasResolver(
- self.settings['repo-alias'])
- lrc = morphlib.localrepocache.LocalRepoCache(
- self, os.path.join(cachedir, 'gits'), repo_resolver,
- bundle_base_url=self.settings['bundle-server'])
- if self.settings['cache-server']:
- rrc = morphlib.remoterepocache.RemoteRepoCache(
- self.settings['cache-server'], repo_resolver)
- else:
- rrc = None
-
- def the_one(source, repo_name, ref, filename):
- return (source.repo_name == repo_name and
- source.original_ref == ref and
- source.filename == filename)
-
- def get_artifact(repo_name, ref, filename):
- srcpool = self.create_source_pool(
- lrc, rrc, (repo_name, ref, filename))
- ar = morphlib.artifactresolver.ArtifactResolver()
- artifacts = ar.resolve_artifacts(srcpool)
- for artifact in artifacts:
- artifact.cache_key = ckc.compute_key(artifact)
- if the_one(artifact.source, repo_name, ref, filename):
- a = morphlib.artifact.Artifact(
- artifact.source,
- artifact.source.morphology['name'] + '-rootfs')
- a.cache_key = artifact.cache_key
- return a
-
- artifact1 = get_artifact(repo_name1, ref1, filename1)
- artifact2 = get_artifact(repo_name2, ref2, filename2)
-
- image_path_1 = lac.get(artifact1).name
- image_path_2 = lac.get(artifact2).name
-
- def setup(path):
- part = morphlib.fsutils.setup_device_mapping(self.runcmd, path)
- mount_point = tempfile.mkdtemp(dir=self.settings['tempdir'])
- morphlib.fsutils.mount(self.runcmd, part, mount_point)
- return mount_point
-
- def cleanup(path, mount_point):
- if mount_point is not None:
- try:
- morphlib.fsutils.unmount(self.runcmd, mount_point)
- except:
- pass
- try:
- morphlib.fsutils.undo_device_mapping(self.runcmd, path)
- except:
- pass
- try:
- os.rmdir(mount_point)
- except:
- pass
-
- mount_point_1 = None
- mount_point_2 = None
- try:
- mount_point_1 = setup(image_path_1)
- mount_point_2 = setup(image_path_2)
-
- self.runcmd(['tbdiff-create', output,
- os.path.join(mount_point_1, 'factory'),
- os.path.join(mount_point_2, 'factory')])
- except BaseException:
- raise
- finally:
- cleanup(image_path_1, mount_point_1)
- cleanup(image_path_2, mount_point_2)
-
def cmd_init(self, args):
'''Initialize a mine.'''
diff --git a/morphlib/plugins/trebuchet_plugin.py b/morphlib/plugins/trebuchet_plugin.py
new file mode 100644
index 00000000..6aa0bc17
--- /dev/null
+++ b/morphlib/plugins/trebuchet_plugin.py
@@ -0,0 +1,111 @@
+# Copyright (C) 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.
+
+
+import cliapp
+import os
+import tempfile
+
+import morphlib
+
+
+class TrebuchetPlugin(cliapp.Plugin):
+
+ def enable(self):
+ self.app.add_subcommand('make-patch',
+ self.make_patch,
+ arg_synopsis='PATH SRC_TRIPLE TGT_TRIPLE')
+
+ def disable(self):
+ pass
+
+ def make_patch(self, args):
+ '''Create a Trebuchet patch between two system images.'''
+
+ if len(args) != 7:
+ raise cliapp.AppException('make-patch requires arguments: '
+ 'name of output file plus two triplest')
+
+ output = args[0]
+ repo_name1, ref1, filename1 = args[1:4]
+ repo_name2, ref2, filename2 = args[4:7]
+
+ app = self.app
+ build_env = morphlib.buildenvironment.BuildEnvironment(app.settings)
+ ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
+ lac, rac = morphlib.util.new_artifact_caches(app.settings)
+ lrc, rrc = morphlib.util.new_repo_caches(app)
+
+ def the_one(source, repo_name, ref, filename):
+ return (source.repo_name == repo_name and
+ source.original_ref == ref and
+ source.filename == filename)
+
+ def get_artifact(repo_name, ref, filename):
+ srcpool = app.create_source_pool(
+ lrc, rrc, (repo_name, ref, filename))
+ ar = morphlib.artifactresolver.ArtifactResolver()
+ artifacts = ar.resolve_artifacts(srcpool)
+ for artifact in artifacts:
+ artifact.cache_key = ckc.compute_key(artifact)
+ if the_one(artifact.source, repo_name, ref, filename):
+ a = morphlib.artifact.Artifact(
+ artifact.source,
+ artifact.source.morphology['name'] + '-rootfs')
+ a.cache_key = artifact.cache_key
+ return a
+
+ artifact1 = get_artifact(repo_name1, ref1, filename1)
+ artifact2 = get_artifact(repo_name2, ref2, filename2)
+
+ image_path_1 = lac.get(artifact1).name
+ image_path_2 = lac.get(artifact2).name
+
+ def setup(path):
+ app.status(msg='Mounting image %(path)s', path=path)
+ part = morphlib.fsutils.setup_device_mapping(app.runcmd, path)
+ mount_point = tempfile.mkdtemp(dir=app.settings['tempdir'])
+ morphlib.fsutils.mount(app.runcmd, part, mount_point)
+ return mount_point
+
+ def cleanup(path, mount_point):
+ if mount_point is not None:
+ try:
+ morphlib.fsutils.unmount(app.runcmd, mount_point)
+ except:
+ pass
+ try:
+ morphlib.fsutils.undo_device_mapping(app.runcmd, path)
+ except:
+ pass
+ try:
+ os.rmdir(mount_point)
+ except:
+ pass
+
+ mount_point_1 = None
+ mount_point_2 = None
+ try:
+ mount_point_1 = setup(image_path_1)
+ mount_point_2 = setup(image_path_2)
+
+ app.runcmd(['tbdiff-create', output,
+ os.path.join(mount_point_1, 'factory'),
+ os.path.join(mount_point_2, 'factory')])
+ except BaseException:
+ raise
+ finally:
+ cleanup(image_path_1, mount_point_1)
+ cleanup(image_path_2, mount_point_2)
diff --git a/without-test-modules b/without-test-modules
index f625bc14..4c3af81f 100644
--- a/without-test-modules
+++ b/without-test-modules
@@ -11,4 +11,5 @@ morphlib/plugins/syslinux-disk-systembuilder_plugin.py
morphlib/plugins/tarball-systembuilder_plugin.py
morphlib/plugins/show_dependencies_plugin.py
morphlib/plugins/update_gits_plugin.py
+morphlib/plugins/trebuchet_plugin.py