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

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

Changes to run specified version of python.

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