mercurial/demandload.py
author Bryan O'Sullivan <bos@serpentine.com>
Sun, 14 Aug 2005 21:33:09 -0800
changeset 907 652507dc9fce
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Modify init command to take an optional directory to set up. If the directory does not exist, it is created. If no directory is given, the current directory is used.

def demandload(scope, modules):
    class d:
        def __getattr__(self, name):
            mod = self.__dict__["mod"]
            scope = self.__dict__["scope"]
            scope[mod] = __import__(mod, scope, scope, [])
            return getattr(scope[mod], name)

    for m in modules.split():
        dl = d()
        dl.mod = m
        dl.scope = scope
        scope[m] = dl