当前位置: 首页>>代码示例>>Python>>正文


Python MasterSql类代码示例

本文整理汇总了Python中MasterSql的典型用法代码示例。如果您正苦于以下问题:Python MasterSql类的具体用法?Python MasterSql怎么用?Python MasterSql使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MasterSql类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remote_sql

 def remote_sql(self, json_obj, connection):
     """
     Execute sql command from configurator
     """
     db = MasterSql();
     req = json_obj['data'].split(';');
     for item in req:
         if item != '':
             db.mysql_handler_personnal_query(item);
     connection.close();
     return;
开发者ID:Fuere,项目名称:Domoleaf,代码行数:11,代码来源:MasterDaemon.py

示例2: __init__

class EnOceanManager:

    ## The constructor.
    #
    # @param slave_keys The aes keys of the slaves.
    def __init__(self, slave_keys):
        ## Logger object for formatting and printing
        self.logger = Logger(DEBUG_MODE, LOG_FILE);
        ## SQL manager for the master daemon
        self.sql = MasterSql();
        self._parser = DaemonConfigParser('/etc/domoleaf/master.conf');
        ## Object containing the AES keys for encrypted communications
        self.aes_slave_keys = slave_keys;
        ## Array containing functions associated with IDs
        self.functions_transform = {
              0: utils.convert_none,
              4: utils.eno_onoff
        };

    ## Updates the table room_device_option with EnOcean values.
    #
    # @param daemon_id The ID of the daemon.
    # @param json_obj JSON object containing the source address of the EnOcean device.
    # @param db The database handler.
    #
    # @return The result of the query.
    def update_room_device_option(self, daemon_id, json_obj, db):
        query = ''.join(["SELECT room_device_option.option_id, room_device.room_device_id, addr_plus, function_answer, room_device_option.dpt_id ",
              "FROM room_device_option JOIN room_device ON room_device_option.room_device_id=room_device.room_device_id ",
              "JOIN dpt_optiondef ON dpt_optiondef.option_id=room_device_option.option_id AND ",
              "dpt_optiondef.protocol_id=room_device.protocol_id AND dpt_optiondef.dpt_id=room_device_option.dpt_id ",
              "WHERE daemon_id=", str(daemon_id), " AND room_device_option.addr=\"", str(json_obj['src_addr']), "\""]);
        res = self.sql.mysql_handler_personnal_query(query, db);
        result = []
        append = result.append
        if not res:
            query = ''.join(["SELECT room_device_option.option_id, room_device.room_device_id, addr_plus, function_answer, room_device_option.dpt_id ",
                  "FROM room_device_option JOIN room_device ON room_device_option.room_device_id=room_device.room_device_id ",
                  "JOIN dpt_optiondef ON dpt_optiondef.option_id=room_device_option.option_id AND ",
                  "dpt_optiondef.protocol_id=room_device.protocol_id AND dpt_optiondef.dpt_id=room_device_option.dpt_id ",
                  "WHERE daemon_id=", str(daemon_id), " AND  room_device_option.addr_plus=\"", str(json_obj['src_addr']), "\""]);
            res = self.sql.mysql_handler_personnal_query(query, db);
        for r in res:
            val = self.functions_transform[r[3]](int(json_obj['value']), r[4]);
            if val is not None:
                append(r)
                up = ''.join(["UPDATE room_device_option SET opt_value=\"", str(val),
                      "\" WHERE room_device_id=", str(r[1]), " AND option_id=\"", str(r[0]), "\""]);
                self.sql.mysql_handler_personnal_query(up, db);
        return result
开发者ID:V-Paranoiaque,项目名称:Domoleaf,代码行数:50,代码来源:EnOceanManager.py

示例3: SlaveReceiver

