def get_changes_chain_for_election_id(election_id, config, tree, node_changes): ''' Gets a complete list of changes to apply to an election ''' changes_chain = [] # contains self ancestors = get_ancestors(tree, election_id) + [election_id] for ancestor_id in ancestors: changes_chain = changes_chain + node_changes[ancestor_id] return changes_chain, ancestors
def list_ids(config, changes_path, action, ids_path=None): ''' Executes print actions related to the listing of election ids from the changes file. Available actions are 'tree', 'edges', 'leaves' and 'all'. ''' changes = get_changes_config(changes_path) tree = get_changes_tree(changes) l = [] def add_others(l, ids_path): other_ids = [] with open(ids_path, mode='r', encoding="utf-8", errors='strict') as f: for line in f: line = line.strip() other_ids.append(line) l = list(set(other_ids + l)) l.sort() return l if action == 'tree': print(serialize(tree)) return elif action == 'leaves_ancestors': list_leaves(tree, l) l = add_others(l, ids_path) ancestors = dict() for election_id in l: ancestors[election_id] = get_ancestors(tree, election_id) + [election_id] for election_id in l: print(",".join(ancestors[election_id])) return if action == 'edges': list_edges(tree, l) elif action == 'leaves': list_leaves(tree, l) elif action == 'all_with_others': list_all(tree, l) l = add_others(l, ids_path) elif action == 'all': list_all(tree, l) l.sort() for election_id in l: print(election_id)