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


Python DaemonConfigParser.writeValueFromSection方法代码示例

本文整理汇总了Python中DaemonConfigParser.writeValueFromSection方法的典型用法代码示例。如果您正苦于以下问题:Python DaemonConfigParser.writeValueFromSection方法的具体用法?Python DaemonConfigParser.writeValueFromSection怎么用?Python DaemonConfigParser.writeValueFromSection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DaemonConfigParser的用法示例。


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

示例1: master_conf_initdb

# 需要导入模块: import DaemonConfigParser [as 别名]
# 或者: from DaemonConfigParser import writeValueFromSection [as 别名]
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,
    )
开发者ID:giorda-a,项目名称:Domoleaf,代码行数:61,代码来源:domomaster_postinst.py

示例2: slave_conf_init

# 需要导入模块: import DaemonConfigParser [as 别名]
# 或者: from DaemonConfigParser import writeValueFromSection [as 别名]
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();
开发者ID:Fuere,项目名称:Domoleaf,代码行数:21,代码来源:domoslave_postinst.py

示例3: master_conf_initdb

# 需要导入模块: import DaemonConfigParser [as 别名]
# 或者: from DaemonConfigParser import writeValueFromSection [as 别名]
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);
开发者ID:couturg,项目名称:Domoleaf,代码行数:23,代码来源:domomaster_postinst.py

示例4: monitors

# 需要导入模块: import DaemonConfigParser [as 别名]
# 或者: from DaemonConfigParser import writeValueFromSection [as 别名]

#.........这里部分代码省略.........
                data2 = encode_obj.encrypt(json_str + (spaces * ' '));
                master.send(bytes(aes_IV, 'utf-8') + data2);
                master.close();
            except KeyError as e:
                self.logger.error('in send_data_to_all_masters: '+str(e));
                print(e);
                pass;

    def send_tech(self, json_obj, connection):
        json_str = json.JSONEncoder().encode(
            {
                "packet_type": "send_tech",
                "info": GLManager.TechInfo()
            }
        );
        self.send_data_to_all_masters(json_str);

    def send_alive(self, json_obj, connection):
        json_str = json.JSONEncoder().encode(
            {
                "packet_type": "send_alive",
                "info": GLManager.TechAlive()
            }
        );
        self.send_data_to_all_masters(json_str);

    def send_interfaces(self, json_obj, connection):
        try:
            if os.path.exists('/tmp/knxd'):
                call(['service', 'knxd', 'stop']);
            previous_val_knx = self._parser.getValueFromSection('knx', 'interface');
            previous_val_EnOcean = self._parser.getValueFromSection('enocean', 'interface');
            new_val = str(json_obj['interface_arg_knx'])
            self._parser.writeValueFromSection('knx', 'interface', new_val);
            self._parser.writeValueFromSection('knx', 'activated', str(json_obj['daemon_knx']));
            self._parser.writeValueFromSection('enocean', 'interface', str(json_obj['interface_arg_EnOcean']));
            if not previous_val_knx or previous_val_knx is None:
                call(['update-rc.d', 'knxd', 'defaults']);
                call(['update-rc.d', 'knxd', 'enable']);
            if not new_val or new_val is None:
                Popen(['systemctl', '-q', 'disable', 'knxd']);
            else:
                knx_edit = 'KNXD_OPTS="-e 1.0.254 -D -T -S -b ';
                if json_obj['interface_knx'] == 'tpuarts':
                    knx_edit += json_obj['interface_knx']+':/dev/'+new_val+'"';
                else:
                    knx_edit += json_obj['interface_knx']+':'+new_val+'"';
                conf_knx = open('/etc/knxd.conf', 'w');
                conf_knx.write(knx_edit+'\n');
                conf_knx.close();
                call(['service', 'knxd', 'start']);
                if json_obj['daemon_knx'] == 1:
                    if os.path.exists('/var/run/monitor_knx.pid'):
                        os.remove('/var/run/monitor_knx.pid');
                    Popen(['monitor_knx', 'ip:localhost', '--daemon']);
        except Exception as e:
            self.logger.error(e);
        json_str = '{"packet_type": "send_interfaces", "aes_pass": "' + self.private_aes + '"}';
        master_hostname = str(json_obj['sender_name']);
        encrypt_IV = AESManager.get_IV();
        spaces = 16 - len(json_str) % 16;
        json_str = json_str + (spaces * ' ');
        encode_obj = AES.new(self.private_aes, AES.MODE_CBC, encrypt_IV);
        data = encode_obj.encrypt(json_str);
        connection.send(bytes(encrypt_IV, 'utf-8') + data);
        if previous_val_EnOcean != str(json_obj['interface_arg_EnOcean']):
