Package PyFoam :: Package Paraview :: Module ServermanagerWrapper
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Paraview.ServermanagerWrapper

 1  #  ICE Revision: $Id: ServermanagerWrapper.py 10792 2009-09-01 14:01:48Z bgschaid $  
 2  """ Wrapper class for the paraview servermanager 
 3   
 4  Sets up the servermanager to be used with OpenFOAM-Data. Especially makes sure that 
 5  the plugins for the OpenFOAM-Data are loaded""" 
 6   
 7  from math import sqrt 
 8  from paraview import servermanager 
 9  from PyFoam.Paraview import version 
10  if version()>=(3,6): 
11      from paraview import simple 
12       
13  from os import environ,path,uname 
14   
15  from PyFoam.Error import error 
16   
17 -class ServermanagerWrapper(object):
18 """Wrapper class for the servermanager 19 20 Load the plugins and build a connection""" 21
22 - def __init__(self):
23 """Sets up the Servermanager in such a way that it is usable 24 with OpenFOAM-data.""" 25 26 self.con=servermanager.Connect() 27 28 dyExt="so" 29 if uname()[0]=="Darwin": 30 dyExt="dylib" 31 elif uname()[0]=="Linux": 32 try: 33 import ctypes 34 lib=ctypes.CDLL(path.join(environ["FOAM_LIBBIN"],"libPV3FoamReader.so"),mode=ctypes.RTLD_GLOBAL) 35 except ImportError: 36 error("The Workaround for Linux-Systems won't work because there is no ctypes library") 37 38 plug1="libPV3FoamReader."+dyExt 39 plug2="libPV3FoamReader_SM."+dyExt 40 41 loaded=False 42 for p in environ["PV_PLUGIN_PATH"].split(":"): 43 if path.exists(path.join(p,plug1)): 44 if version()>=(3,6): 45 simple.LoadPlugin(path.join(p,plug1),ns=globals()) 46 try: 47 simple.LoadPlugin(path.join(p,plug2),ns=globals()) 48 except NameError: 49 print dir(self.module()) 50 pass 51 else: 52 servermanager.LoadPlugin(path.join(p,plug1)) 53 servermanager.LoadPlugin(path.join(p,plug2)) 54 loaded=True 55 break 56 57 if not loaded: 58 error("The plugin",plug1,"was not found in the PV_PLUGIN_PATH",environ["PV_PLUGIN_PATH"]) 59 if not "PV3FoamReader" in dir(servermanager.sources): 60 error("The plugin was not properly loaded. PV3FoamReader not found in the list of sources")
61
62 - def __getattr__(self,attr):
63 """Delegate Attributes to the servermanager-module""" 64 65 return getattr(servermanager,attr)
66
67 - def __setattr__(self,attr,val):
68 """Delegate Attributes to the servermanager-module""" 69 70 return setattr(servermanager,attr,val)
71
72 - def module(self):
73 """Return the actual module (for developing)""" 74 return servermanager
75