from functools import total_ordering import ee.tools import importlib import logging import pkgutil import sys def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) @total_ordering class Tool(object): def __init__(self, module_name, name): self.module_name = module_name self.name = name def __eq__(self, other): return self.name == other.name def __lt__(self, other): return self.name < other.name def find_tools(): prefix = ee.tools.__name__ + '.' ps = pkgutil.walk_packages(ee.tools.__path__, prefix) tools = [] for (module_loader, module_name, ispkg) in ps: name = module_name.replace(prefix, '').replace('_', '-') tools.append(Tool(module_name, name)) return sorted(tools) def main(): logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True tools = find_tools() name = sys.argv[1] del sys.argv[1] for t in tools: if t.name != name: continue sys.argv[0] = t.name importlib.import_module(t.module_name) exit(0) eprint("No such tool: {}".format(name)) exit(1) if __name__ == "__main__": main()