diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 451: Display qemu version in l-m-c and l-a-m-c --version output.

Message ID 20111020070110.31412.28935.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Mattias Backman Oct. 20, 2011, 7:01 a.m. UTC
Merge authors:
  Mattias Backman (mabac)
Related merge proposals:
  https://code.launchpad.net/~mabac/linaro-image-tools/qemu-version/+merge/79821
  proposed by: Mattias Backman (mabac)
------------------------------------------------------------
revno: 451 [merge]
committer: Mattias Backman <mattias.backman@linaro.org>
branch nick: linaro-image-tools
timestamp: Thu 2011-10-20 08:58:39 +0200
message:
  Display qemu version in l-m-c and l-a-m-c --version output.
modified:
  linaro_image_tools/media_create/__init__.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_image_tools/media_create/__init__.py'
--- linaro_image_tools/media_create/__init__.py	2011-10-12 13:44:12 +0000
+++ linaro_image_tools/media_create/__init__.py	2011-10-19 14:18:52 +0000
@@ -18,7 +18,10 @@ 
 # along with Linaro Image Tools.  If not, see <http://www.gnu.org/licenses/>.
 
 import argparse
+import subprocess
+import os
 
+from linaro_image_tools import cmd_runner
 from linaro_image_tools.media_create.boards import board_configs
 from linaro_image_tools.media_create.android_boards import android_board_configs
 from linaro_image_tools.__version__ import __version__
@@ -46,9 +49,26 @@ 
         setattr(namespace, 'is_live', True)
 
 
+def get_version():
+    qemu_path = '/usr/bin/qemu-arm-static'
+    p = cmd_runner.run(["head", "-n", "1"],
+                       stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+    if os.path.exists(qemu_path):
+        try:
+            # qemu-arm-static has no --version option so it fails,
+            # but still prints its version plus usage
+            cmd_runner.run(["/usr/bin/qemu-arm-static", "--version"],
+                           stdout=p.stdin).communicate()
+            p.communicate()
+        except:
+            qemu_version = p.stdout.read()
+    else:
+        qemu_version = "Cannot find %s." % qemu_path
+    return "%s\n: %s" % (__version__, qemu_version)
+
 def get_args_parser():
     """Get the ArgumentParser for the arguments given on the command line."""
-    parser = argparse.ArgumentParser(version='%(prog)s ' + __version__)
+    parser = argparse.ArgumentParser(version='%(prog)s ' + get_version())
     group = parser.add_mutually_exclusive_group(required=True)
     group.add_argument(
         '--mmc', dest='device', help='The storage device to use.')
@@ -129,7 +149,7 @@ 
 
 def get_android_args_parser():
     """Get the ArgumentParser for the arguments given on the command line."""
-    parser = argparse.ArgumentParser(version='%(prog)s ' + __version__)
+    parser = argparse.ArgumentParser(version='%(prog)s ' + get_version())
     group = parser.add_mutually_exclusive_group(required=True)
     group.add_argument(
         '--mmc', dest='device', help='The storage device to use.')