ia64/xen-unstable

view tools/xm-test/lib/XmTestReport/ProgReport.py @ 7757:139aabe357a4

Various chmod a+x.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Thu Nov 10 12:00:09 2005 +0100 (2005-11-10)
parents ecb5997f7b25
children
line source
1 #!/usr/bin/python
3 """
4 ProgReport.py - Handles the gathering and xml-formatting of supporting
5 program information
7 Copyright (C) International Business Machines Corp., 2005
8 Author: Dan Smith <danms@us.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; under version 2 of the License.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 """
25 import utils
27 import commands
28 import re
29 import distutils.sysconfig
30 import sys
32 from xmtest import XM_TEST_VERSION
34 class Prog:
36 def __init__(self, name, version):
37 self.vars = {}
38 self.vars["name"] = name
39 self.vars["version"] = version
41 def __str__(self):
42 string = "<prog>\n"
44 for k in self.vars.keys():
45 string += " " + utils.tagify(k, self.vars[k]) + "\n"
47 string += "</prog>\n"
49 return string
51 class UnknownProg(Prog):
53 def __init__(self, name):
54 Prog.__init__(self, name, "Unknown Version")
56 class ProgFactory:
58 def getXen(self):
59 status, output = commands.getstatusoutput("xm info")
60 if status != 0:
61 return UnknownProg("xen")
63 for l in output.split("\n"):
64 match = re.match("^([a-z_]+)[ ]*: (.*)$", l)
65 if match and match.group(1) == "xen_changeset":
66 return Prog("xen", match.group(2))
68 return UnknownProg("xen")
70 def getXmTest(self):
71 return Prog("xm-test", XM_TEST_VERSION)
73 def getPython(self):
74 return Prog("python", distutils.sysconfig.get_python_version())
76 def getXenCaps(self):
77 s, o = commands.getstatusoutput("xm info")
78 if s != 0:
79 return UnknownProg("xen_caps")
81 for l in o.split("\n"):
82 match = re.match("^xen_caps[ \t]*: (.*)$", l)
83 if match:
84 return Prog("xen_caps", match.group(1))
86 class ProgReport:
88 def __init__(self):
90 self.progs = []
91 self.errors = 0
93 f = ProgFactory()
95 self.progs.append(f.getXen())
96 self.progs.append(f.getXmTest())
97 self.progs.append(f.getPython())
98 self.progs.append(f.getXenCaps())
100 for p in self.progs:
101 if isinstance(p, UnknownProg):
102 self.errors += 1
104 def __str__(self):
105 string = "<progs>\n"
107 for p in self.progs:
108 string += str(p)
110 string += "</progs>\n"
112 return string
114 if __name__ == "__main__":
115 r = ProgReport()
117 print str(r)
119 sys.exit(r.errors)