Exemple #1
0
def client_doc_static(client_id, path):
    pkg = client_id.split(".")[0].replace("-", "_")
    root_path = os.path.join(get_packages_directory(), pkg)
    root_path = os.path.join(root_path, "_build_doc/html/")
    if not os.path.isfile(os.path.join(root_path, path)):
        return render_template('client_no_doc.html')
    return send_from_directory(root_path, path)
Exemple #2
0
def client_doc_static(client_id, path):
    pkg = client_id.split(".")[0].replace("-", "_")
    root_path = os.path.join(get_packages_directory(), pkg)
    root_path = os.path.join(root_path, "_build_doc/html/")
    if not os.path.isfile(os.path.join(root_path, path)):
        return render_template('client_no_doc.html')
    return send_from_directory(root_path, path)
Exemple #3
0
    return info


def get_errorlog(cmd):
    print("Command = %s" % cmd)
    errorlog = subprocess.Popen([cmd], stdout=subprocess.PIPE)
    output = errorlog.communicate()[0]
    if isinstance(output, str):
        output = unicode(output, 'utf-8')
    return output



### common tasks
package = "plugin_onewired"
template_dir = "{0}/{1}/admin/templates".format(get_packages_directory(), package)
static_dir = "{0}/{1}/admin/static".format(get_packages_directory(), package)
geterrorlogcmd = "{0}/{1}/admin/geterrorlog.sh".format(get_packages_directory(), package)

plugin_onewired_adm = Blueprint(package, __name__,
                        template_folder = template_dir,
                        static_folder = static_dir)


@plugin_onewired_adm.route('/<client_id>')
def index(client_id):
    detail = get_client_detail(client_id)
    device = str(detail['data']['configuration'][1]['value'])
    try:
        return render_template('plugin_onewired.html',
            clientid = client_id,
Exemple #4
0
            config_file_path=
            "/var/lib/domogik/domogik_packages/plugin_hue/data/bridge.config")
        b.connect()
        lights = b.get_light()
        for light in lights:
            output += "Light ID : " + light[0] + "\n"
            output += "    Name : " + lights[light]["name"] + "\n"
            output += "\n"
    except:
        output = "Error while retrieving Hue lamps... Have you push the bridge button?"
    return output


### common tasks
package = "plugin_hue"
template_dir = "{0}/{1}/admin/templates".format(get_packages_directory(),
                                                package)
static_dir = "{0}/{1}/admin/static".format(get_packages_directory(), package)

plugin_hue_adm = Blueprint(package,
                           __name__,
                           template_folder=template_dir,
                           static_folder=static_dir)


@plugin_hue_adm.route('/<client_id>')
def index(client_id):
    detail = get_client_detail(client_id)
    try:
        return render_template(
            'plugin_hue.html',
### package specific functions
def list_bt_devices():
    try:
	bt = subprocess.Popen(["hcitool", "scan"], stdout=subprocess.PIPE)
        output = bt.communicate()[0]
        if isinstance(bt, str):
            output = unicode(output, 'utf-8')
        return output
    except:
	output = unicode('Error with BT detection', 'utf-8')



### common tasks
package = "plugin_bluez"
template_dir = "{0}/{1}/admin/templates".format(get_packages_directory(), package)
static_dir = "{0}/{1}/admin/static".format(get_packages_directory(), package)

plugin_bluez_adm = Blueprint(package, __name__,
                        template_folder = template_dir,
                        static_folder = static_dir)

@plugin_bluez_adm.route('/<client_id>')
def index(client_id):
    detail = get_client_detail(client_id)
    try:
        return render_template('plugin_bluez.html',
            clientid = client_id,
            client_detail = detail,
            mactive="clients",
            active = 'advanced',
Exemple #6
0
@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

@app.errorhandler(500)
def server_error(e):
    return render_template('500.html'), 500



### packages admin pages

sys.path.append(get_libraries_directory())

from domogik.admin.views.client_advanced_empty import nothing_adm
for a_client in os.listdir(get_packages_directory()):
    try:
        if os.path.isdir(os.path.join(get_packages_directory(), a_client)):
            # check if there is an "admin" folder with an __init__.py file in it
            print(a_client)
            if os.path.isfile(os.path.join(get_packages_directory(), a_client, "admin", "__init__.py")):
                print("=> admin")
                app.logger.info("Load advanced page for package '{0}'".format(a_client))
                pkg = "domogik_packages.{0}.admin".format(a_client)
                pkg_adm = "{0}_adm".format(a_client)
                print(u"Try to import module : {0} => {1}_adm".format(pkg, a_client))
                the_adm = getattr(__import__(pkg, fromlist=[pkg_adm], level=1), pkg_adm)
                app.register_blueprint(the_adm, url_prefix="/{0}".format(a_client))
            # if no admin for the client, include the generic empty page
            else:
                app.register_blueprint(nothing_adm, url_prefix="/{0}".format(a_client))
Exemple #7
0
    if pk_type != None:
        app.add_url_rule('{0}<{1}:{2}>'.format(url, pk_type, pk),
                         view_func=view_func,
                         methods=['GET', 'PUT', 'DELETE'])
    else:
        app.add_url_rule('{0}<{1}>'.format(url, pk),
                         view_func=view_func,
                         methods=['GET', 'PUT', 'DELETE'])


### packages admin pages

sys.path.append(get_libraries_directory())

from domogik.admin.views.client_advanced_empty import nothing_adm
for a_client in os.listdir(get_packages_directory()):
    try:
        if os.path.isdir(os.path.join(get_packages_directory(), a_client)):
            # check if there is an "admin" folder with an __init__.py file in it
            if os.path.isfile(
                    os.path.join(get_packages_directory(), a_client, "admin",
                                 "__init__.py")):
                app.logger.info(
                    "Load advanced page for package '{0}'".format(a_client))
                pkg = "domogik_packages.{0}.admin".format(a_client)
                pkg_adm = "{0}_adm".format(a_client)
                the_adm = getattr(__import__(pkg, fromlist=[pkg_adm], level=1),
                                  pkg_adm)
                app.register_blueprint(the_adm,
                                       url_prefix="/{0}".format(a_client))
            # if no admin for the client, include the generic empty page