[livecoding] r143 committed - - reloader.py: UpdateClass was doing class update events for both new ...

3 views
Skip to first unread message

livec...@googlecode.com

unread,
Mar 19, 2010, 3:30:12 AM3/19/10
to py-livecod...@googlegroups.com
Revision: 143
Author: richard.m.tew
Date: Fri Mar 19 00:29:58 2010
Log: - reloader.py: UpdateClass was doing class update events for both new
and existing classes, not creation events for the new ones. This is now
fixed.
http://code.google.com/p/livecoding/source/detail?r=143

Modified:
/trunk/namespace.py
/trunk/reloader.py

=======================================
--- /trunk/namespace.py Mon Feb 22 19:51:09 2010
+++ /trunk/namespace.py Fri Mar 19 00:29:58 2010
@@ -15,7 +15,7 @@
import unittest

logger = logging.getLogger("namespace")
-# logger.setLevel(logging.DEBUG)
+#logger.setLevel(logging.DEBUG)

class ScriptFile(object):
lastError = None
@@ -421,7 +421,7 @@
namespaceContributions.add(k)

if type(v) in (types.TypeType, types.ClassType):
- self.BroadcastClassCreationEvent(namespace, k, v)
+ self.BroadcastClassCreationEvent(v)
# print namespace, k, type(v)

scriptFile.SetNamespaceContributions(namespaceContributions)
=======================================
--- /trunk/reloader.py Sun Feb 21 17:06:02 2010
+++ /trunk/reloader.py Fri Mar 19 00:29:58 2010
@@ -8,6 +8,7 @@
import time

logger = logging.getLogger("reloader")
+#logger.setLevel(logging.DEBUG)

# TODO: rename 'namespace.py' to 'namespaces.py' ... need to think about
it...
import namespace as namespaces
@@ -288,7 +289,7 @@
continue

if newType is types.ClassType or newType is types.TypeType:
- self.UpdateClass(oldValue, newValue, globals_)
+ self.UpdateClass(scriptFile, oldValue, newValue, globals_)

# If there was an old value, it is updated.
if oldValue is not None:
@@ -320,12 +321,14 @@
scriptFile.AddNamespaceContributions(namespaceContributions)
newScriptFile.SetNamespaceContributions(namespaceContributions)

- def UpdateClass(self, value, newValue, globals_):
- if value is None or value is NonExistentValue:
- value = newValue
-
+ def UpdateClass(self, scriptFile, value, newValue, globals_):
logger.debug("Updating class %s:%s from %s:%s", value,
hex(id(value)), newValue, hex(id(newValue)))

+ if value is None or value is NonExistentValue:
+ authoritativeValue = newValue
+ else:
+ authoritativeValue = value
+
for attrName, attrValue in newValue.__dict__.iteritems():
if isinstance(attrValue, types.FunctionType):
attrValue = RebindFunction(attrValue, globals_)
@@ -339,22 +342,26 @@
if attrName in
("__doc__", "__dict__", "__module__", "__weakref__"):
continue

- if value is newValue:
+ if authoritativeValue is newValue:
continue

logger.debug("setting %s %s", attrName, attrValue)
- setattr(value, attrName, attrValue)
-
- if self.classUpdateCallback:
- try:
- if type(self.classUpdateCallback) is tuple:
- getattr(self.classUpdateCallback[0],
self.classUpdateCallback[1])(value)
- else:
- self.classUpdateCallback(value)
- except ReferenceError:
- self.classUpdateCallback = None
- except Exception:
- logger.exception("Error broadcasting class update")
+ setattr(authoritativeValue, attrName, attrValue)
+
+ if value is None or value is NonExistentValue:
+ scriptDirectory = self.FindDirectory(scriptFile.filePath)
+ scriptDirectory.BroadcastClassCreationEvent(newValue)
+ else:
+ if self.classUpdateCallback:
+ try:
+ if type(self.classUpdateCallback) is tuple:
+ getattr(self.classUpdateCallback[0],
self.classUpdateCallback[1])(value)
+ else:
+ self.classUpdateCallback(value)
+ except ReferenceError:
+ self.classUpdateCallback = None
+ except Exception:
+ logger.exception("Error broadcasting class update")

#
------------------------------------------------------------------------
# Leaked attribute support

Reply all
Reply to author
Forward
0 new messages