metrixpp.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #
  2. # Metrix++, Copyright 2009-2019, Metrix++ Project
  3. # Link: https://github.com/metrixplusplus/metrixplusplus
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. import time
  8. import sys
  9. import logging
  10. import os
  11. import subprocess
  12. import itertools
  13. import mpp.log
  14. import mpp.internal.loader
  15. def main():
  16. os.environ['METRIXPLUSPLUS_INSTALL_DIR'] = os.path.dirname(os.path.abspath(__file__))
  17. exemode = None
  18. if len(sys.argv[1:]) != 0:
  19. exemode = sys.argv[1]
  20. if exemode != "-R" and exemode != "-D":
  21. exemode = '-D' # TODO implement install and release mode
  22. # inject '-D' or '-R' option
  23. #profile_args = ['-m', 'cProfile']
  24. profile_args = []
  25. exit(subprocess.call(itertools.chain([sys.executable], profile_args, [sys.argv[0], '-D'], sys.argv[1:])))
  26. command = ""
  27. if len(sys.argv[1:]) > 1:
  28. command = sys.argv[2]
  29. loader = mpp.internal.loader.Loader()
  30. mpp_paths = []
  31. if 'METRIXPLUSPLUS_PATH' in os.environ.keys():
  32. mpp_paths = os.environ['METRIXPLUSPLUS_PATH'].split(os.pathsep)
  33. args = loader.load(command, mpp_paths, sys.argv[3:])
  34. exit_code = loader.run(args)
  35. loader.unload()
  36. return exit_code
  37. def start():
  38. ts = time.time()
  39. mpp.log.set_default_format()
  40. exit_code = main()
  41. time_spent = round((time.time() - ts), 2)
  42. if 'METRIXPLUSPLUS_TEST_GENERATE_GOLDS' in os.environ.keys() and \
  43. os.environ['METRIXPLUSPLUS_TEST_GENERATE_GOLDS'] == "True":
  44. time_spent = 1 # Constant value if under tests
  45. logging.warning("Done (" + str(time_spent) +" seconds). Exit code: " + str(exit_code))
  46. exit(exit_code)
  47. if __name__ == '__main__':
  48. start()