#!/usr/bin/env python # # This file is part of the Coriolis Software. # Copyright (c) UPMC 2014-2018, All Rights Reserved # # +-----------------------------------------------------------------+ # | C O R I O L I S | # | U n i c o r n - M a i n G U I | # | | # | Author : Jean-Paul CHAPUT | # | E-mail : Jean-Paul.Chaput@asim.lip6.fr | # | =============================================================== | # | Python : "./init/unicornInit.py" | # +-----------------------------------------------------------------+ try: import traceback import sys import os.path import helpers from helpers.io import ErrorMessage from helpers.io import WarningMessage import Viewer except ImportError, e: serror = str(e) if serror.startswith('No module named'): module = serror.split()[-1] print '[ERROR] The <%s> python module or symbol cannot be loaded.' % module print ' Please check the integrity of the package.' if str(e).find('cannot open shared object file'): library = serror.split(':')[0] print '[ERROR] The <%s> shared library cannot be loaded.' % library print ' Under RHEL 6, you must be under devtoolset-2.' print ' (scl enable devtoolset-2 bash)' sys.exit(1) except Exception, e: print '[ERROR] A strange exception occurred while loading the basic Coriolis/Python' print ' modules. Something may be wrong at Python/C API level.\n' print ' %s' % e sys.exit(2) def unicornConfigure ( **kw ): editor = None if kw.has_key('editor'): editor = kw['editor'] else: print ErrorMessage( 3, 'unicornConfigure.py: Must be run from a CellView derived class.' ) return cumulusDir = None for path in sys.path: if path.endswith('/cumulus'): cumulusDir = path if not cumulusDir: print ErrorMessage( 3, 'unicornConfigure.py: Cannot find in PYTHONPATH.' ) return pluginsDir = os.path.join( cumulusDir, 'plugins' ) if not os.path.isdir(pluginsDir): print ErrorMessage( 3, 'unicornConfigure.py: Cannot find directory:' \ , '<%s>' % pluginsDir ) return sys.path.append( pluginsDir ) if editor.hasMenu( 'plugins' ): print WarningMessage( 'The menu has already been created.' ) return #editor.addMenu( 'plugins', 'Plu&gins', Viewer.CellViewer.TopMenu ) moduleNames = [] for pluginFile in os.listdir( pluginsDir ): if pluginFile == "__init__.py": continue if not pluginFile.endswith('.py'): continue moduleNames.append( os.path.basename(pluginFile)[:-3] ) moduleNames.sort() for moduleName in moduleNames: try: module = __import__( moduleName, globals(), locals(), moduleName ) if not module.__dict__.has_key('unicornHook'): print WarningMessage( 'Plugin <%s> do not provides the unicornHook() method, skipped.' \ % moduleName ) continue module.__dict__['unicornHook']( **kw ) except ErrorMessage, e: print e helpers.showStackTrace( e.trace ) except Exception, e: helpers.showPythonTrace( __file__, e ) return