view mercurial/demandload.py @ 300:d3400605d246

hg init: when hardlinking, remove dirstate -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 hg init: when hardlinking, remove dirstate manifest hash: 48d32cdfe7eacf17b012226a884384e48377b0d8 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCqU5gywK+sNU5EO8RAmzxAJ4hQUt/qrIcPzuGHf5dazJkKc9wgwCgpqV/ zSC4SHAvJQ2VptJSSVCEOAg= =QVG+ -----END PGP SIGNATURE-----
author mpm@selenic.com
date Fri, 10 Jun 2005 00:25:04 -0800
parents 3db700146536
children f3abe0bdccdd
line wrap: on
line source

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