addon-sdk/source/python-lib/jetpack_sdk_env.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/python-lib/jetpack_sdk_env.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +import sys
     1.9 +import os
    1.10 +
    1.11 +def welcome():
    1.12 +    """
    1.13 +    Perform a bunch of sanity tests to make sure the Add-on SDK
    1.14 +    environment is sane, and then display a welcome message.
    1.15 +    """
    1.16 +
    1.17 +    try:
    1.18 +        if sys.version_info[0] > 2:
    1.19 +            print ("Error: You appear to be using Python %d, but "
    1.20 +                   "the Add-on SDK only supports the Python 2.x line." %
    1.21 +                   (sys.version_info[0]))
    1.22 +            return
    1.23 +
    1.24 +        import mozrunner
    1.25 +
    1.26 +        if 'CUDDLEFISH_ROOT' not in os.environ:
    1.27 +            print ("Error: CUDDLEFISH_ROOT environment variable does "
    1.28 +                   "not exist! It should point to the root of the "
    1.29 +                   "Add-on SDK repository.")
    1.30 +            return
    1.31 +
    1.32 +        env_root = os.environ['CUDDLEFISH_ROOT']
    1.33 +
    1.34 +        bin_dir = os.path.join(env_root, 'bin')
    1.35 +        python_lib_dir = os.path.join(env_root, 'python-lib')
    1.36 +        path = os.environ['PATH'].split(os.path.pathsep)
    1.37 +
    1.38 +        if bin_dir not in path:
    1.39 +            print ("Warning: the Add-on SDK binary directory %s "
    1.40 +                   "does not appear to be in your PATH. You may "
    1.41 +                   "not be able to run 'cfx' or other SDK tools." %
    1.42 +                   bin_dir)
    1.43 +
    1.44 +        if python_lib_dir not in sys.path:
    1.45 +            print ("Warning: the Add-on SDK python-lib directory %s "
    1.46 +                   "does not appear to be in your sys.path, which "
    1.47 +                   "is odd because I'm running from it." % python_lib_dir)
    1.48 +
    1.49 +        if not mozrunner.__path__[0].startswith(env_root):
    1.50 +            print ("Warning: your mozrunner package is installed at %s, "
    1.51 +                   "which does not seem to be located inside the Jetpack "
    1.52 +                   "SDK. This may cause problems, and you may want to "
    1.53 +                   "uninstall the other version. See bug 556562 for "
    1.54 +                   "more information." % mozrunner.__path__[0])
    1.55 +    except Exception:
    1.56 +        # Apparently we can't get the actual exception object in the
    1.57 +        # 'except' clause in a way that's syntax-compatible for both
    1.58 +        # Python 2.x and 3.x, so we'll have to use the traceback module.
    1.59 +
    1.60 +        import traceback
    1.61 +        _, e, _ = sys.exc_info()
    1.62 +        print ("Verification of Add-on SDK environment failed (%s)." % e)
    1.63 +        print ("Your SDK may not work properly.")
    1.64 +        return
    1.65 +
    1.66 +    print ("Welcome to the Add-on SDK. For the docs, visit https://addons.mozilla.org/en-US/developers/docs/sdk/latest/")
    1.67 +
    1.68 +if __name__ == '__main__':
    1.69 +    welcome()

mercurial