class SlaveReceiver(Thread):
    def __init__(self, connection, hostname, daemon):
        """
        Threaded class for reading from a slave and send the data to the treatment function
        """
        Thread.__init__(self);
        self.connection = connection;
        self.daemon = daemon;
        self.connected_host = hostname;
        self.sql = MasterSql();

    def run(self):
        """
        Thread run function overload
        """
        res = self.sql.mysql_handler_personnal_query('SELECT serial, secretkey FROM daemon WHERE serial=\'' + self.connected_host + '\'');
        aes_key = '';
        for r in res:
            if r[0] == self.connected_host:
                aes_key = r[1];
                break;
        if aes_key == '':
            return None;
        data = self.connection.recv(MasterDaemon.MAX_DATA_LENGTH);
        decrypt_IV = data[:16].decode();
        decode_obj = AES.new(aes_key, AES.MODE_CBC, decrypt_IV);
        data2 = decode_obj.decrypt(data[16:]).decode();
        flag = False;
        obj = data2;
        self.daemon.parse_data(obj, self.connection);
开发者ID:AdrienCourtois,项目名称:Domoleaf,代码行数:30,代码来源:SlaveReceiver.py

示例4: __init__

class Smartcommand:

    def __init__(self, daemon, smartcmd_id = 0):
        self.logger = Logger(False, LOG_FILE);
        self.logger.info('Started SMARTCMD');
        self.smartcmd_id = smartcmd_id;
        self.sql = MasterSql();
        self.daemon = daemon;

    def launch_smartcmd(self, json_obj, connection):
        if (self.smartcmd_id == 0):
            self.logger.error('Invalid Smartcommand');
            return;

        query = 'SELECT room_device_id, option_id, option_value, time_lapse FROM smartcommand_elems WHERE smartcommand_id ="'+ str(self.smartcmd_id) +'" ORDER BY exec_id';
        res = self.sql.mysql_handler_personnal_query(query);
        delay_color = 0;
        for r in res:
            obj = {};
            obj['sync'] = 0;
            data = {};
            data['room_device_id'] = r[0];
            data['option_id'] = r[1];
            data['value'] = r[2];
            obj['data'] = data;
            obj['packet_type'] = 'smartcmd_launch';
            delay = r[3];
            if (data['option_id'] ==  392 or data['option_id'] ==  393 or data['option_id'] ==  394):
                delay_color = delay_color + 1;
            if (delay > 0 and delay_color <= 1):
                time.sleep(delay);
            if (delay_color >= 3):
                delay_color = 0;
            self.daemon.send_to_device(obj, connection);
开发者ID:giorda-a,项目名称:Domoleaf,代码行数:34,代码来源:Smartcommand.py

示例5: __init__

 def __init__(self, daemon):
     Thread.__init__(self);
     self.logger = Logger(False, LOG_FILE);
     self.sql = MasterSql();
     self.daemon = daemon;
     self.scenarios_list = {};
     self.update_scenarios_list();
开发者ID:Fuere,项目名称:Domoleaf,代码行数:7,代码来源:Scenario.py

示例6: __init__

