util.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. import json
  9. import os
  10. import re
  11. import sys
  12. import subprocess
  13. def error(message):
  14. print(('Error: {}'.format(message)))
  15. exit(1)
  16. def warn(message):
  17. print(('Warning: {}'.format(message)))
  18. def execute_system_call(command, **kwargs):
  19. print(('Executing subprocess.check_call({})'.format(command)))
  20. try:
  21. subprocess.check_call(command, **kwargs)
  22. except subprocess.CalledProcessError as e:
  23. print((e.output))
  24. error('Executing subprocess.check_call({}) failed with error {}'.format(command, e))
  25. except FileNotFoundError as e:
  26. error("File Not Found - Failed to call {} with error {}".format(command, e))
  27. def safe_execute_system_call(command, **kwargs):
  28. print(('Executing subprocess.check_call({})'.format(command)))
  29. try:
  30. subprocess.check_call(command, **kwargs)
  31. except subprocess.CalledProcessError as e:
  32. print((e.output))
  33. warn('Executing subprocess.check_call({}) failed'.format(command))
  34. return e.returncode
  35. return 0