-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdiffcalc_launcher.py
executable file
·86 lines (67 loc) · 3.09 KB
/
diffcalc_launcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python
import argparse
import subprocess
import os
import getpass
DIFFCALC_BIN = os.path.split(os.path.realpath(__file__))[0]
DIFFCALC_ROOT = os.path.abspath(os.path.join(DIFFCALC_BIN, os.pardir))
MODULE_FOR_MANUALS = '_make_sixcircle_manual'
def main():
parser = argparse.ArgumentParser(description='Diffcalc: A diffraction condition calculator of x-ray and neutron crystalography')
parser.add_argument('--modules', dest='show_modules', action='store_true',
help='list available modules')
parser.add_argument('--python', dest='use_python', action='store_true',
help='run within python rather than ipython')
parser.add_argument('--debug', dest='debug', action='store_true',
help='run in debug mode')
parser.add_argument('--make-manuals-source', dest='make_manuals', action='store_true',
help='make .rst manual files by running template through sixcircle')
parser.add_argument('--non-interactive', dest='non_interactive', action='store_true',
help='do not enter interactive mode after startup')
parser.add_argument('module', type=str, nargs='?',
help='the module to startup with')
args = parser.parse_args()
# Create list of available modules
module_names = []
for module_path in os.listdir(os.path.join(DIFFCALC_ROOT, 'startup')):
if not module_path.startswith('_') and module_path.endswith('.py'):
module_names.append(module_path.split('.')[0])
module_names.sort()
if args.show_modules:
print_available_modules(module_names)
exit(0)
if not args.make_manuals and not args.module:
print "A module name should be provided. Choose one of:"
print_available_modules(module_names)
exit(0)
if args.make_manuals:
if args.module:
print "When building the manuals no module should be given"
exit(1)
args.module = MODULE_FOR_MANUALS
if not args.make_manuals and args.module not in module_names:
print "The provided argument '%s' is not one of:" % args.module
print_available_modules(module_names)
exit(1)
env = os.environ.copy()
if 'PYTHONPATH' not in env:
env['PYTHONPATH'] = ''
env['PYTHONPATH'] = DIFFCALC_ROOT + ':' + env['PYTHONPATH']
diffcmd_start_path = os.path.join(DIFFCALC_ROOT, 'diffcmd', 'start.py')
if args.use_python:
cmd = 'python'
else: # ipython
cmd = 'ipython --no-banner --HistoryManager.hist_file=/tmp/ipython_hist_%s.sqlite' % getpass.getuser()
iflag = '' if args.non_interactive else '-i'
cmd = cmd + ' ' + ' '.join([iflag, diffcmd_start_path, args.module, str(args.debug)])
print 'Running: ' + cmd
rc = subprocess.call(cmd, env=env, shell=True)
exit(rc)
def print_available_modules(module_names):
lines = []
for m in sorted(module_names):
lines.append(' ' + m)
print '\n'.join(lines)
if __name__ == '__main__':
main()
#