Python Script launcher extended to accomodate Chams.
* New: In VLSISAPD, in Configuration, add a new priority level UserFile to distinguish between the system configuration files and the user's configuration files (which take precedence). * New: In Hurricane, in Script (Python), improve the API to be able to support Chams (and remove the duplicate capability from it). Add separate functions to perform the initialize/run(s)/finalize cycle step by step. * Change: In CRL Core, rename real technology <hcmos9> to <hcmos9gp>, it's offcial name from CMP/ST. This is the 130nm. Move the reading of the symbolic & real technologies names from coriolisInit.py to helpers.__init__.py, to be shared with chamsInit.py. To avoid a clash of names inside of helpers, the two variables of techno.py are renamed "symbolicTechnology" and "realTechnology". Move python init system from crlcore/src/crlcore to crlcore/python. * New: In CRL Core, In Utilities, add site-packages/pharos to the PYTHONPATH. * Change: In Kite, move python init system from kite/src/init to kite/python.
This commit is contained in:
parent
c65a79b47c
commit
a7c4e8b02e
|
@ -32,6 +32,7 @@
|
|||
find_package(Libexecinfo REQUIRED)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(python)
|
||||
add_subdirectory(etc)
|
||||
add_subdirectory(cmake_modules)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
install ( DIRECTORY vsc200 DESTINATION ${SYS_CONF_DIR}/coriolis2 )
|
||||
install ( DIRECTORY scmos_deep_018 DESTINATION ${SYS_CONF_DIR}/coriolis2 )
|
||||
install ( DIRECTORY scn6m_deep_09 DESTINATION ${SYS_CONF_DIR}/coriolis2 )
|
||||
install ( DIRECTORY hcmos9 DESTINATION ${SYS_CONF_DIR}/coriolis2 )
|
||||
install ( DIRECTORY hcmos9gp DESTINATION ${SYS_CONF_DIR}/coriolis2 )
|
||||
|
||||
install ( FILES environment.alliance.xml DESTINATION ${SYS_CONF_DIR}/coriolis2 )
|
||||
install ( FILES technology.symbolic.xml DESTINATION ${SYS_CONF_DIR}/coriolis2 )
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- Mode:Python -*-
|
||||
|
||||
symbolicTechno = 'cmos'
|
||||
realTechno = 'hcmos9'
|
||||
realTechno = 'hcmos9gp'
|
||||
|
|
|
@ -86,40 +86,17 @@ def coriolisConfigure():
|
|||
|
||||
Cfg.Configuration.pushDefaultPriority ( Cfg.Parameter.Priority.ConfigurationFile )
|
||||
|
||||
technoFiles = [ helpers.sysConfDir+'/techno.conf' ]
|
||||
if os.getenv('HOME'):
|
||||
technoFiles += [ os.getenv('HOME')+'/.coriolis2/techno.py' ]
|
||||
technoFiles += [ os.getcwd()+'/.coriolis2/techno.py' ]
|
||||
|
||||
technoFiles.reverse()
|
||||
for technoFile in technoFiles:
|
||||
if os.path.isfile(technoFile):
|
||||
print ' - Loading \"%s\".' % helpers.truncPath(technoFile)
|
||||
execfile(technoFile,moduleGlobals)
|
||||
break
|
||||
if moduleGlobals.has_key('symbolicTechno'):
|
||||
helpers.symbolicTechno = symbolicTechno
|
||||
helpers.symbolicDir = os.path.join( helpers.sysConfDir, symbolicTechno )
|
||||
else:
|
||||
print '[ERROR] The symbolic technology name is not set. Using <cmos>.'
|
||||
if moduleGlobals.has_key('realTechno'):
|
||||
helpers.realTechno = realTechno
|
||||
helpers.realDir = os.path.join( helpers.sysConfDir, realTechno )
|
||||
else:
|
||||
print '[ERROR] The real technology name is not set. Using <hcmos9>.'
|
||||
|
||||
|
||||
confFiles = [ (helpers.sysConfDir+'/'+symbolicTechno+'/alliance.conf', SystemFile|AllianceHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/patterns.conf', SystemFile|PatternsHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/display.conf' , SystemFile|DisplayHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/misc.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/hMetis.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/nimbus.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/mauka.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/etesian.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/kite.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/stratus1.conf', SystemFile|ConfigurationHelper)
|
||||
, (helpers.sysConfDir+'/'+symbolicTechno+'/plugins.conf' , SystemFile|ConfigurationHelper)
|
||||
confFiles = [ (helpers.symbolicDir+'/alliance.conf', SystemFile|AllianceHelper)
|
||||
, (helpers.symbolicDir+'/patterns.conf', SystemFile|PatternsHelper)
|
||||
, (helpers.symbolicDir+'/display.conf' , SystemFile|DisplayHelper)
|
||||
, (helpers.symbolicDir+'/misc.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.symbolicDir+'/hMetis.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.symbolicDir+'/nimbus.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.symbolicDir+'/mauka.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.symbolicDir+'/etesian.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.symbolicDir+'/kite.conf' , SystemFile|ConfigurationHelper)
|
||||
, (helpers.symbolicDir+'/stratus1.conf', SystemFile|ConfigurationHelper)
|
||||
, (helpers.symbolicDir+'/plugins.conf' , SystemFile|ConfigurationHelper)
|
||||
]
|
||||
if os.getenv('HOME'):
|
||||
confFiles += [ (os.getenv('HOME')+'/.coriolis2/settings.py', 0) ]
|
||||
|
@ -136,6 +113,8 @@ def coriolisConfigure():
|
|||
Configuration.loadCompatXml()
|
||||
|
||||
for confFile, confFlags in confFiles:
|
||||
if confFile.endswith('settings.py'):
|
||||
Cfg.Configuration.pushDefaultPriority ( Cfg.Parameter.Priority.UserFile )
|
||||
try:
|
||||
if not os.path.isfile(confFile):
|
||||
if confFlags & SystemFile:
|
||||
|
@ -166,6 +145,9 @@ def coriolisConfigure():
|
|||
print ' <%s>' % confFile
|
||||
print ' Trying to continue anyway...'
|
||||
|
||||
if confFile.endswith('settings.py'):
|
||||
Cfg.Configuration.popDefaultPriority ()
|
||||
|
||||
Cfg.Configuration.popDefaultPriority ()
|
||||
|
||||
#sys.stdout.write(CRL.AllianceFramework.get().getEnvironment().getPrint())
|
|
@ -33,6 +33,7 @@ realTechno = 'hcmos9'
|
|||
realDir = None
|
||||
tab = None
|
||||
_trace = None
|
||||
moduleGlobals = globals()
|
||||
|
||||
|
||||
def stype ( o ): return str(type(o)).split("'")[1]
|
||||
|
@ -245,6 +246,37 @@ def setTraceLevel ( level ):
|
|||
return
|
||||
|
||||
|
||||
def initTechno ( quiet ):
|
||||
global realDir
|
||||
global realTechno
|
||||
global symbolicDir
|
||||
global symbolicTechno
|
||||
|
||||
technoFiles = [ sysConfDir+'/techno.conf' ]
|
||||
if os.getenv('HOME'):
|
||||
technoFiles += [ os.getenv('HOME')+'/.coriolis2/techno.py' ]
|
||||
technoFiles += [ os.getcwd()+'/.coriolis2/techno.py' ]
|
||||
|
||||
technoFiles.reverse()
|
||||
for technoFile in technoFiles:
|
||||
if os.path.isfile(technoFile):
|
||||
if not quiet: print ' - Loading \"%s\".' % truncPath(technoFile)
|
||||
execfile(technoFile,moduleGlobals)
|
||||
break
|
||||
if moduleGlobals.has_key('symbolicTechnology'):
|
||||
symbolicTechno = symbolicTechnology
|
||||
else:
|
||||
print '[ERROR] The symbolic technology name is not set. Using <cmos>.'
|
||||
if moduleGlobals.has_key('realTechnology'):
|
||||
realTechno = realTechnology
|
||||
else:
|
||||
print '[ERROR] The real technology name is not set. Using <hcmos9gp>.'
|
||||
|
||||
symbolicDir = os.path.join( sysConfDir, symbolicTechno )
|
||||
realDir = os.path.join( sysConfDir, realTechno )
|
||||
if not quiet: print ' - Technologies: %s+%s.' % (symbolicTechno,realTechno)
|
||||
|
||||
|
||||
def staticInitialization ( quiet=False ):
|
||||
global sysConfDir
|
||||
global symbolicDir
|
||||
|
@ -263,7 +295,7 @@ def staticInitialization ( quiet=False ):
|
|||
for path in sys.path:
|
||||
if reSysConfDir.match(path):
|
||||
sysConfDir = path
|
||||
if not quiet: print ' - <%s>' % sysConfDir
|
||||
#if not quiet: print ' - <%s>' % sysConfDir
|
||||
break
|
||||
|
||||
if not sysConfDir:
|
||||
|
@ -277,6 +309,5 @@ def staticInitialization ( quiet=False ):
|
|||
, 'The path is something ending by <.../etc/coriolis2>.'] )
|
||||
|
||||
if not quiet: print ' - <%s>' % sysConfDir
|
||||
symbolicDir = os.path.join( sysConfDir, symbolicTechno )
|
||||
realDir = os.path.join( sysConfDir, realTechno )
|
||||
initTechno( quiet )
|
||||
return
|
|
@ -1,5 +1,4 @@
|
|||
add_subdirectory(ccore)
|
||||
add_subdirectory(pyCRL)
|
||||
add_subdirectory(crlcore)
|
||||
add_subdirectory(cyclop)
|
||||
add_subdirectory(x2y)
|
||||
|
|
|
@ -310,12 +310,14 @@ namespace CRL {
|
|||
Utilities::Path crlcoreDir = pythonSitePackages / "crlcore";
|
||||
Utilities::Path stratusDir = pythonSitePackages / "stratus";
|
||||
Utilities::Path cumulusDir = pythonSitePackages / "cumulus";
|
||||
Utilities::Path pharosDir = pythonSitePackages / "pharos";
|
||||
|
||||
Isobar::Script::addPath ( sysConfDir.string() );
|
||||
Isobar::Script::addPath ( pythonSitePackages.string() );
|
||||
Isobar::Script::addPath ( crlcoreDir.string() );
|
||||
Isobar::Script::addPath ( stratusDir.string() );
|
||||
Isobar::Script::addPath ( cumulusDir.string() );
|
||||
Isobar::Script::addPath ( pharosDir.string() );
|
||||
|
||||
// Triggers Configuration singleton creation.
|
||||
Cfg::Configuration::get ();
|
||||
|
@ -475,12 +477,12 @@ namespace CRL {
|
|||
}
|
||||
|
||||
// Delayed printing, as we known only now whether VerboseLevel1 is requested.
|
||||
if ( cmess1.enabled() ) {
|
||||
cmess1 << " o Reading Configuration. " << endl;
|
||||
if (systemConfFound) cmess1 << " - <" << systemConfFile.string() << ">." << endl;
|
||||
if (homeConfFound) cmess1 << " - <" << homeConfFile.string() << ">." << endl;
|
||||
if (dotConfFound) cmess1 << " - <" << dotConfFile.string() << ">." << endl;
|
||||
}
|
||||
//if ( cmess1.enabled() ) {
|
||||
// cmess1 << " o Reading Configuration. " << endl;
|
||||
// if (systemConfFound) cmess1 << " - <" << systemConfFile.string() << ">." << endl;
|
||||
// if (homeConfFound) cmess1 << " - <" << homeConfFile.string() << ">." << endl;
|
||||
// if (dotConfFound) cmess1 << " - <" << dotConfFile.string() << ">." << endl;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -*- C++ -*-
|
||||
//
|
||||
// This file is part of the Coriolis Software.
|
||||
// Copyright (c) UPMC/LIP6 2010-2014, All Rights Reserved
|
||||
// Copyright (c) UPMC 2010-2014, All Rights Reserved
|
||||
//
|
||||
// +-----------------------------------------------------------------+
|
||||
// | C O R I O L I S |
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
|
||||
// -*- C++ -*-
|
||||
//
|
||||
// This file is part of the Coriolis Software.
|
||||
// Copyright (c) UPMC/LIP6 2010-2012, All Rights Reserved
|
||||
// Copyright (c) UPMC 2010-2014, All Rights Reserved
|
||||
//
|
||||
// +-----------------------------------------------------------------+
|
||||
// | C O R I O L I S |
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
// -*- C++ -*-
|
||||
//
|
||||
// Copyright (c) BULL S.A. 2000-2009, All Rights Reserved
|
||||
// Copyright (c) BULL S.A. 2000-2014, All Rights Reserved
|
||||
//
|
||||
// This file is part of Hurricane.
|
||||
//
|
||||
|
@ -21,10 +20,7 @@
|
|||
//
|
||||
// ===================================================================
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// x-----------------------------------------------------------------x
|
||||
// | |
|
||||
// +-----------------------------------------------------------------+
|
||||
// | H U R R I C A N E |
|
||||
// | V L S I B a c k e n d D a t a - B a s e |
|
||||
// | |
|
||||
|
@ -32,10 +28,7 @@
|
|||
// | E-mail : Jean-Paul.Chaput@lip6.fr |
|
||||
// | =============================================================== |
|
||||
// | C++ Module : "./DbU.cpp" |
|
||||
// | *************************************************************** |
|
||||
// | U p d a t e s |
|
||||
// | |
|
||||
// x-----------------------------------------------------------------x
|
||||
// +-----------------------------------------------------------------+
|
||||
|
||||
|
||||
#include <cstring>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
// -*- C++ -*-
|
||||
//
|
||||
// Copyright (c) BULL S.A. 2000-2009, All Rights Reserved
|
||||
// Copyright (c) BULL S.A. 2000-2014, All Rights Reserved
|
||||
//
|
||||
// This file is part of Hurricane.
|
||||
//
|
||||
|
@ -21,10 +20,7 @@
|
|||
//
|
||||
// ===================================================================
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// x-----------------------------------------------------------------x
|
||||
// | |
|
||||
// +-----------------------------------------------------------------+
|
||||
// | H U R R I C A N E |
|
||||
// | V L S I B a c k e n d D a t a - B a s e |
|
||||
// | |
|
||||
|
@ -32,14 +28,11 @@
|
|||
// | E-mail : Jean-Paul.Chaput@lip6.fr |
|
||||
// | =============================================================== |
|
||||
// | C++ Header : "./hurricane/DbU.h" |
|
||||
// | *************************************************************** |
|
||||
// | U p d a t e s |
|
||||
// | |
|
||||
// x-----------------------------------------------------------------x
|
||||
// +-----------------------------------------------------------------+
|
||||
|
||||
|
||||
#ifndef __HURRICANE_DBU__
|
||||
#define __HURRICANE_DBU__
|
||||
#ifndef HURRICANE_DBU_H
|
||||
#define HURRICANE_DBU_H
|
||||
|
||||
|
||||
#include <cmath>
|
||||
|
@ -150,13 +143,13 @@ namespace Hurricane {
|
|||
// New converter naming scheme.
|
||||
inline DbU::Unit DbU::fromDb ( long value ) { return value; }
|
||||
inline DbU::Unit DbU::fromGrid ( double value ) { return (long)rint( value/_resolution ); }
|
||||
inline DbU::Unit DbU::fromLambda ( double value ) { return grid(value*_gridsPerLambda); }
|
||||
inline DbU::Unit DbU::fromPhysical ( double value, UnitPower p ) { return grid((value*getUnitPower(p))/_physicalsPerGrid); }
|
||||
inline DbU::Unit DbU::fromLambda ( double value ) { return fromGrid(value*_gridsPerLambda); }
|
||||
inline DbU::Unit DbU::fromPhysical ( double value, UnitPower p ) { return fromGrid((value*getUnitPower(p))/_physicalsPerGrid); }
|
||||
inline long DbU::toDb ( DbU::Unit u ) { return u; }
|
||||
inline double DbU::toGrid ( DbU::Unit u ) { return _resolution*(double)u; }
|
||||
inline double DbU::toGrid ( double u ) { return _resolution*u; }
|
||||
inline double DbU::toLambda ( DbU::Unit u ) { return getGrid(u)/_gridsPerLambda; }
|
||||
inline double DbU::toLambda ( double u ) { return getGrid(u)/_gridsPerLambda; }
|
||||
inline double DbU::toLambda ( DbU::Unit u ) { return toGrid(u)/_gridsPerLambda; }
|
||||
inline double DbU::toLambda ( double u ) { return toGrid(u)/_gridsPerLambda; }
|
||||
inline double DbU::toPhysical ( DbU::Unit u, UnitPower p ) { return (_physicalsPerGrid*_resolution*(double)u)/getUnitPower(p); }
|
||||
inline double DbU::toPhysical ( double u, UnitPower p ) { return (_physicalsPerGrid*_resolution*u)/getUnitPower(p); }
|
||||
|
||||
|
@ -181,4 +174,4 @@ namespace Hurricane {
|
|||
} // End of Hurricane namespace.
|
||||
|
||||
|
||||
#endif // __HURRICANE_DBU__
|
||||
#endif // HURRICANE_DBU_H
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -*- C++ -*-
|
||||
//
|
||||
// This file is part of the Coriolis Software.
|
||||
// Copyright (c) UPMC/LIP6 2008-2014, All Rights Reserved
|
||||
// Copyright (c) UPMC 2008-2014, All Rights Reserved
|
||||
//
|
||||
// +-----------------------------------------------------------------+
|
||||
// | C O R I O L I S |
|
||||
|
|
|
@ -23,15 +23,6 @@
|
|||
#include "hurricane/viewer/Script.h"
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
#if THIS_IS_DISABLED
|
||||
const char* __editorKw = "__editor";
|
||||
#endif
|
||||
|
||||
} // End of anonymous namespace.
|
||||
|
||||
|
||||
namespace Isobar {
|
||||
|
||||
using std::string;
|
||||
|
@ -63,7 +54,9 @@ namespace Isobar {
|
|||
|
||||
|
||||
Script::Script ( const string& name )
|
||||
: _moduleName (name)
|
||||
: _initModuleNames()
|
||||
, _initModules ()
|
||||
, _moduleName (name)
|
||||
, _sysModule (NULL)
|
||||
, _hurricaneModule(NULL)
|
||||
, _userModule (NULL)
|
||||
|
@ -71,9 +64,6 @@ namespace Isobar {
|
|||
, _pyArgs (NULL)
|
||||
, _pyKw (NULL)
|
||||
, _pyResult (NULL)
|
||||
#if THIS_IS_DISABLED
|
||||
, _cellViewer (NULL)
|
||||
#endif
|
||||
, _globalState (NULL)
|
||||
, _subInterpreter (NULL)
|
||||
, _flags (0)
|
||||
|
@ -81,10 +71,7 @@ namespace Isobar {
|
|||
|
||||
|
||||
Script::~Script ()
|
||||
{
|
||||
_finalize();
|
||||
//Py_Finalize ();
|
||||
}
|
||||
{ finalize(); }
|
||||
|
||||
|
||||
Script* Script::create ( const std::string& name )
|
||||
|
@ -100,45 +87,49 @@ namespace Isobar {
|
|||
}
|
||||
|
||||
|
||||
#if THIS_IS_DISABLED
|
||||
void Script::setEditor ( CellViewer* viewer )
|
||||
{ _cellViewer = viewer; }
|
||||
#endif
|
||||
void Script::setUserModuleName ( const std::string& name )
|
||||
{
|
||||
finalize();
|
||||
_moduleName = name;
|
||||
}
|
||||
|
||||
|
||||
bool Script::addInitModuleName ( std::string name )
|
||||
{
|
||||
for ( auto moduleName : _initModuleNames ) {
|
||||
if (name == moduleName) return false;
|
||||
}
|
||||
_initModuleNames.push_back( name );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
PyObject* Script::getFunction ( std::string function )
|
||||
{
|
||||
if (not _userModule) return NULL;
|
||||
|
||||
PyObject* pyFunction = PyObject_GetAttrString( _userModule, const_cast<char*>(function.c_str()) );
|
||||
if ( (pyFunction == NULL) or not PyCallable_Check(pyFunction) )
|
||||
return NULL;
|
||||
|
||||
return pyFunction;
|
||||
}
|
||||
|
||||
|
||||
bool Script::runFunction ( const std::string& function, Cell* cell, unsigned int flags )
|
||||
{
|
||||
bool returnCode = true;
|
||||
|
||||
_initialize();
|
||||
|
||||
_userModule = PyImport_ImportModule( const_cast<char*>(_moduleName.c_str()) );
|
||||
|
||||
if (_userModule == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
}
|
||||
_finalize();
|
||||
throw Error( "Cannot load python module: %s",_moduleName.c_str() );
|
||||
}
|
||||
|
||||
#if THIS_IS_DISABLED
|
||||
_setEditor();
|
||||
#endif
|
||||
initialize();
|
||||
|
||||
_pyFunction = PyObject_GetAttrString( _userModule, const_cast<char*>(function.c_str()) );
|
||||
if ( (_pyFunction == NULL) or not PyCallable_Check(_pyFunction) ) {
|
||||
_finalize();
|
||||
finalize();
|
||||
throw Error( "Python module %s doesn't contains any %s function."
|
||||
, _moduleName.c_str(),function.c_str());
|
||||
}
|
||||
|
||||
_pyArgs = PyTuple_New( 0 );
|
||||
#if THIS_IS_DISABLED
|
||||
if (cell != NULL) addKwArgument( "cell" , (PyObject*)PyCell_Link(cell) );
|
||||
if (_cellViewer != NULL) addKwArgument( "editor", (PyObject*)PyCellViewer_Link(_cellViewer) );
|
||||
#endif
|
||||
|
||||
_pyResult = PyObject_Call( _pyFunction, _pyArgs, _pyKw );
|
||||
_pyArgs = NULL;
|
||||
_pyKw = NULL;
|
||||
|
@ -152,22 +143,48 @@ namespace Isobar {
|
|||
returnCode = false;
|
||||
}
|
||||
|
||||
_finalize();
|
||||
finalize();
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
|
||||
void Script::_importSys ()
|
||||
PyObject* Script::callFunction ( const std::string& function, PyObject* pyArgs )
|
||||
{
|
||||
if ( not Py_IsInitialized() )
|
||||
throw Error ( "Script::_importSys(): Called before Py_Initialize()." );
|
||||
if (_userModule == NULL) {
|
||||
if (PyErr_Occurred()) PyErr_Print();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_sysModule = _importModule ( "sys" );
|
||||
_pyFunction = PyObject_GetAttrString( _userModule, const_cast<char*>(function.c_str()) );
|
||||
if ( (_pyFunction == NULL) or not PyCallable_Check(_pyFunction) ) {
|
||||
cerr << Error( "Python module %s doesn't contains any %s function."
|
||||
, _moduleName.c_str(),function.c_str()) << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_pyResult = PyObject_Call( _pyFunction, pyArgs, NULL );
|
||||
|
||||
if (_pyResult == NULL) {
|
||||
cerr << "Something has gone slightly wrong" << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyErr_Occurred()) PyErr_Print();
|
||||
|
||||
return _pyResult;
|
||||
}
|
||||
|
||||
|
||||
PyObject* Script::_importSys ( unsigned int flags )
|
||||
{
|
||||
_sysModule = _importModule( "sys", flags );
|
||||
|
||||
PyObject* path = PyObject_GetAttrString( _sysModule, "path" );
|
||||
if ( path == NULL )
|
||||
if (path == NULL) {
|
||||
if (flags & NoThrow) return NULL;
|
||||
throw Error("Script::_importSys(): No \"sys.path\" attribute.");
|
||||
}
|
||||
|
||||
vector<string>::iterator ipath = _pathes.begin();
|
||||
|
||||
|
@ -175,39 +192,35 @@ namespace Isobar {
|
|||
PyObject* element = PyString_FromString( const_cast<char*>((*ipath).c_str()) );
|
||||
PyList_Insert( path, 0, element );
|
||||
}
|
||||
|
||||
return _sysModule;
|
||||
}
|
||||
|
||||
|
||||
void Script::_importHurricane ()
|
||||
PyObject* Script::_importModule ( const string& moduleName, unsigned int flags )
|
||||
{
|
||||
if ( not Py_IsInitialized() )
|
||||
throw Error ( "Script::_importHurricane(): Called before Py_Initialize()." );
|
||||
if (not Py_IsInitialized()) {
|
||||
if (flags & NoThrow) return NULL;
|
||||
|
||||
_hurricaneModule = PyImport_ImportModule ( "Hurricane" );
|
||||
if ( _hurricaneModule == NULL )
|
||||
throw Error("Script::_importModule(): No Hurricane module.");
|
||||
|
||||
#if THIS_IS_DISABLED
|
||||
PyModule_AddObject ( _hurricaneModule, const_cast<char*>(__editorKw), Py_None );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PyObject* Script::_importModule ( const string& moduleName )
|
||||
{
|
||||
if ( not Py_IsInitialized() )
|
||||
throw Error( "Script::_importModule(): Called before Py_Initialize() while importing <%s>."
|
||||
, moduleName.c_str() );
|
||||
}
|
||||
|
||||
PyObject* module = PyImport_ImportModule( const_cast<char*>(moduleName.c_str()) );
|
||||
if ( module == NULL )
|
||||
throw Error("Script::_importModule(): No <%s> module.",moduleName.c_str());
|
||||
if (module == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
}
|
||||
if (flags & NoThrow) return NULL;
|
||||
|
||||
throw Error( "Script::_importModule(): Unable to load module <%s>.",moduleName.c_str() );
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
||||
void Script::_initialize ()
|
||||
bool Script::initialize ( unsigned int flags )
|
||||
{
|
||||
if (Py_IsInitialized()) {
|
||||
// Python is already running. Launch a sub-interpreter.
|
||||
|
@ -216,13 +229,27 @@ namespace Isobar {
|
|||
} else
|
||||
Py_Initialize();
|
||||
|
||||
if (not Py_IsInitialized()) {
|
||||
if (flags & NoThrow) return false;
|
||||
|
||||
throw Error( "Script::initialize(): Unable to initialize the Python interpreter (<%s>)."
|
||||
, _moduleName.c_str());
|
||||
}
|
||||
|
||||
_flags |= Initialized;
|
||||
_importSys ();
|
||||
_importHurricane();
|
||||
_importSys ( flags );
|
||||
|
||||
for ( auto moduleName : _initModuleNames )
|
||||
_initModules.push_back( _importModule(moduleName,flags) );
|
||||
|
||||
_importHurricane( flags );
|
||||
_importUser ( flags );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Script::_finalize ()
|
||||
void Script::finalize ()
|
||||
{
|
||||
if (not Py_IsInitialized()) return;
|
||||
if (not (_flags & Initialized)) return;
|
||||
|
@ -240,6 +267,14 @@ namespace Isobar {
|
|||
if ( _pyArgs != NULL ) { Py_DECREF ( _pyArgs ); }
|
||||
if ( _pyFunction != NULL ) { Py_DECREF ( _pyFunction ); }
|
||||
|
||||
for ( size_t i=0 ; i<_initModules.size() ; ++i ) {
|
||||
if (_initModules[i]) {
|
||||
Py_DECREF( _initModules[i] );
|
||||
_initModules[i] = NULL;
|
||||
}
|
||||
}
|
||||
_initModules.clear();
|
||||
|
||||
Py_Finalize ();
|
||||
|
||||
_userModule = NULL;
|
||||
|
@ -252,25 +287,6 @@ namespace Isobar {
|
|||
}
|
||||
|
||||
|
||||
#if THIS_IS_DISABLED
|
||||
void Script::_setEditor ()
|
||||
{
|
||||
if ( _userModule == NULL ) return;
|
||||
|
||||
PyObject* dictionary = PyModule_GetDict ( _userModule );
|
||||
|
||||
if ( _cellViewer != NULL ) {
|
||||
PyCellViewer* pyCellViewer = PyObject_NEW ( PyCellViewer, &PyTypeCellViewer );
|
||||
pyCellViewer->_object = _cellViewer;
|
||||
|
||||
PyDict_SetItemString ( dictionary, __editorKw, (PyObject*)pyCellViewer );
|
||||
} else {
|
||||
PyDict_SetItemString ( dictionary, __editorKw, Py_None );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void Script::addKwArgument ( const char* key, PyObject* object )
|
||||
{
|
||||
if (_pyKw == NULL) _pyKw = PyDict_New();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -*- C++ -*-
|
||||
//
|
||||
// This file is part of the Coriolis Software.
|
||||
// Copyright (c) UPMC/LIP6 2008-2014, All Rights Reserved
|
||||
// Copyright (c) UPMC 2008-2014, All Rights Reserved
|
||||
//
|
||||
// +-----------------------------------------------------------------+
|
||||
// | C O R I O L I S |
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
struct _object;
|
||||
typedef _object PyObject;
|
||||
}
|
||||
|
||||
namespace Hurricane {
|
||||
class Cell;
|
||||
class CellViewer;
|
||||
|
@ -30,22 +35,32 @@ namespace Isobar {
|
|||
|
||||
class Script {
|
||||
public:
|
||||
enum Flags { NoScriptArgs=0x1, Initialized=0x10 };
|
||||
enum Flags { NoFlags = 0x0000
|
||||
, NoScriptArgs = 0x0001
|
||||
, Initialized = 0x0002
|
||||
, NoThrow = 0x0004
|
||||
};
|
||||
public:
|
||||
static void addPath ( const std::string& path );
|
||||
static void removePath ( const std::string& path );
|
||||
static Script* create ( const std::string& name );
|
||||
static Script* create ( const std::string& name="" );
|
||||
void destroy ();
|
||||
inline std::string getUserModuleName () const;
|
||||
inline PyObject* getSysModule ();
|
||||
inline PyObject* getHurricaneModule ();
|
||||
inline PyObject* getUserModule ();
|
||||
#if THIS_IS_DISABLED
|
||||
void setEditor ( Hurricane::CellViewer* );
|
||||
#endif
|
||||
bool addInitModuleName ( std::string );
|
||||
void setUserModuleName ( const std::string& );
|
||||
PyObject* getFunction ( std::string function );
|
||||
bool runFunction ( const std::string& function, Hurricane::Cell* cell, unsigned int flags=0 );
|
||||
PyObject* callFunction ( const std::string& function, PyObject* pyArgs );
|
||||
void addKwArgument ( const char* key, PyObject* object );
|
||||
bool initialize ( unsigned int flags=NoFlags );
|
||||
void finalize ();
|
||||
protected:
|
||||
static std::vector<std::string> _pathes;
|
||||
std::vector<std::string> _initModuleNames;
|
||||
std::vector<PyObject*> _initModules;
|
||||
std::string _moduleName;
|
||||
PyObject* _sysModule;
|
||||
PyObject* _hurricaneModule;
|
||||
|
@ -54,9 +69,6 @@ namespace Isobar {
|
|||
PyObject* _pyArgs;
|
||||
PyObject* _pyKw;
|
||||
PyObject* _pyResult;
|
||||
#if THIS_IS_DISABLED
|
||||
Hurricane::CellViewer* _cellViewer;
|
||||
#endif
|
||||
PyThreadState* _globalState;
|
||||
PyThreadState* _subInterpreter;
|
||||
long _flags;
|
||||
|
@ -65,22 +77,25 @@ namespace Isobar {
|
|||
~Script ();
|
||||
Script ( const Script& );
|
||||
Script& operator= ( const Script& );
|
||||
void _importSys ();
|
||||
void _importHurricane ();
|
||||
PyObject* _importModule ( const std::string& );
|
||||
void _initialize ();
|
||||
void _finalize ();
|
||||
#if THIS_IS_DISABLED
|
||||
void _setEditor ();
|
||||
#endif
|
||||
PyObject* _importSys ( unsigned int flags );
|
||||
inline PyObject* _importHurricane ( unsigned int flags );
|
||||
inline PyObject* _importUser ( unsigned int flags );
|
||||
PyObject* _importModule ( const std::string&, unsigned int flags );
|
||||
};
|
||||
|
||||
|
||||
// Inline Methods.
|
||||
inline std::string Script::getUserModuleName () const { return _moduleName; }
|
||||
inline PyObject* Script::getSysModule () { return _sysModule; }
|
||||
inline PyObject* Script::getHurricaneModule () { return _hurricaneModule; }
|
||||
inline PyObject* Script::getUserModule () { return _userModule; }
|
||||
|
||||
inline PyObject* Script::_importHurricane ( unsigned int flags )
|
||||
{ return _hurricaneModule = _importModule("Hurricane",flags); }
|
||||
|
||||
inline PyObject* Script::_importUser ( unsigned int flags )
|
||||
{ return _userModule = _importModule(_moduleName,flags); }
|
||||
|
||||
|
||||
} // End of Isobar namespace.
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
endif(CHECK_DETERMINISM)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(python)
|
||||
add_subdirectory(cmake_modules)
|
||||
|
||||
if(BUILD_DOC)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
install ( FILES kiteInit.py DESTINATION ${PYTHON_SITE_PACKAGES}/kite )
|
|
@ -115,7 +115,5 @@
|
|||
install ( FILES ${includes}
|
||||
${mocIncludes}
|
||||
${pyIncludes} DESTINATION include/coriolis2/kite )
|
||||
install ( FILES init/kiteInit.py
|
||||
DESTINATION ${PYTHON_SITE_PACKAGES}/kite )
|
||||
|
||||
|
||||
|
|
|
@ -254,6 +254,7 @@ namespace Cfg {
|
|||
.value("UseDefault" ,Parameter::UseDefault)
|
||||
.value("ApplicationBuiltin",Parameter::ApplicationBuiltin)
|
||||
.value("ConfigurationFile" ,Parameter::ConfigurationFile)
|
||||
.value("UserFile" ,Parameter::UserFile)
|
||||
.value("CommandLine" ,Parameter::CommandLine)
|
||||
.value("Interactive" ,Parameter::Interactive)
|
||||
;
|
||||
|
|
|
@ -51,8 +51,9 @@ namespace Cfg {
|
|||
enum Priority { UseDefault = 0
|
||||
, ApplicationBuiltin = 1
|
||||
, ConfigurationFile = 2
|
||||
, CommandLine = 3
|
||||
, Interactive = 4
|
||||
, UserFile = 3
|
||||
, CommandLine = 4
|
||||
, Interactive = 5
|
||||
};
|
||||
typedef boost::function< void(Parameter*) > ParameterChangedCb_t;
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue