Quieter helpers initialisation, isderived() alternative to isinstance().
* New: In CRL.python.helpers, all methods make use of the quiet mode to allow completly silent initialisation. Introduce isderived() function to check the derivation relationship of two C++ encapsulated classes by Isobar. The Python isinstance do not work, all C++ wrapped classes are of the base type 'type'. isderived() uses the MRO mechanism (Method Resolution Order) as a workaround. I can't find in the documentation if it's the expected behavior or if i did miss something in when building my classes.
This commit is contained in:
parent
41856f8c50
commit
bdc474d7fc
|
@ -25,6 +25,7 @@ import re
|
||||||
import traceback
|
import traceback
|
||||||
import Hurricane
|
import Hurricane
|
||||||
|
|
||||||
|
quiet = False
|
||||||
sysConfDir = None
|
sysConfDir = None
|
||||||
ndaConfDir = None
|
ndaConfDir = None
|
||||||
symbolicTechno = 'cmos'
|
symbolicTechno = 'cmos'
|
||||||
|
@ -39,6 +40,13 @@ moduleGlobals = globals()
|
||||||
def stype ( o ): return str(type(o)).split("'")[1]
|
def stype ( o ): return str(type(o)).split("'")[1]
|
||||||
|
|
||||||
|
|
||||||
|
def isderived ( derived, base ):
|
||||||
|
btype = base.mro()[0]
|
||||||
|
for dtype in derived.mro():
|
||||||
|
if dtype == btype: return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def truncPath ( path ):
|
def truncPath ( path ):
|
||||||
if len(path) < 70: return path
|
if len(path) < 70: return path
|
||||||
return '.../'+os.sep.join(path.split(os.sep)[-4:])
|
return '.../'+os.sep.join(path.split(os.sep)[-4:])
|
||||||
|
@ -246,13 +254,16 @@ def setTraceLevel ( level ):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def initTechno ( quiet ):
|
def initTechno ( argQuiet ):
|
||||||
|
global quiet
|
||||||
global ndaConfDir
|
global ndaConfDir
|
||||||
global realDir
|
global realDir
|
||||||
global realTechno
|
global realTechno
|
||||||
global symbolicDir
|
global symbolicDir
|
||||||
global symbolicTechno
|
global symbolicTechno
|
||||||
|
|
||||||
|
quiet = argQuiet
|
||||||
|
|
||||||
technoFiles = [ sysConfDir+'/techno.conf' ]
|
technoFiles = [ sysConfDir+'/techno.conf' ]
|
||||||
if os.getenv('HOME'):
|
if os.getenv('HOME'):
|
||||||
technoFiles += [ os.getenv('HOME')+'/.coriolis2/techno.py' ]
|
technoFiles += [ os.getenv('HOME')+'/.coriolis2/techno.py' ]
|
||||||
|
|
|
@ -80,8 +80,10 @@ def runScript ( scriptPath, editor ):
|
||||||
|
|
||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
module = str(e).split()[-1]
|
module = str(e).split()[-1]
|
||||||
print '[ERROR] The <%s> script cannot be loaded.' % module
|
print '[ERROR] The <%s> script cannot be loaded.' % os.path.basename(scriptPath)
|
||||||
print ' Please check your design hierarchy.'
|
print ' Please check your design hierarchy or the Python syntax.'
|
||||||
|
print ' Error was:'
|
||||||
|
print ' %s\n' % e
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print '[ERROR] An exception occured while loading the Stratus script module:'
|
print '[ERROR] An exception occured while loading the Stratus script module:'
|
||||||
print ' <%s>\n' % (scriptPath)
|
print ' <%s>\n' % (scriptPath)
|
||||||
|
|
Loading…
Reference in New Issue