Merge lp:~mabac/linaro-image-tools/qemu-version into lp:linaro-image-tools/11.11

Proposed by Mattias Backman
Status: Merged
Merged at revision: 451
Proposed branch: lp:~mabac/linaro-image-tools/qemu-version
Merge into: lp:linaro-image-tools/11.11
Diff against target: 51 lines (+22/-2)
1 file modified
linaro_image_tools/media_create/__init__.py (+22/-2)
To merge this branch: bzr merge lp:~mabac/linaro-image-tools/qemu-version
Reviewer Review Type Date Requested Status
Fathi Boudra Pending
linaro-image-tools maintainers Pending
Review via email: mp+79821@code.launchpad.net

Description of the change

Hi,

This branch adds printing the version of qemu-arm-static along with the l-i-t version with the --version option.

It seems that argparse strips \n from the version string so the output is currently unreadable. Please let me know what you'd like the output to be and I'll try to make it happen.

Another slight inconvenience is that qemu-arm-static doesn't have a --version option which is the reason for the not so obvious implementation. I run qemu-arm-static --version with stdout piped to head -n 1 to get the first line of output. Just using the stdout pipe from the first Popen call didn't work since it closes as the command fails.

Thanks,

Mattias

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Heh, funny implementation of --version that is in qemu :-)

I don't think the output is unusable, so unless you can come up with
a way around that behaviour I think it can go in like this.

Thanks,

James

Revision history for this message
Mattias Backman (mabac) wrote :

On Wed, Oct 19, 2011 at 7:18 PM, James Westby <email address hidden> wrote:
> Heh, funny implementation of --version that is in qemu :-)
>
> I don't think the output is unusable, so unless you can come up with
> a way around that behaviour I think it can go in like this.

Ok, then I'll just land it and we can see if it's important enough
that we get bug reports on it. I don't think the --version option is
worth spending too much time on.

>
> Thanks,
>
> James
>
> --
> https://code.launchpad.net/~mabac/linaro-image-tools/qemu-version/+merge/79821
> You are the owner of lp:~mabac/linaro-image-tools/qemu-version.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro_image_tools/media_create/__init__.py'
2--- linaro_image_tools/media_create/__init__.py 2011-10-12 13:44:12 +0000
3+++ linaro_image_tools/media_create/__init__.py 2011-10-19 14:21:33 +0000
4@@ -18,7 +18,10 @@
5 # along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>.
6
7 import argparse
8+import subprocess
9+import os
10
11+from linaro_image_tools import cmd_runner
12 from linaro_image_tools.media_create.boards import board_configs
13 from linaro_image_tools.media_create.android_boards import android_board_configs
14 from linaro_image_tools.__version__ import __version__
15@@ -46,9 +49,26 @@
16 setattr(namespace, 'is_live', True)
17
18
19+def get_version():
20+ qemu_path = '/usr/bin/qemu-arm-static'
21+ p = cmd_runner.run(["head", "-n", "1"],
22+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
23+ if os.path.exists(qemu_path):
24+ try:
25+ # qemu-arm-static has no --version option so it fails,
26+ # but still prints its version plus usage
27+ cmd_runner.run(["/usr/bin/qemu-arm-static", "--version"],
28+ stdout=p.stdin).communicate()
29+ p.communicate()
30+ except:
31+ qemu_version = p.stdout.read()
32+ else:
33+ qemu_version = "Cannot find %s." % qemu_path
34+ return "%s\n: %s" % (__version__, qemu_version)
35+
36 def get_args_parser():
37 """Get the ArgumentParser for the arguments given on the command line."""
38- parser = argparse.ArgumentParser(version='%(prog)s ' + __version__)
39+ parser = argparse.ArgumentParser(version='%(prog)s ' + get_version())
40 group = parser.add_mutually_exclusive_group(required=True)
41 group.add_argument(
42 '--mmc', dest='device', help='The storage device to use.')
43@@ -129,7 +149,7 @@
44
45 def get_android_args_parser():
46 """Get the ArgumentParser for the arguments given on the command line."""
47- parser = argparse.ArgumentParser(version='%(prog)s ' + __version__)
48+ parser = argparse.ArgumentParser(version='%(prog)s ' + get_version())
49 group = parser.add_mutually_exclusive_group(required=True)
50 group.add_argument(
51 '--mmc', dest='device', help='The storage device to use.')

Subscribers

People subscribed via source and target branches