Skip to content
Snippets Groups Projects
Select Git revision
  • cd8ea1c043f6a918d31d686ed2c4f1e989a9d27c
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

ost_startup.py.in

Blame
  • ost_startup.py.in 2.30 KiB
    import sys, os, platform
    import optparse
    
    def show_help(option, opt, value, parser):
      parser.print_help()
      sys.exit(-1)
    
    def interactive_flag(option, opt, value, parser):
      pass
    
    def stop():
      sys.exit(0)
    
    usage = 'usage: ost [ost options] [script to execute] [script parameters]'
    class OstOptionParser(optparse.OptionParser):
      def __init__(self, **kwargs):
        optparse.OptionParser.__init__(self, **kwargs)
      def exit(self, status_code, error_message):
        print error_message,
        sys.exit(-1)
    
    parser=OstOptionParser(usage=usage,conflict_handler="resolve", prog='ost''')
    parser.add_option("-i", "--interactive", action="callback", callback=interactive_flag, help="start interpreter interactively (must be first parameter, ignored otherwise)")
    parser.add_option("-h", "--help", action="callback", callback=show_help, help="show this help message and exit")
    parser.add_option("-v", "--verbosity_level", action="store", type="int", dest="vlevel", default=2, help="sets the verbosity level [default: %default]")
    parser.disable_interspersed_args()
    (options, args) = parser.parse_args()
    
    _site_packs='python%d.%d/site-packages' % sys.version_info[0:2]
    _base_dir=os.getenv('DNG_ROOT')
    sys.path.insert(0, os.path.join(_base_dir, '@LIBDIR@', _site_packs))
         
    from ost import SetPrefixPath, GetSharedDataPath, conop
    
    SetPrefixPath(_base_dir)
    
    def _InitRuleBasedProcessor():
      compound_lib_path=os.path.join(GetSharedDataPath(), 'compounds.chemlib')
      if os.path.exists(compound_lib_path):
        compound_lib=conop.CompoundLib.Load(compound_lib_path)
        conop.SetDefaultLib(compound_lib)
    
    # switch to rule-based processor, if compound library is available
    _InitRuleBasedProcessor()
    from ost import *
    import ost
    
    import os.path
    HistoryFile=os.path.expanduser('~/.ost_history')
    
    # we are not in GUI mode. 
    gui_mode=False
    
    sys.ps1='ost> '
    sys.ps2='..... '
    sys.argv=sys.argv[1:]
    home = os.getenv('HOME') or os.getenv('USERPROFILE')
    _ostrc=os.path.join(home, '.ostrc')
    if os.path.exists(_ostrc):
      try:
        exec(open(_ostrc))
      except Exception, e:
        print e
    PushVerbosityLevel(options.vlevel)
    
    # this should probably only be added when running an interactive shell
    sys.path.append(".")
    
    if len(parser.rargs)>0 :
      script=parser.rargs[0]	
      sys_argv_backup=sys.argv
      sys.argv=parser.rargs
      try:
        execfile(script)
      finally:
        sys.argv=sys_argv_backup