开发者ID:Fuere,项目名称:Domoleaf,代码行数:70,代码来源:SlaveDaemon.py

示例5: slave_conf_copy

# 需要导入模块: import DaemonConfigParser [as 别名]
# 或者: from DaemonConfigParser import writeValueFromSection [as 别名]
def slave_conf_copy():
    file_from = DaemonConfigParser(SLAVE_CONF_FILE_FROM);
    file_to   = DaemonConfigParser(SLAVE_CONF_FILE_TO);
    
    #listen
    var = file_from.getValueFromSection('listen', 'port');
    file_to.writeValueFromSection('listen', 'port', var);
    
    #connect
    var = file_from.getValueFromSection('connect', 'port');
    file_to.writeValueFromSection('connect', 'port', var);
    
    #knx
    var = file_from.getValueFromSection('knx', 'port');
    file_to.writeValueFromSection('knx', 'port', var);
    var = file_from.getValueFromSection('knx', 'interface');
    file_to.writeValueFromSection('knx', 'interface', var);
    var = file_from.getValueFromSection('knx', 'activated');
    file_to.writeValueFromSection('knx', 'activated', var);
    
    #enocean
    var = file_from.getValueFromSection('enocean', 'port');
    file_to.writeValueFromSection('enocean', 'port', var);
    var = file_from.getValueFromSection('enocean', 'interface');
    file_to.writeValueFromSection('enocean', 'interface', var);
    
    #cron
    var = file_from.getValueFromSection('cron', 'port');
    file_to.writeValueFromSection('cron', 'port', var);
    var = file_from.getValueFromSection('cron', 'address');
    file_to.writeValueFromSection('cron', 'address', var);
    
    #personnal_key
    var = file_from.getValueFromSection('personnal_key', 'aes');
    file_to.writeValueFromSection('personnal_key', 'aes', var);
    
    #openvpn
    var = file_from.getValueFromSection('openvpn', 'openvpnserver');
    file_to.writeValueFromSection('openvpn', 'openvpnserver', var);
开发者ID:Fuere,项目名称:Domoleaf,代码行数:41,代码来源:domoslave_postinst.py

示例6: master_conf_copy

# 需要导入模块: import DaemonConfigParser [as 别名]
# 或者: from DaemonConfigParser import writeValueFromSection [as 别名]
def master_conf_copy():
    file_from = DaemonConfigParser(MASTER_CONF_FILE_BKP)
    file_to = DaemonConfigParser(MASTER_CONF_FILE_TO)

    # listen
    var = file_from.getValueFromSection("listen", "port_slave")
    file_to.writeValueFromSection("listen", "port_slave", var)
    var = file_from.getValueFromSection("listen", "port_cmd")
    file_to.writeValueFromSection("listen", "port_cmd", var)

    # connect
    var = file_from.getValueFromSection("connect", "port")
    file_to.writeValueFromSection("connect", "port", var)

    # mysql
    var = file_from.getValueFromSection("mysql", "user")
    file_to.writeValueFromSection("mysql", "user", var)
    var = file_from.getValueFromSection("mysql", "database_name")
    file_to.writeValueFromSection("mysql", "database_name", var)

    # greenleaf
    var = file_from.getValueFromSection("greenleaf", "commercial")
    file_to.writeValueFromSection("greenleaf", "commercial", var)
    var = file_from.getValueFromSection("greenleaf", "admin_addr")
    file_to.writeValueFromSection("greenleaf", "admin_addr", var)
开发者ID:giorda-a,项目名称:Domoleaf,代码行数:27,代码来源:domomaster_postinst.py

示例7: master_conf_copy

