Esempio n. 1
0
def init():
    L.l.debug('WebUI module initialising')
    # thread_pool.add_callable(webui.thread_run, run_interval_second=60)
    from crud import admin, user
    crud.init_crud()
    app.register_blueprint(admin, url_prefix='/admin')
    app.register_blueprint(user, url_prefix='/user')
    global initialised, flask_thread
    if BIND_IP is not None and BIND_PORT is not None:
        host = BIND_IP
        port = BIND_PORT
    else:
        # otherwise listen on all interfaces
        host = '0.0.0.0'
        port = int(model_helper.get_param(Constant.P_FLASK_WEB_PORT))
    app.wsgi_app = ReverseProxied(app.wsgi_app)
    app.config['STATIC_FOLDER'] = os.path.join(os.path.dirname(__file__),
                                               'static')
    flask_thread = helpers.FlaskInThread(app,
                                         host=host,
                                         port=port,
                                         debug=True,
                                         use_reloader=False)
    initialised = True
    flask_thread.start()
Esempio n. 2
0
def init():
    L.l.debug('Hipchat module initialising')
    dispatcher.connect(hipchat_notify,
                       signal=Constant.SIGNAL_CHAT_NOTIFICATION,
                       sender=dispatcher.Any)
    global _token, _room
    _token = model_helper.get_param(Constant.P_HIPCHAT_TOKEN)
    _room = model_helper.get_param(Constant.P_HIPCHAT_ROOM_API_ID)
    try:
        pass
        # hipchat_notify(message='Module initialising', notify=True, color='red')
        # send_message(title="Initialised", message="Module initialised")
        # send_message(title="Initialised 2", message="Module initialised 2")
    except Exception as ex:
        L.l.error("Unable tp init hipchat %s" % ex)
    # thread_pool.add_interval_callable(_send_queue, run_interval_second=60)
    global initialised
    initialised = True
Esempio n. 3
0
def init():
    global initialised, __CLIENT_SECRETS_FILE, __youtube
    try:
        __CLIENT_SECRETS_FILE = utils.get_app_root_path(
        ) + model_helper.get_param(Constant.P_YOUTUBE_CREDENTIAL_FILE)
        L.l.info('Initialising youtube with credential from {}'.format(
            __CLIENT_SECRETS_FILE))
        __youtube = get_authenticated_service([])
        dispatcher.connect(file_watcher_event,
                           signal=Constant.SIGNAL_FILE_WATCH,
                           sender=dispatcher.Any)
        thread_pool.add_interval_callable(thread_run, run_interval_second=10)
        initialised = True
        # upload_file('c:\\temp\\01-20150512215655-alert.avi')
    except Exception as ex:
        L.l.warning('Unable to initialise youtube uploader, err={}'.format(ex))
Esempio n. 4
0
def init():
    # use auto setup as described here: https://plot.ly/python/getting-started/ to avoid passwords in code
    # or less secure sign_in code below
    # py.sign_in(model_helper.get_param(constant.P_PLOTLY_USERNAME),model_helper.get_param(constant.P_PLOTLY_APIKEY))
    username = ""
    if py.get_credentials()['username'] == '' or py.get_credentials(
    )['api_key'] == '':
        env_var = 'PLOTLY_CREDENTIALS_PATH'
        alt_path = os.environ.get(env_var)
        if not alt_path:
            L.l.info(
                'Plotly config not in environment var: {}'.format(env_var))
            env_var = 'OPENSHIFT_REPO_DIR'
            alt_path = os.environ.get(env_var)
            if alt_path is None:
                L.l.info(
                    'Plotly config not in environment var: {}'.format(env_var))
                credential_file = model_helper.get_param(
                    Constant.P_PLOTLY_ALTERNATE_CONFIG)
                alt_path = os.getcwd() + '/' + credential_file
            else:
                L.l.info('Plotly config found in environment var: {}, path={}'.
                         format(env_var, alt_path))
                alt_path = str(alt_path) + '/../data/.plotly.credentials'
        L.l.info("Plotly standard config empty, trying alt_path={}".format(
            alt_path))
        try:
            with open(alt_path, 'r') as cred_file:
                data = cred_file.read().replace('\n', '')
            if len(data) > 0:
                cred_obj = utils.json2obj(data)
                username = cred_obj['username']
                api_key = cred_obj['api_key']
                if username and api_key:
                    py.sign_in(username, api_key)
                    global initialised
                    initialised = True
                    # else:
                    #    Log.logger.info("Plotly init from db folder config {}{} not ok, trying with db data".format(os.getcwd(),
                    #        credential_file))
                    #    #alternate way if reading data from DB
                    #    py.sign_in(model_helper.get_param(constant.P_PLOTLY_USERNAME),
                    #               model_helper.get_param(constant.P_PLOTLY_APIKEY))

        except Exception, ex:
            L.l.warning("error reading plotly credentials {}".format(ex))
Esempio n. 5
0
def init():
    global __observer, initialised, __inotify_import_ok
    if __inotify_import_ok:
        path = model_helper.get_param(Constant.P_MOTION_VIDEO_PATH)
        L.l.info('Initialising file watchdog for folder={}'.format(path))
        if os.path.exists(path):
            event_handler = EventHandler()
            __observer = Observer()
            __observer.schedule(event_handler, path, recursive=True)
            initialised = True
            __observer.start()
        else:
            L.l.warning(
                'Filewatch not initialised watch path={} not found'.format(
                    path))
    else:
        L.l.info(
            'Inotify observer not available,  not initialising file watch')
Esempio n. 6
0
def _check_def_change():
    global _channel_lock
    try:
        _channel_lock.acquire()
        config_file = model_helper.get_param(Constant.P_THINGSPEAK_API_FILE)
        read_api = None
        with open(config_file, 'r') as f:
            profile = json.load(f)
            read_api = profile['0']['read_api']
        if read_api is not None:
            get = urllib2.urlopen(
                "https://api.thingspeak.com/channels.json?api_key={}".format(
                    read_api),
                timeout=10)
            response = get.read()
            channel_list = json.loads(response)
            for ch in channel_list:
                if P.key_model in ch['metadata']:
                    #L.l.info("Found uploadable channel {}".format(ch['name']))
                    P.profile_channels[ch['id']] = ch
                    for key in ch['api_keys']:
                        if key['write_flag']:
                            ch['api_write'] = key['api_key']
                        else:
                            ch['api_read'] = key['api_key']
                    _get_channel(chid=ch['id'],
                                 read_api=ch['api_read'],
                                 write_api=ch['api_write'])
                else:
                    L.l.info(
                        "Found non-uploadable channel {}, ignoring".format(
                            ch['name']))
    except Exception as ex:
        L.l.error("Unable to get channels definitions, ex={}".format(ex))
    finally:
        _channel_lock.release()