-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstart.py
88 lines (72 loc) · 2.67 KB
/
start.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
87
88
"""
start the diffcmd environemt using a script from startup.
This should normally be run by the main diffcalc.py program.
with diffcalc on PYTHONPATH
$ ipython -i -m diffcm.diffcmd module_name_string debug_bool
"""
from __future__ import absolute_import
import diffcalc
import diffcalc.settings
import os
import sys
from diffcalc.ub.persistence import UBCalculationJSONPersister
from diffcalc.ub.calcstate import UBCalcStateEncoder
from diffcalc.util import bold
import diffcalc.util
import diffcalc.gdasupport.minigda.command
DIFFCALC_ROOT = os.path.realpath(diffcalc.__file__).split('diffcalc/__init__.py')[0]
try:
__IPYTHON__ # @UndefinedVariable
IPYTHON = True
except NameError:
IPYTHON = False
module_name = sys.argv[1] #3 if IPYTHON else 1]
debug = sys.argv[2] == 'True' #4 if IPYTHON else 2])
print
print bold('-' * 34 + ' DIFFCALC ' + '-' * 35)
# configure persisentence
DIFFCALC_VAR = os.path.join(os.path.expanduser('~'), '.diffcalc', module_name)
if not os.path.exists(DIFFCALC_VAR):
print "Making diffcalc var folder:'%s'" % DIFFCALC_VAR
os.makedirs(DIFFCALC_VAR)
diffcalc.settings.ubcalc_persister = UBCalculationJSONPersister(DIFFCALC_VAR, UBCalcStateEncoder)
# configure debug
diffcalc.util.DEBUG = debug
if debug:
print "WARNING: debug mode on; help for command syntax errors disabled."
# import script
script = os.path.join(DIFFCALC_ROOT, 'startup', module_name) + '.py'
print "Startup script: '%s'" % script
namespace = {}
execfile(script, namespace)
globals().update(namespace)
diffcalc.gdasupport.minigda.command.ROOT_NAMESPACE_DICT = dict(namespace)
print bold('-' * 36 + ' Help ' + '-' * 37)
print HELP_STRING # @UndefinedVariable
if 'LOCAL_MANUAL' in locals():
print "Local: " + LOCAL_MANUAL # @UndefinedVariable
print bold('-' * 79)
print
# magic commands if IPython
if IPYTHON:
from diffcmd.ipython import magic_commands
magic_commands(globals())
if 'MANUALS_TO_MAKE' in locals():
summary_lines = ['Made manuals:']
from diffcmd.make_manual import make_manual
for source_path in MANUALS_TO_MAKE: # @UndefinedVariable
import diffcalc.ub.ub
try:
diffcalc.ub.ub.rmub('example')
except KeyError:
pass
target_path = source_path.replace('_template', '')
print '@' * 79
print "Making manual"
print " Source:", source_path
print " Target:", target_path
make_manual(source_path, target_path,
ub_commands_for_help, # @UndefinedVariable
hkl_commands_for_help) # @UndefinedVariable
summary_lines.append(' - ' + source_path + ' -- > ' + target_path)
print '\n'.join(summary_lines)