metrixpp.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # Metrix++, Copyright 2009-2013, Metrix++ Project
  3. # Link: http://metrixplusplus.sourceforge.net
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. # Metrix++ is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Metrix++ is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import time
  20. import sys
  21. import logging
  22. import os
  23. import subprocess
  24. import itertools
  25. import core.log
  26. def main():
  27. os.environ['METRIXPLUSPLUS_INSTALL_DIR'] = os.path.dirname(os.path.abspath(__file__))
  28. available_tools = []
  29. for fname in os.listdir(os.path.join(os.environ['METRIXPLUSPLUS_INSTALL_DIR'], 'tools')):
  30. tool_name = os.path.splitext(fname)[0]
  31. if tool_name == '__init__':
  32. continue
  33. if tool_name not in available_tools:
  34. available_tools.append(tool_name)
  35. exemode = None
  36. if len(sys.argv[1:]) != 0:
  37. exemode = sys.argv[1]
  38. if exemode != "-R" and exemode != "-D":
  39. exemode = '-D' # TODO implement install and release mode
  40. # inject '-D' or '-R' option
  41. exit(subprocess.call(itertools.chain([sys.executable, sys.argv[0], '-D'], sys.argv[1:])))
  42. command = ""
  43. if len(sys.argv[1:]) > 1:
  44. command = sys.argv[2]
  45. if command not in available_tools:
  46. logging.error("Unknown action: " + str(command))
  47. print "Usage: %prog <action> --help"
  48. print " or: %prog <action> [options] -- [path 1] ... [path N]"
  49. print "where: actions are:"
  50. for each in available_tools:
  51. print "\t" + each
  52. return 1
  53. tool = __import__('tools', globals(), locals(), [command], -1)
  54. module_attr = tool.__getattribute__(command)
  55. class_attr = module_attr.__getattribute__('Tool')
  56. instance = class_attr.__new__(class_attr)
  57. instance.__init__()
  58. return instance.run(sys.argv[3:])
  59. if __name__ == '__main__':
  60. ts = time.time()
  61. core.log.set_default_format()
  62. exit_code = main()
  63. logging.warning("Exit code: " + str(exit_code) + ". Time spent: " + str(round((time.time() - ts), 2)) + " seconds. Done")
  64. exit(exit_code)