# 需要导入模块: import DaemonConfigParser [as 别名]
# 或者: from DaemonConfigParser import writeValueFromSection [as 别名]
def master_conf_copy():
    file_from = DaemonConfigParser(MASTER_CONF_FILE_BKP);
    file_to   = DaemonConfigParser(MASTER_CONF_FILE_TO);
    
    #listen
    var = file_from.getValueFromSection('listen', 'port_slave');
    file_to.writeValueFromSection('listen', 'port_slave', var);
    var = file_from.getValueFromSection('listen', 'port_cmd');
    file_to.writeValueFromSection('listen', 'port_cmd', var);
    
    #connect
    var = file_from.getValueFromSection('connect', 'port');
    file_to.writeValueFromSection('connect', 'port', var);
    
    #mysql
    var = file_from.getValueFromSection('mysql', 'user');
    file_to.writeValueFromSection('mysql', 'user', var);
    var = file_from.getValueFromSection('mysql', 'database_name');
    file_to.writeValueFromSection('mysql', 'database_name', var);
    
    #greenleaf
    var = file_from.getValueFromSection('greenleaf', 'commercial');
    file_to.writeValueFromSection('greenleaf', 'commercial', var);
    var = file_from.getValueFromSection('greenleaf', 'admin_addr');
    file_to.writeValueFromSection('greenleaf', 'admin_addr', var);
开发者ID:couturg,项目名称:Domoleaf,代码行数:27,代码来源:domomaster_postinst.py

示例8: __init__

# 需要导入模块: import DaemonConfigParser [as 别名]
# 或者: from DaemonConfigParser import writeValueFromSection [as 别名]

#.........这里部分代码省略.........
                self.logger.error("in send_data_to_all_masters: " + str(e))
                pass

    ## Sends the informations about the slave to all masters available.
    #
    # @param json_obj Not used here.
    # @param connection Not used here.
    # @return None
    def send_tech(self, json_obj, connection):
        json_str = json.JSONEncoder().encode({"packet_type": "send_tech", "info": GLManager.TechInfo()})
        self.send_data_to_all_masters(json_str)

    ## Sends that the salve daemon is alive to all masters available.
    #
    # @param json_obj Not used here.
    # @param connection Not used here.
    # @return None
    def send_alive(self, json_obj, connection):
        json_str = json.JSONEncoder().encode({"packet_type": "send_alive", "info": GLManager.TechAlive()})
        self.send_data_to_all_masters(json_str)

    ## Sends the protocol interface informations to all masters available.
    #
    # @param json_obj Protocol interface informations.
    # @param connection Connection object used to send the response.
    # @return None
    def send_interfaces(self, json_obj, connection):
        try:
            if os.path.exists("/tmp/knxd"):
                call(["service", "knxd", "stop"])
            previous_val_knx = self._parser.getValueFromSection("knx", "interface")
            previous_val_EnOcean = self._parser.getValueFromSection("enocean", "interface")
            new_val = str(json_obj["interface_arg_knx"])
            self._parser.writeValueFromSection("knx", "interface", new_val)
            self._parser.writeValueFromSection("knx", "activated", str(json_obj["daemon_knx"]))
            self._parser.writeValueFromSection("enocean", "interface", str(json_obj["interface_arg_EnOcean"]))
            if not previous_val_knx or previous_val_knx is None:
                call(["update-rc.d", "knxd", "defaults"])
                call(["update-rc.d", "knxd", "enable"])
            if not new_val or new_val is None:
                Popen(["systemctl", "-q", "disable", "knxd"])
            else:
                knx_edit = 'KNXD_OPTS="-e 1.0.254 -D -T -S -b '
                if json_obj["interface_knx"] == "tpuarts":
                    knx_edit += json_obj["interface_knx"] + ":/dev/" + new_val + '"'
                else:
                    knx_edit += json_obj["interface_knx"] + ":" + new_val + '"'
                conf_knx = open("/etc/knxd.conf", "w")
                conf_knx.write(knx_edit + "\n")
                conf_knx.close()
                call(["service", "knxd", "start"])
                if json_obj["daemon_knx"] == 1:
                    if os.path.exists("/var/run/monitor_knx.pid"):
                        os.remove("/var/run/monitor_knx.pid")
                    Popen(["monitor_knx", "ip:localhost", "--daemon"])
        except Exception as e:
            self.logger.error(e)
        json_str = '{"packet_type": "send_interfaces", "aes_pass": "' + self.private_aes + '"}'
        master_hostname = str(json_obj["sender_name"])
        encrypt_IV = AESManager.get_IV()
        spaces = 16 - len(json_str) % 16
        json_str = json_str + (spaces * " ")
        encode_obj = AES.new(self.private_aes, AES.MODE_CBC, encrypt_IV)
        data = encode_obj.encrypt(json_str)
        connection.send(bytes(encrypt_IV, "utf-8") + data)
        if previous_val_EnOcean != str(json_obj["interface_arg_EnOcean"]):
开发者ID:V-Paranoiaque,项目名称:Domoleaf,代码行数:70,代码来源:SlaveDaemon.py


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