view mercurial/demandload.py @ 467:9d5447a366a7

Add version command -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Add version command Suggested by Arun Sharma manifest hash: 7fc056ffe45ee854f00e76916a560fba28c74a91 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCvQW+ywK+sNU5EO8RAqGQAJ91Eysw4tHVpOB7ICeN9hMF/p+lfQCgksmg TAKr5VNrw2wIZtSKjgQRqiA= =8w84 -----END PGP SIGNATURE-----
author mpm@selenic.com
date Fri, 24 Jun 2005 23:20:30 -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