[PATCH 04/17] Add image analysis plugin

Jonathan Maw jonathan.maw at codethink.co.uk
Thu Jan 24 18:45:09 GMT 2013


From: Jannis Pohlmann <jannis.pohlmann at codethink.co.uk>

---
 morphlib/plugins/image_analysis_plugin.py | 50 +++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 morphlib/plugins/image_analysis_plugin.py

diff --git a/morphlib/plugins/image_analysis_plugin.py b/morphlib/plugins/image_analysis_plugin.py
new file mode 100644
index 0000000..6cb1035
--- /dev/null
+++ b/morphlib/plugins/image_analysis_plugin.py
@@ -0,0 +1,50 @@
+# 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 gzip
+
+import morphlib
+
+from morphlib.mountableimage import MountableImage
+
+
+class ImageAnalysisPlugin(cliapp.Plugin):
+
+    def enable(self):
+        self.app.add_subcommand('run-in-system-image',
+                                self.run_in_image,
+                                arg_synopsis='IMAGE CMD')
+
+    def disable(self):
+        pass
+
+    def run_in_image(self, args):
+        '''Run a command inside a mounted system image.'''
+
+        if len(args) < 2:
+            raise cliapp.AppException('run-in-system-image requires '
+                                      'arguments: a system image filename '
+                                      'plus a shell command')
+
+        filename = args[0]
+        cmd = args[1:]
+
+        with MountableImage(self.app, filename) as mount_point:
+            output = self.app.runcmd(cmd, cwd=mount_point)
+            self.app.output.write(output)
-- 
1.7.11.7





More information about the baserock-dev mailing list