1 import sys, os, platform
16 usage =
'usage: ost [ost options] [script to execute] [script parameters]'
19 optparse.OptionParser.__init__(self, **kwargs)
20 def exit(self, status_code, error_message):
24 parser=
OstOptionParser(usage=usage,conflict_handler=
"resolve", prog=
'ost''')
25 parser.add_option("-i", "--interactive", action="callback", callback=interactive_flag, help="start interpreter interactively (must be first parameter, ignored otherwise)")
26 parser.add_option("-h", "--help", action="callback", callback=show_help, help="show this help message and exit")
27 parser.add_option("-v", "--verbosity_level", action="store", type="int", dest="vlevel", default=2, help="sets the verbosity level [default: %default]")
28 parser.disable_interspersed_args()
29 (options, args) = parser.parse_args()
31 if platform.machine()=='x86_64':
32 sys.path.insert(0, os.getenv('DNG_ROOT')+'/lib64/openstructure')
34 sys.path.insert(0,os.getenv('DNG_ROOT')+'/lib/openstructure')
39 ost.SetPrefixPath(os.getenv('DNG_ROOT'))
40 def _InitRuleBasedBuilder():
41 compound_lib_path=os.path.join(ost.GetSharedDataPath(), 'compounds.chemlib')
42 if os.path.exists(compound_lib_path):
43 conop_inst=conop.Conopology.Instance()
44 compound_lib=conop.CompoundLib.Load(compound_lib_path)
45 conop_inst.RegisterBuilder(conop.RuleBasedBuilder(compound_lib), 'RBB')
46 conop_inst.SetDefaultBuilder('RBB')
48 # switch to rule-based builder for high fidelity if compounds.chemlib is
50 _InitRuleBasedBuilder()
52 HistoryFile=os.path.expanduser('~/.ost_history')
58 home = os.getenv('HOME') or os.getenv('USERPROFILE')
59 _ostrc=os.path.join(home, '.ostrc')
60 if os.path.exists(_ostrc):
66 rcfile=open(_ostrc,"w")
67 print >> rcfile, '# This python file is parsed by ost and dng at startup'
68 print >> rcfile, '# Its content is be made available in the global namespace'
69 print >> rcfile, '# It can be used to define custom variables and functions'
70 print >> rcfile, '# For example:'
71 print >> rcfile, '# IMPORTANT_DIR="path/to/important/dir"'
74 PushVerbosityLevel(options.vlevel)
78 if len(parser.rargs)>0 :
79 script=parser.rargs[0]
80 sys_argv_backup=sys.argv
85 sys.argv=sys_argv_backup