Mercurial > repos > peterjc > mira4_9_mirabait
comparison tools/mira4_9/mirabait/mira_check_version.py @ 1:33bfaf5865c5 draft default tip
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_9 commit cd0ab853082e608d5646638b2d46489480616436
author | peterjc |
---|---|
date | Tue, 13 Oct 2015 10:01:25 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:5979f13c2dc5 | 1:33bfaf5865c5 |
---|---|
1 #!/usr/bin/env python | |
2 """A simple wrapper script to call a MIRA binary to check/report its version. | |
3 | |
4 Syntax: mira_check_version.py binary [expected pattern] | |
5 | |
6 The binary can be a full path, otherwise ``$PATH`` is searched as normal. | |
7 | |
8 Example output from MIRA V3.4 suite installed on the ``$PATH``:: | |
9 | |
10 $ python mira_check_version.py mira | |
11 This is MIRA V3.4.1.1 (production version). | |
12 $ python mira_check_version.py mirabait | |
13 V3.4.1.1 | |
14 | |
15 Example output from MIRA v4.0.2:: | |
16 | |
17 $ python mira_check_version.py ~/downloads/mira_4.0.2_linux-gnu_x86_64_static/bin/mira | |
18 4.0.2 | |
19 $ python mira_check_version.py ~/downloads/mira_4.0.2_linux-gnu_x86_64_static/bin/mirabait | |
20 4.0.2 | |
21 $ python mira_check_version.py ~/downloads/mira_4.0.2_linux-gnu_x86_64_static/bin/miraconvert | |
22 4.0.2 | |
23 | |
24 Example output from MIRA v4.9.5:: | |
25 | |
26 $ python mira_check_version.py ~/downloads/mira_4.9.5_2_linux-gnu_x86_64_static/bin/mira | |
27 4.9.5_2 | |
28 $ python mira_check_version.py ~/downloads/mira_4.9.5_2_linux-gnu_x86_64_static/bin/mirabait | |
29 4.9.5_2 | |
30 $ python mira_check_version.py ~/downloads/mira_4.9.5_2_linux-gnu_x86_64_static/bin/miraconvert | |
31 4.9.5_2 | |
32 | |
33 The optional version checking is simple substring approach (beware of potential | |
34 issues if MIRA versions ever use double digits for minor version), and returns | |
35 zero if this matched:: | |
36 | |
37 $ python mira_check_version.py mirabait 4.9 && echo "Return value $?" | |
38 4.9.5_2 | |
39 Return value 0 | |
40 | |
41 If the expected version did not match, the return value is one (error):: | |
42 | |
43 $ python mira_check_version.py mirabait 4.9 && echo "Return value $?" | |
44 Expected MIRA v4.9, but mirabait reports: V3.4.1.1 | |
45 Return value 1 | |
46 | |
47 This script is intended to be used as part of my Galaxy wrappers for MIRA, | |
48 where it will capture and record the version used - and give a clear error | |
49 message if there is a version mismatch (otherwise due to API changes the | |
50 MIRA error messages tend to be very long and somewhare confusing). | |
51 """ | |
52 import os | |
53 import sys | |
54 import subprocess | |
55 import shutil | |
56 import time | |
57 | |
58 WRAPPER_VER = "0.0.1" #Keep in sync with the XML file | |
59 | |
60 def sys_exit(msg, err=1): | |
61 sys.stderr.write(msg+"\n") | |
62 sys.exit(err) | |
63 | |
64 | |
65 def get_version(mira_binary): | |
66 """Run MIRA to find its version number""" | |
67 # At the commend line I would use: mira -v | head -n 1 | |
68 # however there is some pipe error when doing that here. | |
69 cmd = [mira_binary, "-v"] | |
70 try: | |
71 child = subprocess.Popen(cmd, | |
72 stdout=subprocess.PIPE, | |
73 stderr=subprocess.STDOUT) | |
74 except Exception, err: | |
75 sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err)) | |
76 sys.exit(1) | |
77 ver, tmp = child.communicate() | |
78 del child | |
79 #Workaround for -v not working in mirabait 4.0RC4 | |
80 if "invalid option" in ver.split("\n", 1)[0]: | |
81 for line in ver.split("\n", 1): | |
82 if " version " in line: | |
83 line = line.split() | |
84 return line[line.index("version")+1].rstrip(")") | |
85 sys_exit("Could not determine MIRA version:\n%s" % ver) | |
86 return ver.split("\n", 1)[0] | |
87 | |
88 | |
89 if "-v" in sys.argv or "--version" in sys.argv: | |
90 print("mira_check_version.py version %s" % WRAPPER_VER) | |
91 sys.exit(0) | |
92 | |
93 if len(sys.argv) == 2: | |
94 mira_binary = sys.argv[1] | |
95 expected = None | |
96 elif len(sys.argv) == 3: | |
97 mira_binary = sys.argv[1] | |
98 expected = sys.argv[2] | |
99 else: | |
100 sys_exit("Usage: mira_check_version.py mira_binary [expected version]") | |
101 | |
102 mira_ver = get_version(mira_binary) | |
103 if expected and not mira_ver.strip().startswith(expected): | |
104 sys_exit("Expected MIRA v%s, but %s reports: %s" % (expected, mira_binary, mira_ver)) | |
105 print(mira_ver) |