From 23450658b0c778262cbb34cb716462652aaefcca Mon Sep 17 00:00:00 2001
From: valerio <valerio@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Wed, 21 Apr 2010 15:15:03 +0000
Subject: [PATCH] Ost is not deficient anymore. Fixes BZDNG-107

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2093 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 scripts/init_cl.py | 42 +++++++++++++++++++++++++++++++++++++++---
 scripts/ost.in     | 18 +++++++++---------
 2 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/scripts/init_cl.py b/scripts/init_cl.py
index 9ea415044..942c60c53 100644
--- a/scripts/init_cl.py
+++ b/scripts/init_cl.py
@@ -1,4 +1,31 @@
 import sys, os, platform
+import optparse
+
+interactive=False
+
+def show_help(option, opt, value, parser):
+  parser.print_help()
+  sys.exit(-1)
+
+def interactive_flag(option, opt, value, parser):
+  pass
+
+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,
+    QtGui.QApplication.instance().exit()
+    sys.exit(-1)
+
+parser=OstOptionParser(usage=usage,conflict_handler="resolve")
+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=1, help="sets the verbosity level [default: %default]")
+parser.disable_interspersed_args()
+(options, args) = parser.parse_args()
+
 if platform.machine()=='x86_64':
   sys.path.insert(0, os.getenv('DNG_ROOT')+'/lib64/openstructure')
 else:
@@ -40,7 +67,16 @@ if os.path.exists(_ostrc):
   except Exception, e:
     print e
 
-if(len(sys.argv)>0):
-  script=sys.argv[0]
-  execfile(script)
+PushVerbosityLevel(options.vlevel)
+
+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
 
diff --git a/scripts/ost.in b/scripts/ost.in
index d3e0cc2de..73d7249d1 100755
--- a/scripts/ost.in
+++ b/scripts/ost.in
@@ -57,17 +57,17 @@ if [ $# == 0 ];then
 else
   opts=""
   for argument in "$@";do 
-    if [ "$argument" == "-i" ] ;then
-      interactive="-i"
-    else
-      if [ -n "$opts" ]; then
-        opts=$opts"#""$argument"
-      else  
-        opts="$argument"
-      fi  
-    fi
+    if [ -n "$opts" ]; then
+      opts=$opts"#""$argument"
+    else  
+      opts="$argument"
+    fi  
   done
+  if [ $1 == "-i" ] ;then
+    interactive="-i"
+  fi
 fi
+
 # finally pass control to python instance
 IFS="#"
 exec $pyexec $interactive "$DNG_ROOT/@LIBDIR@/openstructure/init_cl.py" $opts
-- 
GitLab