from os import path import re handlers_file = '/Users/rshield/Documents/THE_ORCHARD/CODE/GIT/FORKS/ows-analytics/analytics/handlers.py' participant_handlers_file = '/Users/rshield/Documents/THE_ORCHARD/CODE/GIT/FORKS/ows-analytics/analytics/participant_handlers.py' config_file = '/Users/rshield/Documents/THE_ORCHARD/CODE/GIT/FORKS/ows-analytics/analytics/config.py' mapper = { '_sound_recording': '/sound-recording/', '_videos': '/videos/', '_participant': '/participant/', '_product': '/product/', '_channels': '/channels/'} def find_handled_paths(): parts = [] with open(handlers_file, 'r') as f: for line in f: needle = re.search("(^@app.route\(config.[A-Z_]*\))", line) if(needle): theneedle = needle.group() theparts = theneedle.split('.') parts.append(theparts[2].rstrip(')')) with open(participant_handlers_file) as ff: for line in ff: needle = re.search("(^@app.route\(config.[A-Z_]*\))", line) if(needle): theneedle = needle.group() theparts = theneedle.split('.') parts.append(theparts[2].rstrip(')')) return parts def find_paths_in_config(): paths = [] with open(config_file) as cf: for line in cf: needle = re.findall("^([A-Z_]*_PATH) = ((_[a-z]*)+)\(\'(.*)\'\)", line) if(needle): paths.append(needle[0]) return paths def format_paths(unformatted_paths): for cp in unformatted_paths: detail = cp[3] pre_path = cp[1] if(pre_path != ''): detail = f"{mapper[pre_path]}{detail}" print(detail) if __name__ == "__main__": config_paths = find_paths_in_config() handled_paths = find_handled_paths() for cf in config_paths: needle = cf[0] if needle not in handled_paths: print(f'this path is configured, but not handled: {needle}') for hp in handled_paths: found = False for cp in config_paths: if cp[0]==hp: found = True break if not found: print(f'handled but not configured {hp}')