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))
def read_peers(data_path): """[read peers] Arguments: data_path {[file]} -- [peers file] """ # read and parser peer file try: for line in open(data_path): peer = line.strip('\n') utils.valid_peer(peer) MchainConf.peers.append(peer) except Exception as ini_exp: LOGGER.error(' open %s file failed, exception is %s', data_path, ini_exp) raise MCError(' open %s file failed, exception is %s' % (data_path, ini_exp)) MchainConf.peers = list(set(MchainConf.peers)) LOGGER.info('peers is %s', MchainConf.peers)