comparison upmana/mercurial/demandimport.py @ 121:496dbf12a6cb alpha

Traipse Alpha 'OpenRPG' {091030-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Cleaning up for Beta): Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree {091029} Changes made to server to start working with Element Tree. Changes made to Meta Server Lib. Prepping test work for a multi meta network page. Minor bug fixed with mini to gametree Zoom Mouse plugin added. {091030} Getting ready for Beta. Server needs debugging so Alpha remains bugged. Plugin UI code cleaned. Auto start works with a graphic, pop-up asks to enable or disable plugin. Update Manager now has a partially working Status Bar. Status Bar captures terminal text, so Merc out put is visible. Manifest.xml file, will be renamed, is now much cleaner. Debug Console has a clear button and a Report Bug button. Prep work for a Term2Win class in Debug Console. Known: Current Alpha fails in Windows.
author sirebral
date Fri, 30 Oct 2009 22:21:40 -0500
parents
children
comparison
equal deleted inserted replaced
120:d86e762a994f 121:496dbf12a6cb
1 # demandimport.py - global demand-loading of modules for Mercurial
2 #
3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
7
8 '''
9 demandimport - automatic demandloading of modules
10
11 To enable this module, do:
12
13 import demandimport; demandimport.enable()
14
15 Imports of the following forms will be demand-loaded:
16
17 import a, b.c
18 import a.b as c
19 from a import b,c # a will be loaded immediately
20
21 These imports will not be delayed:
22
23 from a import *
24 b = __import__(a)
25 '''
26
27 import __builtin__
28 _origimport = __import__
29
30 class _demandmod(object):
31 """module demand-loader and proxy"""
32 def __init__(self, name, globals, locals):
33 if '.' in name:
34 head, rest = name.split('.', 1)
35 after = [rest]
36 else:
37 head = name
38 after = []
39 object.__setattr__(self, "_data", (head, globals, locals, after))
40 object.__setattr__(self, "_module", None)
41 def _extend(self, name):
42 """add to the list of submodules to load"""
43 self._data[3].append(name)
44 def _load(self):
45 if not self._module:
46 head, globals, locals, after = self._data
47 mod = _origimport(head, globals, locals)
48 # load submodules
49 def subload(mod, p):
50 h, t = p, None
51 if '.' in p:
52 h, t = p.split('.', 1)
53 if not hasattr(mod, h):
54 setattr(mod, h, _demandmod(p, mod.__dict__, mod.__dict__))
55 elif t:
56 subload(getattr(mod, h), t)
57
58 for x in after:
59 subload(mod, x)
60
61 # are we in the locals dictionary still?
62 if locals and locals.get(head) == self:
63 locals[head] = mod
64 object.__setattr__(self, "_module", mod)
65
66 def __repr__(self):
67 if self._module:
68 return "<proxied module '%s'>" % self._data[0]
69 return "<unloaded module '%s'>" % self._data[0]
70 def __call__(self, *args, **kwargs):
71 raise TypeError("%s object is not callable" % repr(self))
72 def __getattribute__(self, attr):
73 if attr in ('_data', '_extend', '_load', '_module'):
74 return object.__getattribute__(self, attr)
75 self._load()
76 return getattr(self._module, attr)
77 def __setattr__(self, attr, val):
78 self._load()
79 setattr(self._module, attr, val)
80
81 def _demandimport(name, globals=None, locals=None, fromlist=None, level=None):
82 if not locals or name in ignore or fromlist == ('*',):
83 # these cases we can't really delay
84 return _origimport(name, globals, locals, fromlist)
85 elif not fromlist:
86 # import a [as b]
87 if '.' in name: # a.b
88 base, rest = name.split('.', 1)
89 # email.__init__ loading email.mime
90 if globals and globals.get('__name__', None) == base:
91 return _origimport(name, globals, locals, fromlist)
92 # if a is already demand-loaded, add b to its submodule list
93 if base in locals:
94 if isinstance(locals[base], _demandmod):
95 locals[base]._extend(rest)
96 return locals[base]
97 return _demandmod(name, globals, locals)
98 else:
99 if level is not None:
100 # from . import b,c,d or from .a import b,c,d
101 return _origimport(name, globals, locals, fromlist, level)
102 # from a import b,c,d
103 mod = _origimport(name, globals, locals)
104 # recurse down the module chain
105 for comp in name.split('.')[1:]:
106 if not hasattr(mod, comp):
107 setattr(mod, comp, _demandmod(comp, mod.__dict__, mod.__dict__))
108 mod = getattr(mod, comp)
109 for x in fromlist:
110 # set requested submodules for demand load
111 if not(hasattr(mod, x)):
112 setattr(mod, x, _demandmod(x, mod.__dict__, locals))
113 return mod
114
115 ignore = [
116 '_hashlib',
117 '_xmlplus',
118 'fcntl',
119 'win32com.gen_py',
120 'pythoncom',
121 # imported by tarfile, not available under Windows
122 'pwd',
123 'grp',
124 # imported by profile, itself imported by hotshot.stats,
125 # not available under Windows
126 'resource',
127 ]
128
129 def enable():
130 "enable global demand-loading of modules"
131 __builtin__.__import__ = _demandimport
132
133 def disable():
134 "disable global demand-loading of modules"
135 __builtin__.__import__ = _origimport
136