class Scenario:

    def __init__(self, daemon):
        self.logger = Logger(False, LOG_FILE);
        self.sql = MasterSql();
        self.daemon = daemon;
        self.scenarios_list = {};
        self.update_scenarios_list();

    def get_scenarios_tab(self, scenarios):
        scenarios_tab = {};
        self.logger.debug('\n\nGETTING SCENARIOS TAB\n');
        for d in scenarios:
            scHash = str(d[4])+'_'+str(d[5])
            if (scHash not in scenarios_tab):
                scenarios_tab[scHash] = [];
            scenarios_tab[scHash].append(d)
        return scenarios_tab;
    
    def update_scenarios_list(self):
        self.logger.debug('UPDATING SCENARIOS');

        query = ('SELECT id_scenario, trigger_events_conditions.id_trigger, id_schedule, '
                 'id_smartcmd, trigger_events_conditions.room_device_id, id_option '
                 'FROM trigger_events_conditions '
                 'JOIN scenarios_list '
                 'ON trigger_events_conditions.id_trigger=scenarios_list.id_trigger '
                 'WHERE activated = 1 && scenarios_list.id_trigger IS NOT NULL '
                 'ORDER BY id_scenario');
        scenarios_list = self.sql.mysql_handler_personnal_query(query);
        
        self.logger.debug('S LIST = ' + str(scenarios_list) + '\n');
        self.scenarios_list = self.get_scenarios_tab(scenarios_list);
        self.logger.debug('S TAB = ' + str(self.scenarios_list) + '\n\n\n');
        
    def check_all_scenarios(self, global_state, trigger, schedule, connection, doList):
        self.logger.debug('CHECKING ALL SCENARIOS');
        self.logger.debug('SCENARIOS LIST = ');
        self.logger.debug(self.scenarios_list);
        self.logger.debug('\n');
        for do in doList:
            slist = self.scenarios_list[str(do[1])+'_'+str(do[0])];
            self.logger.debug('SLIST = ');
            self.logger.debug(slist);
            for scenario in slist:
                self.logger.error(scenario);
                self.logger.debug('Scenario : ' + str(scenario) + '\n\n');
                if trigger.test_trigger(scenario[1], global_state) == 1:
                    self.logger.debug('Trigger OK');
                    if (scenario[2] is None or
                        scenario[2] is not None and schedule.test_schedule(scenario[2]) ==  1):
                        self.launch_scenario(scenario[3], connection);
    
    def launch_scenario(self, id_smartcmd, connection):
        self.logger.debug('LAUNCH !!!');
        jsonString = json.JSONEncoder().encode({
            "data": id_smartcmd
        });
        data = json.JSONDecoder().decode(jsonString);
        self.daemon.smartcmd_launch(data, connection);
开发者ID:couturg,项目名称:Domoleaf,代码行数:60,代码来源:Scenario.py

示例7: __init__

 def __init__(self, daemon):
     self.logger = Logger(False, LOG_FILE);
     self.sql = MasterSql();
     self.daemon = daemon;
     self.schedules_list = '';
     self.full_schedules_list = '';
     self.update_schedules_list();
开发者ID:couturg,项目名称:Domoleaf,代码行数:7,代码来源:Schedule.py

示例8: __init__

 def __init__(self, daemon):
     self.logger = Logger(False, LOG_FILE);
     self.logger.debug('Init CalcLogs');
     self.sql = MasterSql();
     self.daemon = daemon;
     self.devices_list = {};
     self.devices_list_update();
开发者ID:Fuere,项目名称:Domoleaf,代码行数:7,代码来源:CalcLogs.py

示例9: __init__

class EnOceanManager:
    """
    KNX management class
    """
    def __init__(self, slave_keys):
        self.logger = Logger(DEBUG_MODE, LOG_FILE);
        self.sql = MasterSql();
        self._parser = DaemonConfigParser('/etc/domoleaf/master.conf');
        self.aes_slave_keys = slave_keys;
        self.functions_transform = {
              0: utils.convert_none,
              4: utils.eno_onoff
        };
    
    def update_room_device_option(self, daemon_id, json_obj):
        """
        Update of the table room_device_option with EnOcean value
        """
        query  = "SELECT room_device_option.option_id, room_device.room_device_id, addr_plus, function_answer, room_device_option.dpt_id ";
        query += "FROM room_device_option ";
        query += "JOIN room_device ON room_device_option.room_device_id=room_device.room_device_id ";
        query += "JOIN dpt_optiondef ON dpt_optiondef.option_id=room_device_option.option_id AND ";
        query += "dpt_optiondef.protocol_id=room_device.protocol_id AND dpt_optiondef.dpt_id=room_device_option.dpt_id ";
        query += "WHERE daemon_id=" + str(daemon_id) + " AND room_device_option.addr=\"";
        query += str(json_obj['src_addr']) + "\"";
        res = self.sql.mysql_handler_personnal_query(query);
        result = []
        
        if len(res) == 0:
            query  = "SELECT room_device_option.option_id, room_device.room_device_id, addr_plus, function_answer, room_device_option.dpt_id ";
            query += "FROM room_device_option ";
            query += "JOIN room_device ON room_device_option.room_device_id=room_device.room_device_id ";
            query += "JOIN dpt_optiondef ON dpt_optiondef.option_id=room_device_option.option_id AND ";
            query += "dpt_optiondef.protocol_id=room_device.protocol_id AND dpt_optiondef.dpt_id=room_device_option.dpt_id ";
            query += "WHERE daemon_id=" + str(daemon_id) + " AND  room_device_option.addr_plus=\"";
            query += str(json_obj['src_addr']) + "\"";
            res = self.sql.mysql_handler_personnal_query(query);
        
        for r in res:
            val = self.functions_transform[r[3]](int(json_obj['value']), r[4]);
            if val is not None:
                result.append(r)
                up = "UPDATE room_device_option SET opt_value=\"" + str(val)
                up += "\" WHERE room_device_id=" + str(r[1]) + " AND option_id=\"" + str(r[0]) + "\"";
                self.sql.mysql_handler_personnal_query(up);
        return result
开发者ID:couturg,项目名称:Domoleaf,代码行数:46,代码来源:EnOceanManager.py

示例10: __init__

 def __init__(self, slave_keys):
     ## Logger object for formatting and printing logs
     self.logger = Logger(DEBUG_MODE, LOG_FILE);
     ## SQL object for managing database
     self.sql = MasterSql();
     self._parser = DaemonConfigParser('/etc/domoleaf/master.conf');
     ## Object containing AES keys for encrypted communications
     self.aes_slave_keys = slave_keys;
开发者ID:V-Paranoiaque,项目名称:Domoleaf,代码行数:8,代码来源:KNXManager.py

示例11: __init__

 def __init__(self, connection, hostname, daemon):
     """
     Threaded class for reading from a slave and send the data to the treatment function
     """
     Thread.__init__(self);
     self.connection = connection;
     self.daemon = daemon;
     self.connected_host = hostname;
     self.sql = MasterSql();
开发者ID:AdrienCourtois,项目名称:Domoleaf,代码行数:9,代码来源:SlaveReceiver.py

示例12: __init__

 def __init__(self, slave_keys):
     self.logger = Logger(DEBUG_MODE, LOG_FILE);
     self.sql = MasterSql();
     self._parser = DaemonConfigParser('/etc/domoleaf/master.conf');
     self.aes_slave_keys = slave_keys;
     self.functions_transform = {
           0: utils.convert_none,
           4: utils.eno_onoff
     };
开发者ID:Fuere,项目名称:Domoleaf,代码行数:9,代码来源:EnOceanManager.py

示例13: __init__

 def __init__(self, daemon):
     ## Logger object for formatting and printing logs
     self.logger = Logger(False, LOG_FILE);
     ## SQL object for managing database
     self.sql = MasterSql();
     ## Instance of the slave daemon
     self.daemon = daemon;
     ## Trigger list
     self.triggers_list = '';
     self.update_triggers_list();
开发者ID:V-Paranoiaque,项目名称:Domoleaf,代码行数:10,代码来源:Trigger.py

示例14: __init__

 def __init__(self, daemon):
     Thread.__init__(self)
     ## Logger object for formatting and printing logs
     self.logger = Logger(False, LOG_FILE)
     ## SQL object for managing slave daemon database
     self.sql = MasterSql()
     ## Instance of the slave daemon
     self.daemon = daemon
     ## List of scenarios
     self.scenarios_list = {}
     self.update_scenarios_list()
开发者ID:V-Paranoiaque,项目名称:Domoleaf,代码行数:11,代码来源:Scenario.py

示例15: __init__

 def __init__(self, daemon):
     ## Logger object for formatting and printing logs
     self.logger = Logger(False, LOG_FILE)
     ## SQL object for managing slave database
     self.sql = MasterSql()
     ## Instance of the slave daemon
     self.daemon = daemon
     ## Schedule list
     self.schedules_list = ""
     ## Full schedule list
     self.full_schedules_list = ""
     self.update_schedules_list(0)
开发者ID:V-Paranoiaque,项目名称:Domoleaf,代码行数:12,代码来源:Schedule.py


注:本文中的MasterSql类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。