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