-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpymodloader.py
97 lines (80 loc) · 2.88 KB
/
pymodloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import clr
clr.AddReference('OpenSim.Framework')
clr.AddReference('OpenSim.Region.Framework')
import sys
sys.path.append('/usr/lib/python2.6/') #'ScriptEngines/Lib') # stdlib seems to live here
from OpenSim.Region.Framework.Interfaces import IRegionModule
#import textcreate, pictureframe, toggleboxcolor, oukautil
import webframeserver
class PyReloader(IRegionModule):
upgradable = False
regpymods = [webframeserver] #textcreate, pictureframe, toggleboxcolor, oukautil]
reginstances = []
def Initialise(self, scene, configsource):
self.scene = scene
self.config = configsource
scene.AddCommand(self, "py-reload", "py-reload", "...", self.cmd_py_reload)
print self, 'initialised with', scene
def PostInitialise(self):
print self, 'post-initialise'
def Close(self):
print self, 'close'
def getname(self):
return "MyRegionModule"
Name = property(getname)
def isshared(self):
return False
IsSharedModule = property(isshared)
def cmd_py_reload(self, modname, args):
try:
self.reload(modname, args)
except Exception, e:
print 'err or'
import traceback
traceback.print_exc()
raise
def reload(self, modname, args):
print 'closing modules'
for ri in self.reginstances:
print "found", ri, "in reginstances"
if ri.Name in self.scene.Modules:
print "also found in modules, so marking removed"
ri.removed = True
print "removing", ri.Name, "from self.scene.Modules"
self.scene.Modules.Remove(ri.Name)
else:
print "not found in modules so not removing"
ri.Close()
self.reginstances[:] = []
print 'reloading modules & looking for region classes'
regclasses = []
for m in self.regpymods:
reload(m)
for name in dir(m):
o = getattr(m, name)
if name.startswith('_'):
continue
try:
x = issubclass(o, IRegionModule)
except TypeError:
pass
else:
if x and getattr(o, 'autoload', None):
print 'found', name
regclasses.append(o)
print 'instantiating found regions'
for klass in regclasses:
ri = klass()
ri.Initialise(self.scene, self.config)
self.scene.AddModule(ri.Name, ri)
print "register instance", ri
self.reginstances.append(ri)
ri.PostInitialise()
print 'reload done'
loader = None
def sceneinit(scene, config):
global loader
loader = PyReloader()
loader.Initialise(scene, config)
loader.PostInitialise()
loader.cmd_py_reload('', [])