示例#1
0
def add_peers2cfg(_peers, _node):
    """[summary]

    Arguments:
        _peers {[type]} -- [description]
        _node {[type]} -- [description]
    """
    data_path = _peers
    p2p_list = []
    node_send = []
    utils.file_must_exists(data_path)
    try:
        for line in open(data_path):
            peer = line.strip('\n')
            utils.valid_peer(peer)
            p2p_list.append(peer)
    except Exception as ini_exp:
        LOGGER.error(
            ' add peers %s file failed, exception is %s', data_path, ini_exp)
        raise MCError(
            ' add peers %s file failed, exception is %s' % (data_path, ini_exp))
    LOGGER.info('merge peers is %s', p2p_list)
    p2p_list = list(set(p2p_list))
    node_send = utils.get_all_nodes_dir(_node)
    for node_file in node_send:
        utils.file_must_exists('{}/config.ini'.format(node_file))
        merge_cfg(p2p_list, '{}/config.ini'.format(node_file))
示例#2
0
def add_group(_group, _node):
    """
    Arguments:
        _group {[type]} -- [description]
        _node {[type]} -- [description]
    """
    data_path = _group
    node_send = []
    utils.file_must_exists(data_path)
    file_name = os.path.basename(data_path)
    group_id = utils.valid_genesis(file_name)
    if group_id == 0:
        raise MCError(' paser %s file failed' % (data_path))
    node_name = os.path.basename(os.path.normpath(_node))
    if utils.valid_node_dir(node_name):
        utils.file_must_not_exists('{}/conf/{}'.format(_node, file_name))
        shutil.copyfile(data_path, '{}/conf/{}'.format(_node, file_name))
        shutil.copyfile('{}/tpl/group.i.ini'.format(path.get_path()),
                        '{}/conf/group.{}.ini'.format(_node, group_id))
    else:
        node_send = utils.get_all_nodes_dir(_node)
        for node_file in node_send:
            utils.file_must_not_exists('{}/conf/{}'.format(
                node_file, file_name))
            shutil.copyfile(data_path,
                            '{}/conf/{}'.format(node_file, file_name))
            shutil.copyfile('{}/tpl/group.i.ini'.format(path.get_path()),
                            '{}/conf/group.{}.ini'.format(node_file, group_id))