mercurial/demandload.py
author Thomas Arendsen Hein <thomas@intevation.de>
Mon, 27 Jun 2005 06:52:13 +0100
changeset 492 9bd468e36de3
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Use "kill $!" to kill running background processes. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Use "kill $!" to kill running background processes. manifest hash: 94563ef45ac0c8d15c9c827430f3d87380946434 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCv5QNW7P1GVgWeRoRAm+1AJwMopIWkvc/eG21mm/gbTrC9sCvhACePQl/ VOPdJKQxutQTCdAqA8iMzck= =7ejv -----END PGP SIGNATURE-----

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