00001 import sys, os, platform 00002 import optparse 00003 00004 def show_help(option, opt, value, parser): 00005 parser.print_help() 00006 sys.exit(-1) 00007 00008 def interactive_flag(option, opt, value, parser): 00009 pass 00010 00011 def stop(): 00012 sys.exit(0) 00013 00014 usage = 'usage: ost [ost options] [script to execute] [script parameters]' 00015 class OstOptionParser(optparse.OptionParser): 00016 def __init__(self, **kwargs): 00017 optparse.OptionParser.__init__(self, **kwargs) 00018 def exit(self, status_code, error_message): 00019 print error_message, 00020 sys.exit(-1) 00021 00022 parser=OstOptionParser(usage=usage,conflict_handler="resolve", prog='ost''') 00023 parser.add_option("-i", "--interactive", action="callback", callback=interactive_flag, help="start interpreter interactively (must be first parameter, ignored otherwise)") 00024 parser.add_option("-h", "--help", action="callback", callback=show_help, help="show this help message and exit") 00025 parser.add_option("-v", "--verbosity_level", action="store", type="int", dest="vlevel", default=2, help="sets the verbosity level [default: %default]") 00026 parser.disable_interspersed_args() 00027 (options, args) = parser.parse_args() 00028 00029 _site_packs='python%d.%d/site-packages' % sys.version_info[0:2] 00030 _base_dir=os.getenv('DNG_ROOT') 00031 sys.path.insert(0, os.path.join(_base_dir, 'lib64', _site_packs)) 00032 00033 from ost import SetPrefixPath, GetSharedDataPath, conop 00034 00035 SetPrefixPath(_base_dir) 00036 00037 def _InitRuleBasedProcessor(): 00038 compound_lib_path=os.path.join(GetSharedDataPath(), 'compounds.chemlib') 00039 if os.path.exists(compound_lib_path): 00040 compound_lib=conop.CompoundLib.Load(compound_lib_path) 00041 conop.SetDefaultLib(compound_lib) 00042 00043 # switch to rule-based processor, if compound library is available 00044 _InitRuleBasedProcessor() 00045 from ost import * 00046 import ost 00047 00048 import os.path 00049 HistoryFile=os.path.expanduser('~/.ost_history') 00050 00051 # we are not in GUI mode. 00052 gui_mode=False 00053 00054 sys.ps1='ost> ' 00055 sys.ps2='..... ' 00056 sys.argv=sys.argv[1:] 00057 home = os.getenv('HOME') or os.getenv('USERPROFILE') 00058 _ostrc=os.path.join(home, '.ostrc') 00059 if os.path.exists(_ostrc): 00060 try: 00061 exec(open(_ostrc)) 00062 except Exception, e: 00063 print e 00064 PushVerbosityLevel(options.vlevel) 00065 00066 # this should probably only be added when running an interactive shell 00067 sys.path.append(".") 00068 00069 if len(parser.rargs)>0 : 00070 script=parser.rargs[0] 00071 sys_argv_backup=sys.argv 00072 sys.argv=parser.rargs 00073 try: 00074 execfile(script) 00075 finally: 00076 sys.argv=sys_argv_backup 00077