diff --git a/crlcore/CMakeLists.txt b/crlcore/CMakeLists.txt index c4e59aaf..75ae2747 100644 --- a/crlcore/CMakeLists.txt +++ b/crlcore/CMakeLists.txt @@ -32,6 +32,7 @@ find_package(Libexecinfo REQUIRED) add_subdirectory(src) + add_subdirectory(python) add_subdirectory(etc) add_subdirectory(cmake_modules) diff --git a/crlcore/etc/CMakeLists.txt b/crlcore/etc/CMakeLists.txt index c0e29afe..8ef87b31 100644 --- a/crlcore/etc/CMakeLists.txt +++ b/crlcore/etc/CMakeLists.txt @@ -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 ) diff --git a/crlcore/etc/common/etesian.conf b/crlcore/etc/common/etesian.conf index e7d3880e..a1166cf9 100644 --- a/crlcore/etc/common/etesian.conf +++ b/crlcore/etc/common/etesian.conf @@ -29,9 +29,9 @@ layoutTable = \ , (TypeRule ,) , (TypeTitle , 'Etesian - Placer') - , (TypeOption, "etesian.uniformDensity" , "Uniform density" , 0 ) - , (TypeOption, "etesian.routingDriven" , "Routing driven" , 0 ) - , (TypeOption, "etesian.effort" , "Placement effort" , 1 ) - , (TypeOption, "etesian.graphics" , "Placement view" , 1 ) + , (TypeOption, "etesian.uniformDensity", "Uniform density" , 0 ) + , (TypeOption, "etesian.routingDriven" , "Routing driven" , 0 ) + , (TypeOption, "etesian.effort" , "Placement effort" , 1 ) + , (TypeOption, "etesian.graphics" , "Placement view" , 1 ) , (TypeRule ,) ) diff --git a/crlcore/etc/hcmos9/technology.conf b/crlcore/etc/hcmos9gp/technology.conf similarity index 100% rename from crlcore/etc/hcmos9/technology.conf rename to crlcore/etc/hcmos9gp/technology.conf diff --git a/crlcore/etc/techno.conf b/crlcore/etc/techno.conf index 04b409a5..4eae5fc1 100644 --- a/crlcore/etc/techno.conf +++ b/crlcore/etc/techno.conf @@ -1,4 +1,4 @@ # -*- Mode:Python -*- symbolicTechno = 'cmos' -realTechno = 'hcmos9' +realTechno = 'hcmos9gp' diff --git a/crlcore/src/crlcore/CMakeLists.txt b/crlcore/python/CMakeLists.txt similarity index 100% rename from crlcore/src/crlcore/CMakeLists.txt rename to crlcore/python/CMakeLists.txt diff --git a/crlcore/src/crlcore/coriolisInit.py b/crlcore/python/coriolisInit.py similarity index 73% rename from crlcore/src/crlcore/coriolisInit.py rename to crlcore/python/coriolisInit.py index 23143ba1..b22f23c9 100644 --- a/crlcore/src/crlcore/coriolisInit.py +++ b/crlcore/python/coriolisInit.py @@ -86,41 +86,18 @@ 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 .' - 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 .' - - - 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) ] else: @@ -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: @@ -165,6 +144,9 @@ def coriolisConfigure(): print '[ERROR] Mandatory symbol <%s> is missing in system configuration file:' % symbol print ' <%s>' % confFile print ' Trying to continue anyway...' + + if confFile.endswith('settings.py'): + Cfg.Configuration.popDefaultPriority () Cfg.Configuration.popDefaultPriority () diff --git a/crlcore/src/crlcore/helpers/Alliance.py b/crlcore/python/helpers/Alliance.py similarity index 100% rename from crlcore/src/crlcore/helpers/Alliance.py rename to crlcore/python/helpers/Alliance.py diff --git a/crlcore/src/crlcore/helpers/Configuration.py b/crlcore/python/helpers/Configuration.py similarity index 100% rename from crlcore/src/crlcore/helpers/Configuration.py rename to crlcore/python/helpers/Configuration.py diff --git a/crlcore/src/crlcore/helpers/Debug.py b/crlcore/python/helpers/Debug.py similarity index 100% rename from crlcore/src/crlcore/helpers/Debug.py rename to crlcore/python/helpers/Debug.py diff --git a/crlcore/src/crlcore/helpers/Display.py b/crlcore/python/helpers/Display.py similarity index 100% rename from crlcore/src/crlcore/helpers/Display.py rename to crlcore/python/helpers/Display.py diff --git a/crlcore/src/crlcore/helpers/Patterns.py b/crlcore/python/helpers/Patterns.py similarity index 100% rename from crlcore/src/crlcore/helpers/Patterns.py rename to crlcore/python/helpers/Patterns.py diff --git a/crlcore/src/crlcore/helpers/RealTechnology.py b/crlcore/python/helpers/RealTechnology.py similarity index 100% rename from crlcore/src/crlcore/helpers/RealTechnology.py rename to crlcore/python/helpers/RealTechnology.py diff --git a/crlcore/src/crlcore/helpers/SymbolicTechnology.py b/crlcore/python/helpers/SymbolicTechnology.py similarity index 100% rename from crlcore/src/crlcore/helpers/SymbolicTechnology.py rename to crlcore/python/helpers/SymbolicTechnology.py diff --git a/crlcore/src/crlcore/helpers/__init__.py b/crlcore/python/helpers/__init__.py similarity index 87% rename from crlcore/src/crlcore/helpers/__init__.py rename to crlcore/python/helpers/__init__.py index 33b3676b..8ffff234 100644 --- a/crlcore/src/crlcore/helpers/__init__.py +++ b/crlcore/python/helpers/__init__.py @@ -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 .' + if moduleGlobals.has_key('realTechnology'): + realTechno = realTechnology + else: + print '[ERROR] The real technology name is not set. Using .' + + 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 diff --git a/crlcore/src/crlcore/helpers/etesian.py b/crlcore/python/helpers/etesian.py similarity index 100% rename from crlcore/src/crlcore/helpers/etesian.py rename to crlcore/python/helpers/etesian.py diff --git a/crlcore/src/crlcore/helpers/hMetis.py b/crlcore/python/helpers/hMetis.py similarity index 100% rename from crlcore/src/crlcore/helpers/hMetis.py rename to crlcore/python/helpers/hMetis.py diff --git a/crlcore/src/crlcore/helpers/kite.py b/crlcore/python/helpers/kite.py similarity index 100% rename from crlcore/src/crlcore/helpers/kite.py rename to crlcore/python/helpers/kite.py diff --git a/crlcore/src/crlcore/helpers/mauka.py b/crlcore/python/helpers/mauka.py similarity index 100% rename from crlcore/src/crlcore/helpers/mauka.py rename to crlcore/python/helpers/mauka.py diff --git a/crlcore/src/crlcore/helpers/misc.py b/crlcore/python/helpers/misc.py similarity index 100% rename from crlcore/src/crlcore/helpers/misc.py rename to crlcore/python/helpers/misc.py diff --git a/crlcore/src/crlcore/helpers/nimbus.py b/crlcore/python/helpers/nimbus.py similarity index 100% rename from crlcore/src/crlcore/helpers/nimbus.py rename to crlcore/python/helpers/nimbus.py diff --git a/crlcore/src/crlcore/helpers/stratus1.py b/crlcore/python/helpers/stratus1.py similarity index 100% rename from crlcore/src/crlcore/helpers/stratus1.py rename to crlcore/python/helpers/stratus1.py diff --git a/crlcore/src/CMakeLists.txt b/crlcore/src/CMakeLists.txt index ef64edb9..6ea83480 100644 --- a/crlcore/src/CMakeLists.txt +++ b/crlcore/src/CMakeLists.txt @@ -1,5 +1,4 @@ add_subdirectory(ccore) add_subdirectory(pyCRL) -add_subdirectory(crlcore) add_subdirectory(cyclop) add_subdirectory(x2y) diff --git a/crlcore/src/ccore/Utilities.cpp b/crlcore/src/ccore/Utilities.cpp index a4dd2034..82b0cc26 100644 --- a/crlcore/src/ccore/Utilities.cpp +++ b/crlcore/src/ccore/Utilities.cpp @@ -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; + //} } diff --git a/crlcore/src/pyCRL/PyAllianceFramework.cpp b/crlcore/src/pyCRL/PyAllianceFramework.cpp index 7e5b984d..bbe5133e 100644 --- a/crlcore/src/pyCRL/PyAllianceFramework.cpp +++ b/crlcore/src/pyCRL/PyAllianceFramework.cpp @@ -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 | diff --git a/crlcore/src/pyCRL/crlcore/PyAllianceFramework.h b/crlcore/src/pyCRL/crlcore/PyAllianceFramework.h index f9428c07..28f68ee3 100644 --- a/crlcore/src/pyCRL/crlcore/PyAllianceFramework.h +++ b/crlcore/src/pyCRL/crlcore/PyAllianceFramework.h @@ -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 | diff --git a/hurricane/src/hurricane/DbU.cpp b/hurricane/src/hurricane/DbU.cpp index 2a76a011..e8c85af3 100644 --- a/hurricane/src/hurricane/DbU.cpp +++ b/hurricane/src/hurricane/DbU.cpp @@ -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 diff --git a/hurricane/src/hurricane/hurricane/DbU.h b/hurricane/src/hurricane/hurricane/DbU.h index 050c10d5..a1c6e717 100644 --- a/hurricane/src/hurricane/hurricane/DbU.h +++ b/hurricane/src/hurricane/hurricane/DbU.h @@ -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 @@ -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 diff --git a/hurricane/src/viewer/HApplication.cpp b/hurricane/src/viewer/HApplication.cpp index 4377e88b..eee573b4 100644 --- a/hurricane/src/viewer/HApplication.cpp +++ b/hurricane/src/viewer/HApplication.cpp @@ -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 | diff --git a/hurricane/src/viewer/Script.cpp b/hurricane/src/viewer/Script.cpp index 0cd78947..222f1142 100644 --- a/hurricane/src/viewer/Script.cpp +++ b/hurricane/src/viewer/Script.cpp @@ -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(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(_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(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 - + _pyArgs = PyTuple_New( 0 ); _pyResult = PyObject_Call( _pyFunction, _pyArgs, _pyKw ); _pyArgs = NULL; _pyKw = NULL; @@ -152,62 +143,84 @@ 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(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; + } - PyObject* path = PyObject_GetAttrString ( _sysModule, "path" ); - if ( path == 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 (flags & NoThrow) return NULL; throw Error("Script::_importSys(): No \"sys.path\" attribute."); + } vector::iterator ipath = _pathes.begin(); for ( ; ipath != _pathes.end() ; ++ipath ) { - PyObject* element = PyString_FromString ( const_cast((*ipath).c_str()) ); - PyList_Insert ( path, 0, element ); + PyObject* element = PyString_FromString( const_cast((*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."); + throw Error( "Script::_importModule(): Called before Py_Initialize() while importing <%s>." + , moduleName.c_str() ); + } -#if THIS_IS_DISABLED - PyModule_AddObject ( _hurricaneModule, const_cast(__editorKw), Py_None ); -#endif - } + PyObject* module = PyImport_ImportModule( const_cast(moduleName.c_str()) ); + if (module == NULL) { + if (PyErr_Occurred()) { + PyErr_Print(); + } + if (flags & NoThrow) return NULL; - - 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(moduleName.c_str()) ); - if ( module == NULL ) - throw Error("Script::_importModule(): No <%s> module.",moduleName.c_str()); + 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(); diff --git a/hurricane/src/viewer/hurricane/viewer/HApplication.h b/hurricane/src/viewer/hurricane/viewer/HApplication.h index ab7a6742..73394222 100644 --- a/hurricane/src/viewer/hurricane/viewer/HApplication.h +++ b/hurricane/src/viewer/hurricane/viewer/HApplication.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 | diff --git a/hurricane/src/viewer/hurricane/viewer/Script.h b/hurricane/src/viewer/hurricane/viewer/Script.h index ccbfe2d9..110ad9a0 100644 --- a/hurricane/src/viewer/hurricane/viewer/Script.h +++ b/hurricane/src/viewer/hurricane/viewer/Script.h @@ -19,6 +19,11 @@ #include +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 ); - void destroy (); - inline PyObject* getSysModule (); - inline PyObject* getHurricaneModule (); - inline PyObject* getUserModule (); -#if THIS_IS_DISABLED - void setEditor ( Hurricane::CellViewer* ); -#endif - bool runFunction ( const std::string& function, Hurricane::Cell* cell, unsigned int flags=0 ); - void addKwArgument ( const char* key, PyObject* object ); + static void addPath ( const std::string& path ); + static void removePath ( const std::string& path ); + static Script* create ( const std::string& name="" ); + void destroy (); + inline std::string getUserModuleName () const; + inline PyObject* getSysModule (); + inline PyObject* getHurricaneModule (); + inline PyObject* getUserModule (); + 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 _pathes; + std::vector _initModuleNames; + std::vector _initModules; std::string _moduleName; PyObject* _sysModule; PyObject* _hurricaneModule; @@ -54,32 +69,32 @@ namespace Isobar { PyObject* _pyArgs; PyObject* _pyKw; PyObject* _pyResult; -#if THIS_IS_DISABLED - Hurricane::CellViewer* _cellViewer; -#endif PyThreadState* _globalState; PyThreadState* _subInterpreter; long _flags; protected: - Script ( const std::string& name ); - ~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 + Script ( const std::string& name ); + ~Script (); + Script ( const Script& ); + Script& operator= ( const Script& ); + 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 PyObject* Script::getSysModule () { return _sysModule; } - inline PyObject* Script::getHurricaneModule () { return _hurricaneModule; } - inline PyObject* Script::getUserModule () { return _userModule; } + 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. diff --git a/kite/CMakeLists.txt b/kite/CMakeLists.txt index e181743d..05332ef8 100644 --- a/kite/CMakeLists.txt +++ b/kite/CMakeLists.txt @@ -36,6 +36,7 @@ endif(CHECK_DETERMINISM) add_subdirectory(src) + add_subdirectory(python) add_subdirectory(cmake_modules) if(BUILD_DOC) diff --git a/kite/python/CMakeLists.txt b/kite/python/CMakeLists.txt new file mode 100644 index 00000000..ced0049d --- /dev/null +++ b/kite/python/CMakeLists.txt @@ -0,0 +1,2 @@ + + install ( FILES kiteInit.py DESTINATION ${PYTHON_SITE_PACKAGES}/kite ) diff --git a/kite/src/init/kiteInit.py b/kite/python/kiteInit.py similarity index 100% rename from kite/src/init/kiteInit.py rename to kite/python/kiteInit.py diff --git a/kite/src/CMakeLists.txt b/kite/src/CMakeLists.txt index 2d83971a..de53f375 100644 --- a/kite/src/CMakeLists.txt +++ b/kite/src/CMakeLists.txt @@ -115,7 +115,5 @@ install ( FILES ${includes} ${mocIncludes} ${pyIncludes} DESTINATION include/coriolis2/kite ) - install ( FILES init/kiteInit.py - DESTINATION ${PYTHON_SITE_PACKAGES}/kite ) diff --git a/vlsisapd/src/configuration/src/PyConfiguration.cpp b/vlsisapd/src/configuration/src/PyConfiguration.cpp index 38c6f650..d1d018e6 100644 --- a/vlsisapd/src/configuration/src/PyConfiguration.cpp +++ b/vlsisapd/src/configuration/src/PyConfiguration.cpp @@ -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) ; diff --git a/vlsisapd/src/configuration/src/vlsisapd/configuration/Parameter.h b/vlsisapd/src/configuration/src/vlsisapd/configuration/Parameter.h index 505e4d34..0aabeb8d 100644 --- a/vlsisapd/src/configuration/src/vlsisapd/configuration/Parameter.h +++ b/vlsisapd/src/configuration/src/vlsisapd/configuration/Parameter.h @@ -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: