本文整理汇总了Python中MasterSql.insert_hostlist_in_db方法的典型用法代码示例。如果您正苦于以下问题:Python MasterSql.insert_hostlist_in_db方法的具体用法?Python MasterSql.insert_hostlist_in_db怎么用?Python MasterSql.insert_hostlist_in_db使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MasterSql
的用法示例。
在下文中一共展示了MasterSql.insert_hostlist_in_db方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import insert_hostlist_in_db [as 别名]
class MasterDaemon:
"""
Main class of the master daemon
It provides communication between master and slave boxes and a part of the database management
"""
def __init__(self, log_flag):
self.logger = Logger(log_flag, LOG_FILE);
self.logger.info('Started Greenleaf Master Daemon');
self.d3config = {};
self.aes_slave_keys = {};
self.aes_master_key = None;
self.connected_clients = {};
self.sql = MasterSql();
self._parser = DaemonConfigParser(MASTER_CONF_FILE);
self.get_aes_slave_keys();
self.reload_camera(None, None);
self.scanner = Scanner(HOSTS_CONF);
self.scanner.scan(False);
self.hostlist = self.scanner._HostList;
self.sql.insert_hostlist_in_db(self.scanner._HostList);
self.knx_manager = KNXManager(self.aes_slave_keys);
self.reload_d3config(None, None);
self.protocol_function = {
PROTOCOL_KNX : KNXManager.protocol_knx,
PROTOCOL_ENOCEAN : self.protocol_enocean,
PROTOCOL_IP : self.protocol_ip
};
self.upnp_function = {
UPNP_PLAY : self.upnp_set_play,
UPNP_PAUSE : self.upnp_set_pause,
UPNP_NEXT : self.upnp_set_next,
UPNP_PREVIOUS : self.upnp_set_prev,
UPNP_STOP : self.upnp_set_stop,
UPNP_VOLUME_UP : self.upnp_set_volume_up,
UPNP_VOLUME_DOWN : self.upnp_set_volume_down,
UPNP_SET_VOLUME : self.upnp_set_volume
};
self.enocean_function = {};
self.data_function = {
DATA_MONITOR_KNX : self.monitor_knx,
DATA_MONITOR_IP : self.monitor_ip,
DATA_MONITOR_ENOCEAN : self.monitor_enocean,
DATA_MONITOR_BLUETOOTH : self.monitor_bluetooth,
DATA_KNX_READ : self.knx_read,
DATA_KNX_WRITE_S : self.knx_write_short,
DATA_KNX_WRITE_L : self.knx_write_long,
DATA_SEND_TO_DEVICE : self.send_to_device,
DATA_CRON_UPNP : self.cron_upnp,
DATA_SEND_MAIL : self.send_mail,
DATA_CHECK_SLAVE : self.check_slave,
DATA_RELOAD_CAMERA : self.reload_camera,
DATA_RELOAD_D3CONFIG : self.reload_d3config,
DATA_BACKUP_DB_CREATE_LOCAL : self.backup_db_create_local,
DATA_BACKUP_DB_REMOVE_LOCAL : self.backup_db_remove_local,
DATA_BACKUP_DB_LIST_LOCAL : self.backup_db_list_local,
DATA_BACKUP_DB_RESTORE_LOCAL : self.backup_db_restore_local,
DATA_UPDATE : self.update
};
def get_aes_slave_keys(self):
"""
Get the secretkeys of each slave daemon stored in database
"""
query = "SELECT serial, secretkey FROM daemon";
res = self.sql.mysql_handler_personnal_query(query);
self_hostname = socket.gethostname();
for r in res:
if SLAVE_NAME_PREFIX in r[0] or 'MD3' in r[0]:
self.aes_slave_keys[r[0]] = r[1];
elif self_hostname == r[0]:
self.aes_slave_keys[r[0]] = r[1];
self.aes_master_key = r[1];
print(self.aes_slave_keys)
def stop(self):
"""
Stops the daemon and closes sockets
"""
flag = False;
while not flag:
flag = True;
for client in self.connected_clients.values():
flag = False;
client.close();
break;
self.slave_connection.close();
sys.exit(0);
def run(self):
"""
Initialization of the connections and accepting incomming communications
"""
self.slave_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
self.cmd_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
self.slave_connection.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1);
self.cmd_connection.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1);
s_port = self._parser.getValueFromSection(MASTER_CONF_LISTEN_SECTION, MASTER_CONF_LISTEN_PORT_SLAVE_ENTRY);
c_port = self._parser.getValueFromSection(MASTER_CONF_LISTEN_SECTION, MASTER_CONF_LISTEN_PORT_CMD_ENTRY);
if not s_port:
frameinfo = getframeinfo(currentframe());
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import insert_hostlist_in_db [as 别名]
#.........这里部分代码省略.........
Callback called each time a knx_write_long packet is received.
Updates room_device_option values in the database.
"""
daemons = self.sql.get_daemons(db);
slave_name = self.get_slave_name(json_obj, daemons);
if slave_name is None:
connection.close();
return None;
dev = {}
dev["addr_dst"] = json_obj['data']['addr']
slave_name = slave_name.split('.')[0];
self.knx_manager.send_knx_write_long_to_slave(json_obj, dev, slave_name);
connection.close();
return None;
def knx_read(self, json_obj, connection, db):
"""
Callback called each time a knx_read packet is received.
"""
daemons = self.sql.get_daemons(db);
slave_name = self.get_slave_name(json_obj, daemons);
if slave_name is None:
return None;
slave_name = slave_name.split('.')[0];
self.knx_manager.send_knx_read_request_to_slave(slave_name, json_obj);
connection.close();
def monitor_ip(self, json_obj, connection, db):
"""
Callback called each time a monitor_ip packet is received.
A new local network scan is performed and the result stored in the database
"""
self.scanner.scan();
self.sql.insert_hostlist_in_db(self.scanner._HostList, db);
self.hostlist = self.scanner._HostList;
connection.close();
def monitor_bluetooth(self, json_obj, connection, db):
"""
TODO
"""
connection.close();
return None;
def monitor_enocean(self, json_obj, connection, db):
"""
Callback called each time a monitor_enocean packet is received.
Stores the data in enocean_log table.
"""
daemon_id = self.sql.update_enocean_log(json_obj, db);
doList = self.enocean_manager.update_room_device_option(daemon_id, json_obj, db);
connection.close();
if doList:
self.scenario.setValues(self.get_global_state(db), self.trigger, self.schedule, connection, doList);
self.scenario.start();
return None;
def send_to_device(self, json_obj, connection, db):
"""
Retrieves the good device in the database and builds the request to send.
"""
hostname = '';
dm = DeviceManager(int(json_obj['data']['room_device_id']), int(json_obj['data']['option_id']), DEBUG_MODE);
dev = dm.load_from_db(db);
if dev is None:
connection.close();