Created
March 19, 2011 20:20
-
-
Save borntyping/877775 to your computer and use it in GitHub Desktop.
Command importer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys | |
commandlist = {} | |
for module in os.listdir(os.path.dirname(__file__)): | |
if module == '__init__.py' or module[-3:] != '.py': | |
continue | |
__import__(module[:-3], locals(), globals()) | |
name = 'tools.'+module[:-3] | |
print "Importing "+name+"..." | |
try: | |
commands = getattr(sys.modules[name], 'commands') | |
for key in commands.keys(): | |
if key in commandlist: continue | |
commandlist[key] = commands[key] | |
except AttributeError: | |
continue | |
print commandlist | |
del module, os, sys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment