source: branches/numpy_misc/tools/acceptance_tests/test_dump_python_environment.py @ 7017

Last change on this file since 7017 was 7017, checked in by rwilson, 15 years ago

Improved reporting.

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/bin/env python
2
3'''Testlet to dump the acceptance environment.'''
4
5import os
6import sys
7import time
8import test_utils as util
9
10name = 'Dump of the acceptance test environment'
11
12def test(logfile):
13    (cluster, domain) = util.get_hostname()
14
15    # show the hostname
16    util.log_print_nl(logfile, 'Hostname: %s.%s' % (cluster, domain))
17    util.log_print_nl(logfile)
18
19    # show value of PYTHON environment variable
20    python_env_var = os.getenv('PYTHON', '')
21    util.log_print_nl(logfile, 'PYTHON environment variable = %s' % python_env_var)
22    if python_env_var == '':
23        util.log_print_nl(logfile, "Assume 'export PYTHON=python'")
24    util.log_print_nl(logfile)
25    python_env_var = os.getenv('PYTHON', 'python')
26
27    # show python version being used
28    cmd = '%s -c "import sys;print sys.version"' % python_env_var
29    fd = os.popen(cmd, 'r')
30    python_version = fd.read()
31    fd.close() 
32    util.log_print_nl(logfile, "Executing '$PYTHON' gives version: %s" % python_version.replace('\n', ' '))
33    util.log_print_nl(logfile)
34
35    # show PYTHONPATH value
36    pythonpath = os.getenv('PYTHONPATH')
37    util.log_print_nl(logfile, 'PYTHONPATH environment variable = %s' % pythonpath)
38    util.log_print_nl(logfile)
39
40    # show contents of ./machines_<machine>
41    home = os.getenv('HOME')
42    machines_file = os.path.join(home, '.machines_%s' % cluster)
43    try:
44        fd = open(machines_file, 'r')
45        data = fd.read()
46        fd.close()
47    except:
48        data = '***** NO FILE FOUND *****\n'
49
50    util.log_print_nl(logfile, '%s:' % machines_file)
51    util.log_print_nl(logfile, '-' * 30)
52    util.log_print(logfile, data)
53    util.log_print_nl(logfile, '-' * 30)
54    util.log_print_nl(logfile)
55
56    return True
57
58
59if __name__ == '__main__':
60    logfile = 'test.log'
61    if len(sys.argv) > 1:
62        logfile = sys.argv[1]
63
64    try:
65        os.remove(logfile)
66    except:
67        pass
68
69    if not test(logfile):
70        sys.exit(10)
71
72    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.