def test_list_files(): base_content = { 'val_int': 1, 'val_str': 'str', 'val_bytes': b'\x00', 'val_bool': True } base_dir = 'list_dir/' num_files = 100 all_contents = {} for x in range(num_files): base_content['val_int'] += 1 base_content['val_str'] += str(x) base_content['val_bytes'] += x.to_bytes(1, 'big') base_content['val_bool'] = not base_content['val_bool'] all_contents[f'file_{x}.yml'] = dict(base_content) for x in range(num_files): file_name = f'file_{x}.yml' file_helper.write(base_dir + file_name, all_contents[file_name]) filenames = file_helper.list_files(base_dir) for x in range(num_files): assert file_helper.read(base_dir + filenames[x]) == \ all_contents[filenames[x]]
def __search_node_by_addr(self, addr: bytes) -> str: filenames = file_helper.list_files(base_dir + node_dir) for f in filenames: node_data = NodeData.load(base_dir + node_dir + f) if addr == node_data.addr: return node_data.name return ''
def __search_application_by_aid(self, aid: int) -> str: filenames = file_helper.list_files(base_dir + app_dir) for f in filenames: app_data = ApplicationData.load(base_dir + app_dir + f) app_aid = crypto.k4(n=app_data.key) if app_aid == aid: return app_data.name return None
def __search_network_by_nid(self, nid: int) -> NetworkData: filenames = file_helper.list_files(base_dir + net_dir) for f in filenames: net_data = NetworkData.load(base_dir + net_dir + f) net_nid, _, _ = self._gen_security_material(net_data) if net_nid == nid: return net_data return None
def net_key_index_list() -> list: filenames = file_helper.list_files(base_dir + net_dir) if not filenames: return [] net_key_indexes = [] for file in filenames: net = NetworkData.load(base_dir + net_dir + file) net_key_indexes.append(net.key_index) return net_key_indexes
def node_addr_list() -> list: filenames = file_helper.list_files(base_dir + node_dir) if not filenames: return [] node_addrs = [] for file in filenames: node = NodeData.load(base_dir + node_dir + file) node_addrs.append(node.addr) return node_addrs
def find_group_by_addr(target_addr: bytes) -> GroupData: filenames = file_helper.list_files(base_dir + group_dir) if not filenames: return False for file in filenames: group = GroupData.load(base_dir + group_dir + file) if target_addr == group.addr: return group return None
def group_name_list() -> list: filenames = file_helper.list_files(base_dir + group_dir) if not filenames: return False # remove file extension filenames_fmt = [] for file in filenames: filenames_fmt.append(file[:-4]) return filenames_fmt