Added the possibility to take into account layout modifications in Python files without needing to restart Zope while in debug mode.

This commit is contained in:
Gaetan Delannay 2010-11-13 17:54:08 +01:00
parent 7dc55f23c2
commit 3fd2d62b30
2 changed files with 35 additions and 1 deletions

View file

@ -477,6 +477,16 @@ class Type:
if isinstance(self, Ref) and not self.isBack: if isinstance(self, Ref) and not self.isBack:
self.back.relationship = '%s_%s_rel' % (prefix, name) self.back.relationship = '%s_%s_rel' % (prefix, name)
def reload(self, klass, obj):
'''In debug mode, we want to reload layouts without restarting Zope.
So this method will prepare a "new", reloaded version of p_self,
that corresponds to p_self after a "reload" of its containing Python
module has been performed.'''
res = getattr(klass, self.name, None)
if not res: return self
res.init(self.name, klass, obj.getProductConfig().PROJECTNAME)
return res
def isMultiValued(self): def isMultiValued(self):
'''Does this type definition allow to define multiple values?''' '''Does this type definition allow to define multiple values?'''
res = False res = False

View file

@ -3,7 +3,7 @@
- mixins/ToolMixin is mixed in with the generated application Tool class.''' - mixins/ToolMixin is mixed in with the generated application Tool class.'''
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import os, os.path, types, mimetypes import os, os.path, sys, types, mimetypes
import appy.gen import appy.gen
from appy.gen import Type, String, Selection, Role from appy.gen import Type, String, Selection, Role
from appy.gen.utils import * from appy.gen.utils import *
@ -379,6 +379,24 @@ class BaseMixin:
res = sortedObjectsUids.index(obj.UID()) res = sortedObjectsUids.index(obj.UID())
return res return res
def isDebug(self):
'''Are we in debug mode ?'''
for arg in sys.argv:
if arg == 'debug-mode=on': return True
return False
def getClass(self, reloaded=False):
'''Returns the Appy class that dictates self's behaviour.'''
if not reloaded:
return self.getTool().getAppyClass(self.__class__.__name__)
else:
klass = self.appy().klass
moduleName = klass.__module__
exec 'import %s' % moduleName
exec 'reload(%s)' % moduleName
exec 'res = %s.%s' % (moduleName, klass.__name__)
return res
def getAppyType(self, name, asDict=False, className=None): def getAppyType(self, name, asDict=False, className=None):
'''Returns the Appy type named p_name. If no p_className is defined, the '''Returns the Appy type named p_name. If no p_className is defined, the
field is supposed to belong to self's class.''' field is supposed to belong to self's class.'''
@ -399,7 +417,13 @@ class BaseMixin:
(dict version) is given.''' (dict version) is given.'''
res = [] res = []
groups = {} # The already encountered groups groups = {} # The already encountered groups
# In debug mode, reload the module containing self's class.
debug = self.isDebug()
if debug:
klass = self.getClass(reloaded=True)
for appyType in self.getAllAppyTypes(): for appyType in self.getAllAppyTypes():
if debug:
appyType = appyType.reload(klass, self)
if appyType.page.name != pageName: continue if appyType.page.name != pageName: continue
if not appyType.isShowable(self, layoutType): continue if not appyType.isShowable(self, layoutType): continue
if not appyType.group: if not appyType.group: