<commit_before>#!/usr/bin/env python

#
#    Copyright (c) 2013-2018 Nest Labs, Inc.
#    All rights reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

#
#    @file
#      This file implements a CLI for the Python-based Weave Device Manager
#

import sys
import os
import platform
import optparse
from optparse import OptionParser, Option, OptionValueError
import binascii
import shlex
import base64
import random
import textwrap
import string
from copy import copy
from cmd import Cmd
from string import lower

# Attempt to import the Weave Device Manager Python module. We might
# be lucky and find the module sitting in the same directory. More
# than likely, however, Python will need to look for it relative to
# the directory this script is in or relative to the WEAVE_HOME
# environment variable.
#
# The relative path will either likely be in:
#
#     lib/python/PACKAGE
#
# or:
#
#     lib/pythonPYTHON_VERSION/dist-packages/PACKAGE
#
# or:
#
#     lib/pythonPYTHON_VERSION/site-packages/PACKAGE

try:
    import WeaveDeviceMgr
except Exception:
    pyversion = sys.version[:3]

    pkgpythondirs = [ "python",
                      "lib/python/weave",
                      "lib/python" + pyversion + "/dist-packages/weave",
                      "lib/python" + pyversion + "/site-packages/weave" ]

    for pkgpythondir in pkgpythondirs:
        if os.environ.has_key("WEAVE_HOME"):
            pyweavepath = os.path.normpath(os.path.join(os.environ["WEAVE_HOME"], pkgpythondir))
        else:
            pyweavepath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", pkgpythondir))

        if os.path.exists(pyweavepath):
            # The path exists in the current SDK, go ahead and append it to
            # the Python module search path.

            sys.path.append(pyweavepath)

    # At this point, we've added any possible paths to search for
    # Python modules. Give it one last try.

    try:
        import WeaveDeviceMgr
    except Exception as ex:
        print ("Could not import the WeaveDeviceMgr module: %s" % (str(ex)))

        sys.exit(1)

# After solving the path problem for WeaveDeviceMgr above now try and import WeaveBleMgr.
if platform.system() == 'Darwin':
    from WeaveCoreBluetoothMgr import CoreBluetoothManager as BleManager
    from WeaveBleUtility import FAKE_CONN_OBJ_VALUE

if sys.platform.startswith('linux'):
    from WeaveBluezMgr import BluezManager as BleManager
    from WeaveBleUtility import FAKE_CONN_OBJ_VALUE<commit_msg>Improve exception output with line and func traceback fo Python WeaveDeviceMgr exception<commit_after>#!/usr/bin/env python

#
#    Copyright (c) 2013-2018 Nest Labs, Inc.
#    All rights reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

#
#    @file
#      This file implements a CLI for the Python-based Weave Device Manager
#

import sys
import os
import platform
import optparse
from optparse import OptionParser, Option, OptionValueError
import binascii
import shlex
import base64
import random
import textwrap
import traceback
import string
from copy import copy
from cmd import Cmd
from string import lower

# Attempt to import the Weave Device Manager Python module. We might
# be lucky and find the module sitting in the same directory. More
# than likely, however, Python will need to look for it relative to
# the directory this script is in or relative to the WEAVE_HOME
# environment variable.
#
# The relative path will either likely be in:
#
#     lib/python/PACKAGE
#
# or:
#
#     lib/pythonPYTHON_VERSION/dist-packages/PACKAGE
#
# or:
#
#     lib/pythonPYTHON_VERSION/site-packages/PACKAGE

try:
    import WeaveDeviceMgr
except Exception:
    pyversion = sys.version[:3]

    pkgpythondirs = [ "python",
                      "lib/python/weave",
                      "lib/python" + pyversion + "/dist-packages/weave",
                      "lib/python" + pyversion + "/site-packages/weave" ]

    for pkgpythondir in pkgpythondirs:
        if os.environ.has_key("WEAVE_HOME"):
            pyweavepath = os.path.normpath(os.path.join(os.environ["WEAVE_HOME"], pkgpythondir))
        else:
            pyweavepath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", pkgpythondir))

        if os.path.exists(pyweavepath):
            # The path exists in the current SDK, go ahead and append it to
            # the Python module search path.

            sys.path.append(pyweavepath)

    # At this point, we've added any possible paths to search for
    # Python modules. Give it one last try.

    try:
        import WeaveDeviceMgr
    except Exception as ex:
        print ("Could not import the WeaveDeviceMgr module: %s" % (str(ex)))
        print(traceback.format_exc())

        sys.exit(1)

# After solving the path problem for WeaveDeviceMgr above now try and import WeaveBleMgr.
if platform.system() == 'Darwin':
    from WeaveCoreBluetoothMgr import CoreBluetoothManager as BleManager
    from WeaveBleUtility import FAKE_CONN_OBJ_VALUE

if sys.platform.startswith('linux'):
    from WeaveBluezMgr import BluezManager as BleManager
    from WeaveBleUtility import FAKE_CONN_OBJ_VALUE
{'fraction_non_alphanumeric': 0.07624398073836276, 'fraction_numerical': 0.005136436597110754, 'mean_word_length': 3.131962864721485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4144083', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1794, 'n_words': 659}