metrixpp.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 mpp.log
  26. import mpp.internal.loader
  27. def main():
  28. os.environ['METRIXPLUSPLUS_INSTALL_DIR'] = os.path.dirname(os.path.abspath(__file__))
  29. exemode = None
  30. if len(sys.argv[1:]) != 0:
  31. exemode = sys.argv[1]
  32. if exemode != "-R" and exemode != "-D":
  33. exemode = '-D' # TODO implement install and release mode
  34. # inject '-D' or '-R' option
  35. #profile_args = ['-m', 'cProfile']
  36. profile_args = []
  37. exit(subprocess.call(itertools.chain([sys.executable], profile_args, [sys.argv[0], '-D'], sys.argv[1:])))
  38. command = ""
  39. if len(sys.argv[1:]) > 1:
  40. command = sys.argv[2]
  41. loader = mpp.internal.loader.Loader()
  42. mpp_paths = []
  43. if 'METRIXPLUSPLUS_PATH' in os.environ.keys():
  44. mpp_paths = os.environ['METRIXPLUSPLUS_PATH'].split(os.pathsep)
  45. args = loader.load(command, mpp_paths, sys.argv[3:])
  46. exit_code = loader.run(args)
  47. loader.unload()
  48. return exit_code
  49. def start():
  50. ts = time.time()
  51. mpp.log.set_default_format()
  52. exit_code = main()
  53. time_spent = round((time.time() - ts), 2)
  54. if 'METRIXPLUSPLUS_TEST_GENERATE_GOLDS' in os.environ.keys() and \
  55. os.environ['METRIXPLUSPLUS_TEST_GENERATE_GOLDS'] == "True":
  56. time_spent = 1 # Constant value if under tests
  57. logging.warning("Done (" + str(time_spent) +" seconds). Exit code: " + str(exit_code))
  58. exit(exit_code)
  59. if __name__ == '__main__':
  60. start()