Initial revision
[blender.git] / intern / python / modules / mcf / utils / reloader.py
1 import sys, string
2
3 class Reloader:
4         '''
5         Class allows for reloading all modules imported
6         after the instance is created. Normally you will
7         use this by doing:
8                 import <anything you don't want reloaded>
9                 from mcf.utils import reloader
10                 <do testing and rewriting>
11                 reloader.go()
12         '''
13         def __init__(self):
14                 self.keys = sys.modules.keys()
15         def __call__(self, *args, **namedargs):
16                 done = []
17                 for key, val in sys.modules.items():
18                         if key not in self.keys:
19                                 try:
20                                         reload( val )
21                                         done.append( key )
22                                 except (ImportError):
23                                         print '''Couldn't reload module:''', key
24                                 except (TypeError): # for None's
25                                         # is a flag to prevent reloading
26                                         pass
27                 if done:
28                         print '''Reloaded:''', string.join( done, ', ')
29                 else:
30                         print '''No modules reloaded'''
31
32 # the default reloader...
33 go = Reloader()