Exemple #1
0
    def __init__(self, db_host=None, db_port=None):
        if db_port is None:
            r_ip, r_port = data_models.service_connection()
        else:
            r_ip, r_port = db_host, db_port

        self.binary_r = redis.StrictRedis(host=r_ip, port=r_port)
        self.redis_conn = redis.StrictRedis(host=r_ip,
                                            port=r_port,
                                            decode_responses=True)
    def __init__(self,
                 db_host=None,
                 db_port=None,
                 binary_r=None,
                 redis_conn=None):
        if binary_r and redis_conn:
            self.binary_r = binary_r
            self.redis_conn = redis_conn
        else:
            if not db_host and not db_port:
                db_host, db_port = data_models.service_connection()

            self.redis_conn = redis.StrictRedis(host=db_host,
                                                port=str(db_port),
                                                decode_responses=True)
            self.binary_r = redis.StrictRedis(host=db_host, port=str(db_port))
Exemple #3
0
    def __init__(self, db_host=None, db_port=None):
        self.db_host = db_host
        self.db_port = db_port
        if db_port is None:
            r_ip, r_port = data_models.service_connection()
        else:
            r_ip, r_port = db_host, db_port

        self.binary_r = redis.StrictRedis(host=r_ip, port=r_port)
        self.redis_conn = redis.StrictRedis(
            host=r_ip, port=r_port, decode_responses=True
        )

        # discover slurp_* files and load Slurp* classes
        self.slurp_classes = {}
        self.slurp_default_class = "gphoto2"
        package_path = pathlib.Path(pathlib.Path(__file__).parents[0])
        if package_path.is_dir():
            slurp_files = list(
                x for x in package_path.iterdir() if x.is_file() and "slurp_" in str(x)
            )
        for file in slurp_files:
            # load modules using full path
            spec = importlib.util.spec_from_file_location(pathlib.Path(file).stem, file)
            module = importlib.util.module_from_spec(spec)
            spec.loader.exec_module(module)
            clsmembers = inspect.getmembers(module, inspect.isclass)
            # create a dictionary of names that will be callable with
            # the --slurp-method parameter
            #
            # ('SlurpGphoto2', <class 'slurp_gphoto2.SlurpGphoto2'>)
            # will be used as
            # {"gphoto2" : <class 'slurp_gphoto2.SlurpGphoto2'>}
            #
            self.slurp_classes.update(
                {
                    key.lower()[5:]: value
                    for (key, value) in clsmembers
                    if key.startswith("Slurp")
                }
            )
        # set a default if --slurp-method is not used
        self.slurp_classes["default"] = self.slurp_classes[self.slurp_default_class]
Exemple #4
0
def populate_db(db_host, db_port, xml_files=None, verbose=False):
    if db_port is None:
        r_ip, r_port = data_models.service_connection()
    else:
        r_ip, r_port = db_host, db_port

    if not xml_files:
        # get path in module
        xml_files = [
            pathlib.PurePath(
                pathlib.Path(__file__).parents[0], "reference.xml")
        ]

    redis_conn = redis.StrictRedis(host=r_ip,
                                   port=r_port,
                                   decode_responses=True)
    device_script_lookup_key = "device:script_lookup"
    script_lookup_key = "scripts:{}"
    for xml_file in xml_files:
        xml = etree.parse(str(xml_file))

        for script in xml.xpath("//script"):
            script_name = script.xpath("./@name")[0]
            for call in script.xpath("//call"):
                redis_conn.hset(
                    script_lookup_key.format(script_name),
                    call.xpath("./@name")[0],
                    call.xpath("./@template")[0],
                )

        for device in xml.xpath("//device"):
            redis_conn.hset(
                device_script_lookup_key,
                device.xpath("./@name")[0],
                device.xpath("./@script")[0],
            )
Exemple #5
0
# Copyright (c) 2018, Galen Curwen-McAdams

import argparse
import atexit

import redis
from ma_cli import data_models

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button

r_ip, r_port = data_models.service_connection()
binary_r = redis.StrictRedis(host=r_ip, port=r_port)
redis_conn = redis.StrictRedis(host=r_ip, port=r_port, decode_responses=True)


class EnvApp(App):
    def __init__(self, *args, **kwargs):
        # store kwargs to passthrough
        self.kwargs = kwargs
        if kwargs["db_host"] and kwargs["db_port"]:
            global binary_r
            global redis_conn
            db_settings = {"host": kwargs["db_host"], "port": kwargs["db_port"]}
            binary_r = redis.StrictRedis(**db_settings)
            redis_conn = redis.StrictRedis(**db_settings, decode_responses=True)