jetpack_sdk_env.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. import sys
  5. import os
  6. def welcome():
  7. """
  8. Perform a bunch of sanity tests to make sure the Add-on SDK
  9. environment is sane, and then display a welcome message.
  10. """
  11. try:
  12. if sys.version_info[0] > 2:
  13. print ("Error: You appear to be using Python %d, but "
  14. "the Add-on SDK only supports the Python 2.x line." %
  15. (sys.version_info[0]))
  16. return
  17. import mozrunner
  18. if 'CUDDLEFISH_ROOT' not in os.environ:
  19. print ("Error: CUDDLEFISH_ROOT environment variable does "
  20. "not exist! It should point to the root of the "
  21. "Add-on SDK repository.")
  22. return
  23. env_root = os.environ['CUDDLEFISH_ROOT']
  24. bin_dir = os.path.join(env_root, 'bin')
  25. python_lib_dir = os.path.join(env_root, 'python-lib')
  26. path = os.environ['PATH'].split(os.path.pathsep)
  27. if bin_dir not in path:
  28. print ("Warning: the Add-on SDK binary directory %s "
  29. "does not appear to be in your PATH. You may "
  30. "not be able to run 'cfx' or other SDK tools." %
  31. bin_dir)
  32. if python_lib_dir not in sys.path:
  33. print ("Warning: the Add-on SDK python-lib directory %s "
  34. "does not appear to be in your sys.path, which "
  35. "is odd because I'm running from it." % python_lib_dir)
  36. if not mozrunner.__path__[0].startswith(env_root):
  37. print ("Warning: your mozrunner package is installed at %s, "
  38. "which does not seem to be located inside the Jetpack "
  39. "SDK. This may cause problems, and you may want to "
  40. "uninstall the other version. See bug 556562 for "
  41. "more information." % mozrunner.__path__[0])
  42. except Exception:
  43. # Apparently we can't get the actual exception object in the
  44. # 'except' clause in a way that's syntax-compatible for both
  45. # Python 2.x and 3.x, so we'll have to use the traceback module.
  46. import traceback
  47. _, e, _ = sys.exc_info()
  48. print ("Verification of Add-on SDK environment failed (%s)." % e)
  49. print ("Your SDK may not work properly.")
  50. return
  51. print ("Welcome to the Add-on SDK. For the docs, visit https://addons.mozilla.org/en-US/developers/docs/sdk/latest/")
  52. if __name__ == '__main__':
  53. welcome()