本文整理汇总了Python中DaemonConfigParser类的典型用法代码示例。如果您正苦于以下问题:Python DaemonConfigParser类的具体用法?Python DaemonConfigParser怎么用?Python DaemonConfigParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DaemonConfigParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: master_conf_initdb
def master_conf_initdb():
file = DaemonConfigParser(MASTER_CONF_FILE_TO)
# mysql password
password = "".join(
random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(128)
)
password = sha1(password.encode("utf-8"))
file.writeValueFromSection("mysql", "password", password.hexdigest())
os.system(
"sed -i \"s/define('DB_PASSWORD', 'domoleaf')/define('DB_PASSWORD', '"
+ password.hexdigest()
+ "')/g\" /etc/domoleaf/www/config.php"
)
# mysql user
query1 = 'DELETE FROM user WHERE User="domoleaf"'
query2 = 'DELETE FROM db WHERE User="domoleaf"'
query3 = (
"INSERT INTO user (Host, User, Password) VALUES ('%', 'domoleaf', PASSWORD('" + password.hexdigest() + "'));"
)
query4 = 'INSERT INTO db (Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Create_tmp_table_priv, Lock_tables_priv, Create_view_priv, Show_view_priv, Create_routine_priv, Alter_routine_priv, Execute_priv, Event_priv, Trigger_priv) VALUES ("%","domoleaf","domoleaf","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y");'
query5 = "FLUSH PRIVILEGES"
Popen(
["mysql", "--defaults-file=/etc/mysql/debian.cnf", "mysql", "-e", query1],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
bufsize=-1,
)
Popen(
["mysql", "--defaults-file=/etc/mysql/debian.cnf", "mysql", "-e", query2],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
bufsize=-1,
)
Popen(
["mysql", "--defaults-file=/etc/mysql/debian.cnf", "mysql", "-e", query3],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
bufsize=-1,
)
Popen(
["mysql", "--defaults-file=/etc/mysql/debian.cnf", "mysql", "-e", query4],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
bufsize=-1,
)
Popen(
["mysql", "--defaults-file=/etc/mysql/debian.cnf", "mysql", "-e", query5],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
bufsize=-1,
)
示例2: send_cron
def send_cron(cron_name):
try:
parser = DaemonConfigParser(SLAVE_CONF_FILE);
port = parser.getValueFromSection('cron', 'port').encode()
sock = socket.create_connection(('127.0.0.1', port));
sock.send(bytes(cron_name, 'utf-8'));
sock.close();
except Exception as e:
if 'sock' in locals():
sock.close()
示例3: master_conf_init
def master_conf_init():
file = DaemonConfigParser(SLAVE_CONF_FILE)
personnal_key = file.getValueFromSection("personnal_key", "aes")
hostname = socket.gethostname()
# KNX Interface
if os.path.exists("/dev/ttyAMA0"):
knx = "tpuarts"
knx_interface = "ttyAMA0"
elif os.path.exists("/dev/ttyS0"):
knx = "tpuarts"
knx_interface = "ttyS0"
else:
knx = "ipt"
knx_interface = "127.0.0.1"
fic = open("/etc/domoleaf/.domoslave.version", "r")
domoslave = fic.readline()
fic.close()
personnal_key = md5(personnal_key.encode("utf-8"))
query1 = (
"INSERT INTO daemon (name, serial, secretkey, validation, version) VALUES ('"
+ hostname
+ "','"
+ hostname
+ "','"
+ personnal_key.hexdigest()
+ "',1,'"
+ domoslave.split("\n")[0]
+ "')"
)
query2 = (
"INSERT INTO daemon_protocol (daemon_id, protocol_id, interface, interface_arg) VALUES (1,1,'"
+ knx
+ "','"
+ knx_interface
+ "')"
)
Popen(
["mysql", "--defaults-file=/etc/mysql/debian.cnf", "domoleaf", "-e", query1],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
bufsize=-1,
)
Popen(
["mysql", "--defaults-file=/etc/mysql/debian.cnf", "domoleaf", "-e", query2],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
bufsize=-1,
)
示例4: ipVPN
def ipVPN():
private = InfoSys.ipPrivate();
parser = DaemonConfigParser(SLAVE_CONF_FILE);
server = parser.getValueFromSection('openvpn', 'openvpnserver').encode()
if server.decode() == 'none':
return '';
try:
vpn = ([(s.connect((server, 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1])
except Exception as e:
return ''
if private != vpn:
return vpn;
return '';
示例5: __init__
def __init__(self, log_flag):
self.logger = Logger(log_flag, LOG_FILE);
self.logger.info('Started Domoleaf Slave daemon');
print('######## SLAVE DAEMON #######')
self.connected_masters = {};
self.connected_knx = [];
self.connected_enocean = [];
self.connected_cron = [];
self.clients = [];
self._scanner = Scanner(HOST_CONF_FILE);
self._scanner.scan(False);
self._hostlist = self._scanner._HostList;
self._parser = DaemonConfigParser(SLAVE_CONF_FILE);
self.encrypt_keys = {};
self.knx_sock = None;
self.master_sock = None;
self.enocean_sock = None;
self.cron_sock = None;
self.private_aes = hashlib.md5(self._parser.getValueFromSection('personnal_key', 'aes').encode()).hexdigest();
self.wifi_init(self._parser.getValueFromSection('wifi', 'ssid'), self._parser.getValueFromSection('wifi', 'password'), self._parser.getValueFromSection('wifi', 'encryption'), self._parser.getValueFromSection('wifi', 'mode'), 0);
self.functions = {
KNX_READ_REQUEST : self.knx_read_request,
KNX_WRITE_SHORT : self.knx_write_short,
KNX_WRITE_LONG : self.knx_write_long,
KNX_WRITE_TEMP : self.knx_write_temp,
CHECK_SLAVE : self.check_slave,
MONITOR_IP : self.monitor_ip,
DATA_UPDATE : self.update,
SEND_TECH : self.send_tech,
SEND_ALIVE : self.send_alive,
SEND_INTERFACES : self.send_interfaces,
SHUTDOWN_D3 : self.shutdown_d3,
REBOOT_D3 : self.reboot_d3,
WIFI_UPDATE : self.wifi_update
};
示例6: __init__
def __init__(self, log_flag):
self.logger = Logger(log_flag, LOG_FILE);
self.logger.info('Started Greenleaf Slave daemon');
print('######## SLAVE DAEMON #######')
self.connected_masters = {};
self.connected_knx = [];
self.connected_enocean = [];
self.clients = [];
self._scanner = Scanner(HOST_CONF_FILE);
self._scanner.scan(False);
self._hostlist = self._scanner._HostList;
self._parser = DaemonConfigParser(SLAVE_CONF_FILE);
self.encrypt_keys = {};
self.knx_sock = None;
self.master_sock = None;
self.enocean_sock = None;
self.private_aes = hashlib.md5(self._parser.getValueFromSection('personnal_key', 'aes').encode()).hexdigest();
self.functions = {
KNX_READ_REQUEST : self.knx_read_request,
KNX_WRITE_SHORT : self.knx_write_short,
KNX_WRITE_LONG : self.knx_write_long,
KNX_WRITE_TEMP : self.knx_write_temp,
CHECK_SLAVE : self.check_slave,
MONITOR_IP : self.monitor_ip,
DATA_UPDATE : self.update
};
示例7: __init__
def __init__(self, _id_elem = 0, _option_id = 0, _debug = False):
self._id = _id_elem;
self._debug = _debug;
self._option_id = _option_id;
self._parser = DaemonConfigParser(CONF_FILENAME);
self._db_name = self._parser.getValueFromSection(MYSQL_CONF_SECTION, MYSQL_CONF_USER_ENTRY);
self._db_passwd = self._parser.getValueFromSection(MYSQL_CONF_SECTION, MYSQL_CONF_PASSWORD_ENTRY);
self._db_dbname = self._parser.getValueFromSection(MYSQL_CONF_SECTION, MYSQL_CONF_DATABASE_ENTRY);
示例8: __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;
示例9: __init__
def __init__(self, log_flag):
## Logger object for formatting and printing logs
self.logger = Logger(log_flag, LOG_FILE)
self.logger.info("Started Domoleaf Slave daemon")
## Array of master daemon on local network
self.connected_masters = {}
## Array of monitor KNX on local network
self.connected_knx = []
## Array of monitor EnOcean on local network
self.connected_enocean = []
## Array of cron running on the system
self.connected_cron = []
self._scanner = Scanner(log_flag)
self._hostlist = []
myhostname = socket.gethostname().upper()
if SLAVE_NAME_PREFIX in myhostname:
self._scanner.scan()
self._hostlist = self._scanner._HostList
else:
self._hostlist.append(Host("", "127.0.0.1", myhostname))
self._parser = DaemonConfigParser(SLAVE_CONF_FILE)
## Keys for encrypting communications
self.encrypt_keys = {}
## Main socket for communication with KNX daemon
self.knx_sock = None
## Main socket for communication with master daemon
self.master_sock = None
## Main socket for communication with enocean daemon
self.enocean_sock = None
## Main socket for communication with cron
self.cron_sock = None
## Private AES key got from configuration file
self.private_aes = self._parser.getValueFromSection("personnal_key", "aes")
self.wifi_init(
self._parser.getValueFromSection("wifi", "ssid"),
self._parser.getValueFromSection("wifi", "password"),
self._parser.getValueFromSection("wifi", "encryption"),
self._parser.getValueFromSection("wifi", "mode"),
0,
)
## Port on which connect got from configuration file
self.connect_port = self._parser.getValueFromSection(SLAVE_CONF_CONNECT_SECTION, SLAVE_CONF_CONNECT_PORT_ENTRY)
## Callback array indexed on packet type
self.functions = {
KNX_READ_REQUEST: self.knx_read_request,
KNX_WRITE_SHORT: self.knx_write_short,
KNX_WRITE_LONG: self.knx_write_long,
KNX_WRITE_TEMP: self.knx_write_temp,
CHECK_SLAVE: self.check_slave,
MONITOR_IP: self.monitor_ip,
DATA_UPDATE: self.update,
SEND_TECH: self.send_tech,
SEND_ALIVE: self.send_alive,
SEND_INTERFACES: self.send_interfaces,
SHUTDOWN_D3: self.shutdown_d3,
REBOOT_D3: self.reboot_d3,
WIFI_UPDATE: self.wifi_update,
}
示例10: slave_conf_init
def slave_conf_init():
file = DaemonConfigParser(SLAVE_CONF_FILE_TO);
#KEY
KEY = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(128))
KEY = md5(KEY.encode('utf-8')).hexdigest()
file.writeValueFromSection('personnal_key', 'aes', KEY);
#KNX Interface
knx_edit = 'KNXD_OPTS="-e 1.0.254 -D -T -S -b '
if os.path.exists('/dev/ttyAMA0'):
knx_edit = knx_edit + 'tpuarts:/dev/ttyAMA0"';
elif os.path.exists('/dev/ttyS0'):
knx_edit = knx_edit + 'tpuarts:/dev/ttyS0"';
else:
knx_edit = knx_edit + 'ipt:127.0.0.1"';
conf_knx = open('/etc/knxd.conf', 'w');
conf_knx.write(knx_edit + '\n');
conf_knx.close();
示例11: master_conf_init
def master_conf_init():
file = DaemonConfigParser(SLAVE_CONF_FILE);
personnal_key = file.getValueFromSection('personnal_key', 'aes');
hostname = socket.gethostname();
#KNX Interface
if os.path.exists('/dev/ttyAMA0'):
knx = "tpuarts"
knx_interface = 'ttyAMA0';
elif os.path.exists('/dev/ttyS0'):
knx = "tpuarts"
knx_interface = 'ttyS0';
else:
knx = "ipt"
knx_interface = '127.0.0.1';
domoslave = os.popen("dpkg-query -W -f='${Version}\n' domoslave").read().split('\n')[0];
query1 = "INSERT INTO daemon (name, serial, secretkey, validation, version) VALUES ('"+hostname+"','"+hostname+"','"+personnal_key+"',1,'"+domoslave+"')"
query2 = "INSERT INTO daemon_protocol (daemon_id, protocol_id, interface, interface_arg) VALUES (1,1,'"+knx+"','"+knx_interface+"')"
call(['mysql', '--defaults-file=/etc/mysql/debian.cnf', 'domoleaf',
'-e', query1]);
call(['mysql', '--defaults-file=/etc/mysql/debian.cnf', 'domoleaf',
'-e', query2]);
示例12: __init__
def __init__(self, slave_keys):
self.knx_function = {
OPTION_ON_OFF : self.send_knx_write_short_to_slave,
OPTION_VAR : self.send_knx_write_long_to_slave,
OPTION_UP_DOWN : self.send_knx_write_short_to_slave,
OPTION_OPEN_CLOSE : self.send_knx_write_short_to_slave,
OPTION_STOP_UP_DOWN : self.send_knx_write_short_to_slave,
OPTION_TEMPERATURE_W: self.send_knx_write_temp
};
self.sql = MasterSql();
self._parser = DaemonConfigParser('/etc/greenleaf/master.conf');
self.aes_slave_keys = slave_keys;
示例13: __init__
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
};
示例14: master_conf_initdb
def master_conf_initdb():
file = DaemonConfigParser(MASTER_CONF_FILE_TO);
#mysql password
password = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(128))
password = sha1(password.encode('utf-8'))
file.writeValueFromSection('mysql', 'password', password.hexdigest());
os.system('sed -i "s/define(\'DB_PASSWORD\', \'domoleaf\')/define(\'DB_PASSWORD\', \''+password.hexdigest()+'\')/g" /etc/domoleaf/www/config.php')
#mysql user
query1 = 'DELETE FROM user WHERE User="domoleaf"';
query2 = 'DELETE FROM db WHERE User="domoleaf"';
query3 = 'INSERT INTO user (Host, User, Password) VALUES (\'%\', \'domoleaf\', PASSWORD(\''+password.hexdigest()+'\'));';
query4 = 'INSERT INTO db (Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Create_tmp_table_priv, Lock_tables_priv, Create_view_priv, Show_view_priv, Create_routine_priv, Alter_routine_priv, Execute_priv, Event_priv, Trigger_priv) VALUES ("%","domoleaf","domoleaf","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y");';
query5 = 'FLUSH PRIVILEGES';
Popen(['mysql', '--defaults-file=/etc/mysql/debian.cnf', 'mysql', '-e', query1], stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=-1);
Popen(['mysql', '--defaults-file=/etc/mysql/debian.cnf', 'mysql', '-e', query2], stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=-1);
Popen(['mysql', '--defaults-file=/etc/mysql/debian.cnf', 'mysql', '-e', query3], stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=-1);
Popen(['mysql', '--defaults-file=/etc/mysql/debian.cnf', 'mysql', '-e', query4], stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=-1);
Popen(['mysql', '--defaults-file=/etc/mysql/debian.cnf', 'mysql', '-e', query5], stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=-1);
示例15: __init__
def __init__(self, log_flag = True):
self.logger = Logger(log_flag, '/var/log/domomaster.log');
self._parser = DaemonConfigParser(MASTER_CONF_FILE);
self.db_username = self._parser.getValueFromSection(MASTER_CONF_MYSQL_SECTION,
MASTER_CONF_MYSQL_USER_ENTRY);
self.db_passwd = self._parser.getValueFromSection(MASTER_CONF_MYSQL_SECTION,
MASTER_CONF_MYSQL_PASSWORD_ENTRY);
self.db_dbname = self._parser.getValueFromSection(MASTER_CONF_MYSQL_SECTION,
MASTER_CONF_MYSQL_DB_NAME_ENTRY);
if not self.db_username or not self.db_passwd or not self.db_dbname:
frameinfo = getframeinfo(currentframe());
self.logger.info("[ MASTER DAEMON " + frameinfo.filaname + ":" + str(frameinfo.lineno) + " ]: initialization error: wrong or missing SQL configuration.");
sys.exit(1);