123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import time
- import sys
- import logging
- import os
- import subprocess
- import itertools
- import core.log
- def main():
-
- os.environ['METRIXPLUSPLUS_INSTALL_DIR'] = os.path.dirname(os.path.abspath(__file__))
-
- available_tools = []
- for fname in os.listdir(os.path.join(os.environ['METRIXPLUSPLUS_INSTALL_DIR'], 'tools')):
- tool_name = os.path.splitext(fname)[0]
- if tool_name == '__init__':
- continue
- if tool_name not in available_tools:
- available_tools.append(tool_name)
- exemode = None
- if len(sys.argv[1:]) != 0:
- exemode = sys.argv[1]
- if exemode != "-R" and exemode != "-D":
- exemode = '-D'
-
- exit(subprocess.call(itertools.chain([sys.executable, sys.argv[0], '-D'], sys.argv[1:])))
- command = ""
- if len(sys.argv[1:]) > 1:
- command = sys.argv[2]
-
- if command not in available_tools:
- logging.error("Unknown action: " + str(command))
- print "Usage: %prog <action> --help"
- print " or: %prog <action> [options] -- [path 1] ... [path N]"
- print "where: actions are:"
- for each in available_tools:
- print "\t" + each
- return 1
- tool = __import__('tools', globals(), locals(), [command], -1)
- module_attr = tool.__getattribute__(command)
- class_attr = module_attr.__getattribute__('Tool')
- instance = class_attr.__new__(class_attr)
- instance.__init__()
- return instance.run(sys.argv[3:])
-
- if __name__ == '__main__':
- ts = time.time()
- core.log.set_default_format()
- exit_code = main()
- logging.warning("Exit code: " + str(exit_code) + ". Time spent: " + str(round((time.time() - ts), 2)) + " seconds. Done")
- exit(exit_code)
|