Removed some old stuff related to superReload and made ircs die before shutdown.

This commit is contained in:
Jeremy Fincher 2003-11-14 22:10:57 +00:00
parent 1961ff1f07
commit 296af52ed9

View File

@ -57,14 +57,8 @@ commandsProcessed = 0
# End Global Values.
###
try:
ignore(ircs)
except NameError:
ircs = []
try:
ignore(flushers)
except NameError:
flushers = [] # A periodic function will flush all these.
def flush():
@ -72,9 +66,6 @@ def flush():
for f in flushers:
f()
try:
ignore(tempvars)
except NameError:
tempvars = {} # A storage place for temporary variables that need to be
# globally accessible.
@ -96,127 +87,27 @@ def upkeep(): # Function to be run on occasion to do upkeep stuff.
debug.msg(msg, 'verbose')
return collected
def makeIrcsDie():
for irc in ircs[:]:
irc.die()
def startDying():
global dying
dying = True
atexit.register(upkeep)
atexit.register(makeIrcsDie)
atexit.register(startDying)
'''
def superReload(oldmodule):
###
# So here is how this baby works:
# Reload the module.
# Iterate through the old module, finding classes and functions that are
# also in the new module.
# Add an __getattribute__ or __getattr__ method to those classes that are
# present in the new module. This method will, when called, change
# the __class__ of the instance to point to the new class.
# Change the func_code, func_defaults, and func_doc of any functions or
# methods or generators we run across, just in case someone is holding
# a reference to them instead of calling them by name.
###
"""Reload a module and make objects auto-update."""
# reload(module) modifies module in-place, so we need a copy of its
# __dict__ to iterate through.
olddict = copy.copy(oldmodule.__dict__)
newmodule = reload(oldmodule)
newdict = newmodule.__dict__
for (name, oldvalue) in olddict.iteritems():
if name in newdict:
newvalue = newdict[name]
oldtype = type(oldvalue)
# We have to pass in newvalue because of Python scoping.
def updater(self, s, newvalue=newvalue):
# This function is to be an __getattr__ or __getattribute__.
try:
self.__class__ = newvalue
except:
debug.recoverableException()
try:
del self.__class__.__getattribute__
except AttributeError:
del self.__class__.__getattr__
return getattr(self, s)
if oldtype == types.TypeType and \
oldvalue.__module__ == newmodule.__name__:
# New-style classes support __getattribute__, which is
# called on *any* attribute access, so they get updated
# the first time they are used after a reload.
if not (issubclass(oldvalue, str) or \
issubclass(oldvalue, long) or \
issubclass(oldvalue, tuple)):
oldvalue.__getattribute__ = updater
elif oldtype == types.ClassType and\
oldvalue.__module__ == newmodule.__name__:
# Old-style classes can only use getattr, so they might not
# update right away. Hopefully they will, but to solve
# this problem I just use new-style classes.
oldvalue.__getattr__ = updater
elif oldtype == type(newvalue):
if oldtype == types.FunctionType or\
oldtype == types.GeneratorType:
oldvalue.func_code = newvalue.func_code
oldvalue.func_defaults = newvalue.func_defaults
oldvalue.func_doc = newvalue.func_doc
elif oldtype == types.MethodType:
oldfunc = oldvalue.im_func
newfunc = newvalue.im_func
oldfunc.func_code = newfunc.func_code
oldfunc.func_defaults = newfunc.func_defaults
oldfunc.func_doc = newfunc.func_doc
# Update the linecache, so tracebacks show the proper lines.
linecache.checkcache()
return newmodule
'''
try:
# This makes the module reload properly; we don't want to lose oldobjects
# on reload.
oldobjects
except NameError:
oldobjects = {}
def superReload(module):
"""Reloads a module hardcore. But kinda broken -- don't use it."""
def updateFunction(old, new, attrs):
"""Update all attrs in old to the same attrs in new."""
for name in attrs:
setattr(old, name, getattr(new, name))
for (name, object) in module.__dict__.iteritems():
# For every attribute of the old module, keep the object.
key = (module.__name__, name)
oldobjects.setdefault(key, []).append(object)
module = reload(module)
for name, newobj in module.__dict__.iteritems():
# For every attribute in the new module...
key = (module.__name__, name)
if key in oldobjects: # If the same attribute was in the old module...
for oldobj in oldobjects[key]:
# Give it the new attributes :)
if type(newobj) == types.ClassType:
toRemove = []
for k in oldobj.__dict__:
if k not in newobj.__dict__:
toRemove.append(k)
for k in toRemove:
del oldobj.__dict__[k]
oldobj.__dict__.update(newobj.__dict__)
# elif type(newobj) == types.TypeType:
# if hasattr(oldobj, '__dict__'):
# oldobj.__dict__.update(newobj.__dict__)
elif type(newobj) == types.FunctionType:
updateFunction(oldobj, newobj, ('func_code',
'func_defaults',
'func_doc'))
elif type(newobj) == types.MethodType:
updateFunction(oldobj.im_func, newobj.im_func,
('func_code', 'func_defaults', 'func_doc'))
return module
#################################################
#################################################
#################################################
## Don't even *think* about messing with this. ##
#################################################
#################################################
#################################################
##################################################
##################################################
##################################################
## Don't even *think* about messing with these. ##
##################################################
##################################################
##################################################
startup = False
testing = False
dying = False
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: