From 4cc40e09b32d8a46b6a93314158557b6cad39eb8 Mon Sep 17 00:00:00 2001
From: andreas <andreas@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Tue, 6 Apr 2010 17:50:01 +0000
Subject: [PATCH] modified gosty to take script as first parameter instead of
 getting script from stdin

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1932 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/gui/src/gosty.cc                      | 14 ++-----------
 .../src/python_shell/python_interpreter.cc    | 21 +++++--------------
 scripts/dng.bat.in                            |  4 ++--
 scripts/dng.in                                |  2 +-
 scripts/gipltng.bat.in                        |  2 +-
 scripts/gipltng.in                            |  2 +-
 scripts/init.py                               | 16 +++++++-------
 7 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/modules/gui/src/gosty.cc b/modules/gui/src/gosty.cc
index f7d452b4d..6f5ceaa55 100644
--- a/modules/gui/src/gosty.cc
+++ b/modules/gui/src/gosty.cc
@@ -145,20 +145,10 @@ int init_python_interpreter()
 
 void prepare_scripts(int argc, char** argv, PythonInterpreter& py)
 {
-  QTextStream stdin_stream(stdin);
-  QString stdin_line;
-  QString script_qstring("");
-  stdin_line=stdin_stream.readLine();
-  while (!stdin_line.isNull())
-  {
-    stdin_line.append("\n");
-    script_qstring += stdin_line;
-    stdin_line=stdin_stream.readLine();
-  }
-  for (int param_iter=1; param_iter<argc; ++param_iter) {
+  for (int param_iter=2; param_iter<argc; ++param_iter) {
     py.AppendCommandlineArgument(QString(argv[param_iter]));
   }
-  py.RunCommand(script_qstring);
+  py.RunScript(argv[1]);
 }
 
 
diff --git a/modules/gui/src/python_shell/python_interpreter.cc b/modules/gui/src/python_shell/python_interpreter.cc
index 4af471f17..2ac697de5 100644
--- a/modules/gui/src/python_shell/python_interpreter.cc
+++ b/modules/gui/src/python_shell/python_interpreter.cc
@@ -31,6 +31,7 @@
 
 #include <boost/filesystem/convenience.hpp>
 
+#include <QFile>
 #include <QDebug>
 #include <QApplication>
 #include <QThread>
@@ -196,25 +197,13 @@ void PythonInterpreter::ExecRelease()
 
 void PythonInterpreter::RunScript(const String& fname)
 {
-  std::ifstream script(fname.c_str());
-  if(!script) {
+    QFile file(QString::fromStdString(fname));
+  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
     LOGN_ERROR("could not open " << fname);
     return;
   }
-
-  String line;
-  QString command("");
-  while(std::getline(script,line)) {
-    command.append(QString::fromStdString(line));
-    command.append('\n');
-    if(this->GetCodeBlockStatus(command)!=CODE_BLOCK_INCOMPLETE) {
-      if(!RunCommand(command)) break;
-      command=QString("");
-    }
-  }
-  command.append('\n');
-  command.append('\n');
-  RunCommand(command);
+  QTextStream in(&file);
+  RunCommand(in.readAll());
 }
 
 bool PythonInterpreter::IsSimpleExpression(const QString& expr)
diff --git a/scripts/dng.bat.in b/scripts/dng.bat.in
index b54761f5c..0de8f7fe3 100644
--- a/scripts/dng.bat.in
+++ b/scripts/dng.bat.in
@@ -27,5 +27,5 @@ echo Starting DNG in %BIN_DIR%
 
 set DNG_ROOT=%BIN_DIR%\..
 set PATH=%BIN_DIR%;%DNG_ROOT%\@LIBDIR@\Release;%DNG_ROOT%\@LIBDIR@;%DNG_ROOT%\bin\Release;%PATH%
-REM type %DNG_ROOT%\@LIBDIR@\openstructure\init.py | %BIN_DIR%@BUILD_TYPE@\gosty.exe ost %*
-type "%DNG_ROOT%\@LIBDIR@\openstructure\init.py" | "%BIN_DIR%Release\gosty.exe" ost %*
+REM "%BIN_DIR%Release\gosty.exe" %DNG_ROOT%\@LIBDIR@\openstructure\init.py ost %*
+"%BIN_DIR%Release\gosty.exe" "%DNG_ROOT%\@LIBDIR@\openstructure\init.py" ost %*
diff --git a/scripts/dng.in b/scripts/dng.in
index 1a5c4e33e..809ee5f93 100755
--- a/scripts/dng.in
+++ b/scripts/dng.in
@@ -30,4 +30,4 @@ export LD_LIBRARY_PATH=$DNG_ROOT/@LIBDIR@:$LD_LIBRARY_PATH
 #export PYTHONHOME=$DNG_ROOT
 #export QT_PLUGIN_PATH=$BIN_DIR/plugins
 
-cat "$DNG_ROOT/@LIBDIR@/openstructure/init.py" | gosty ost $@
\ No newline at end of file
+gosty $DNG_ROOT/@LIBDIR@/openstructure/init.py ost $@
diff --git a/scripts/gipltng.bat.in b/scripts/gipltng.bat.in
index d57678355..c2dabf029 100644
--- a/scripts/gipltng.bat.in
+++ b/scripts/gipltng.bat.in
@@ -27,4 +27,4 @@ echo %BIN_DIR%
 
 set DNG_ROOT=%BIN_DIR%\..
 set PATH=%BIN_DIR%;%DNG_ROOT%\@LIBDIR@\Release;%DNG_ROOT%\@LIBDIR@;%DNG_ROOT%\bin\Release;%PATH%
-type "%DNG_ROOT%\@LIBDIR@\openstructure\init_iplt.py" | "%BIN_DIR%Release\gosty.exe" ost %*
+"%BIN_DIR%Release\gosty.exe" "%DNG_ROOT%\@LIBDIR@\openstructure\init_iplt.py" ost %*
diff --git a/scripts/gipltng.in b/scripts/gipltng.in
index a989d80b0..0c30b759c 100755
--- a/scripts/gipltng.in
+++ b/scripts/gipltng.in
@@ -34,4 +34,4 @@ export LD_LIBRARY_PATH=$DNG_ROOT/@LIBDIR@:$LD_LIBRARY_PATH
 # line. If the HERE documnt is fed directly into gosty, the backtrace shows the 
 # full command in case of a segfault which is very confusing and not helpful 
 # at all
-cat $DNG_ROOT/@LIBDIR@/openstructure/init_img.py| gosty img $@
+gosty $DNG_ROOT/@LIBDIR@/openstructure/init_iplt.py img $@
diff --git a/scripts/init.py b/scripts/init.py
index 08f538045..066e3fb74 100644
--- a/scripts/init.py
+++ b/scripts/init.py
@@ -69,12 +69,12 @@ def _load_files():
   graphical_objects=[]
   try:
     for f in input_files:
-      is_pdb_file=False
-      for ext in ['.pdb', '.ent', '.ent.gz', '.pdb.gz']:
-        if f[0].endswith(ext):
-          is_pdb_file=True
-          break
-      if is_pdb_file:
+      is_pdb_file=False
+      for ext in ['.pdb', '.ent', '.ent.gz', '.pdb.gz']:
+        if f[0].endswith(ext):
+          is_pdb_file=True
+          break
+      if is_pdb_file:
         es=io.LoadPDB(f[0], load_multi=True)
         for i, e in enumerate(es):
           index+=1
@@ -247,4 +247,6 @@ if len(loading_list)!=0 or len(options.pdb_ids)!=0:
   _load_files()
   scene.Autoslab()
 if len(script_argv)!=0:
-  _execute_script()
\ No newline at end of file
+  _execute_script()
+
+a=2
-- 
GitLab