+++ /dev/null
-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/
-//
-
-#include <time.h>
-#include <sys/time.h>
-
-#include "utilities.h"
-
-#include <Launchers.hxx>
-
-using namespace std;
-
-static int Launchers_IsLoaded = 0;
-static PyObject * Launchers_module = 0;
-static char * Launchers_name="Launchers";
-
-PyThreadState *mainThreadState=0;
-
-PyThreadState * getMainThreadState(){
- PyInterpreterState *interp;
- PyThreadState *p;
- interp=PyInterpreterState_Head();
- for (interp = PyInterpreterState_Head(); interp != NULL; ){
- if(interp->next == NULL)break;
- interp=interp->next;
- }
- for (p = interp->tstate_head; p != NULL; ){
- if(p->next == NULL)break;
- p=p->next;
- }
- return p;
-}
-PyThreadState *acquireMainThread(){
- PyEval_AcquireLock();
- return PyThreadState_Swap(mainThreadState);
-}
-void releaseMainThread(PyThreadState *tstate){
- PyThreadState_Swap(tstate);
- PyEval_ReleaseLock();
-}
-
-void Launchers_assertInitialized() {
- MESSAGE("===========================================================");
- MESSAGE("Launchers_assertInitialized");
- MESSAGE("===========================================================");
- PyThreadState *_save;
- if( !Py_IsInitialized() ) {
- MESSAGE("===========================================================");
- MESSAGE("Py_Initialize()");
- MESSAGE("===========================================================");
- Py_Initialize();
- PyEval_InitThreads();
- PyEval_SaveThread();
- }
- if( !Launchers_IsLoaded ) {
- mainThreadState=getMainThreadState();
- _save=acquireMainThread();
- Launchers_module=PyImport_ImportModule(Launchers_name);
- if(!Launchers_module){
- PyErr_Print();
- return;
- }
- Py_INCREF(Launchers_module);
- Launchers_IsLoaded = 1;
- releaseMainThread(_save);
- }
-}
-
-PyObject * getLauncher(char* arg0) {
- PyObject *v;
- PyThreadState *_save;
- Launchers_assertInitialized();
- _save=acquireMainThread();
- v=PyObject_CallMethod(Launchers_module,"getLauncher","s",arg0);
- if(!v){
- PyErr_Print();
- return NULL;
- }
- releaseMainThread(_save);
- Py_INCREF(v);
- return v;
-}
-
-void Launcher_Slaunch(PyObject *self, char* arg1, char* arg2) {
- PyObject *v;
- PyThreadState *_save;
- Launchers_assertInitialized();
- _save=acquireMainThread();
- v=PyObject_CallMethod(self,"Slaunch","ss",arg1,arg2);
- if(!v){
- PyErr_Print();
- }
- releaseMainThread(_save);
-}
-
+++ /dev/null
-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/
-//
-#include <pthread.h> // must be before Python.h !
-#include <Python.h>
-#define elDEBUG 0
-
-PyObject * getLauncher(char* );
-void Launcher_Slaunch(PyObject * objId, char*, char* );
-
+++ /dev/null
-import os
-import Utils_Identity
-import ConfigParser
-
-class Config:
- defaults={'user':'','opt':''}
- def __init__(self):
- self.config=ConfigParser.ConfigParser(self.defaults)
- self.config.read(os.path.join(os.environ['HOME'],Utils_Identity.getapplipath(),'launchers.cfg'))
- def computers(self):
- return self.config.sections()
- def options(self,computer):
- if not self.config.has_section(computer):
- return self.defaults
- else:
- d={}
- for opt in self.config.options(computer):
- d[opt]=self.config.get(computer,opt)
- return d
-
-config=None
-def setConfig(conf):
- global config
- config=conf
-
-setConfig(Config())
-
-class Launcher:
- def Slaunch(self,computer,CMD):
- self.launch(computer,CMD.split())
-
-class SSH(Launcher):
- def launch(self,computer,CMD):
- print computer,CMD
- conf=config.options(computer)
- print conf
- command=["ssh",computer]
- if conf["user"]:
- command=command+['-l',conf["user"]]
- if conf["opt"]:
- command=command+string.split(conf["opt"])
- command=command+[os.path.join(Utils_Identity.getapplipath(),'runSession')]+CMD
- command=command+['>', "/tmp/" + CMD[1] + "_" + computer + ".log 2>&1"]
-
- print command
- pid = os.spawnvp(os.P_NOWAIT, command[0], command)
-
-launcher=None
-_register={}
-
-def register(name,klass):
- _register[name]=klass
-
-register("ssh",SSH())
-
-def setLauncher(name):
- global launcher
- launcher=_register[name]
-
-def getLauncher(computer):
- """
- Return a launcher for the computer
- If can be specified in config
- If not return the default one : launcher
- """
- conf=config.options(computer)
- name=conf.get("launcher","")
- return _register.get(name,launcher)
-
-setLauncher("ssh")
-
-try:
- # Try to import a plugin module (user defined) that
- # can define other launchers and register them
- # 1- define a class
- # 2- register it with : Launchers.register(name,klass)
- # 3- eventually set it as default one : Launchers.setLauncher(name)
- import pluginLauncher
-except:
- #import traceback
- #traceback.print_exc()
- print "----------------------------------------------------------"
- print " no user defined launcher, ssh used. (see Launchers.py) "
- print "----------------------------------------------------------"
- pass