def watch_node(node_label, filename, title): """Follow changes to a particular label. \b NODE_LABEL: Label for the node you wish to watch. e.g. 1026-5-a FILENAME: XML file containing the regulation TITLE: Title number""" initial_tree, builder = tree_and_builder(filename, title) initial_node = find(initial_tree, node_label) if initial_node: click.echo("> " + builder.doc_number) click.echo("\t" + pretty_change( {'action': 'POST', 'node': node_to_dict(initial_node)})) # search for label for version, changes in builder.changes_in_sequence(): if node_label in changes: click.echo("> " + version) for change in changes[node_label]: click.echo("\t" + pretty_change(change))
def test_pretty_changes(self): """Verify the output for a variety of "changes" """ self.assertEqual( changes.pretty_change({'action': 'DELETE'}), 'Deleted') self.assertEqual( changes.pretty_change({'action': 'RESERVE'}), 'Reserved') self.assertEqual( changes.pretty_change({'action': 'KEEP'}), 'Mentioned but not modified') self.assertEqual( changes.pretty_change({'action': 'DESIGNATE', 'destination': ['123', '43', 'a', '2']}), 'Moved to 123-43-a-2') node = {'text': 'Some Text'} change = {'action': 'PUT', 'node': node} self.assertEqual( changes.pretty_change(change), 'Modified: Some Text') change['action'] = 'POST' self.assertEqual( changes.pretty_change(change), 'Added: Some Text') node['title'] = 'A Title' self.assertEqual( changes.pretty_change(change), 'Added (title: A Title): Some Text') change['action'] = 'PUT' self.assertEqual( changes.pretty_change(change), 'Modified (title: A Title): Some Text') change['field'] = '[title]' self.assertEqual( changes.pretty_change(change), 'Title changed to: A Title') del node['title'] change['field'] = '[a field]' self.assertEqual( changes.pretty_change(change), 'A Field changed to: Some Text')
def watch_node(node_label, filename, title): """Follow changes to a particular label. \b NODE_LABEL: Label for the node you wish to watch. e.g. 1026-5-a FILENAME: XML file containing the regulation TITLE: Title number""" initial_tree, builder = tree_and_builder(filename, title) initial_node = find(initial_tree, node_label) if initial_node: click.echo("> " + builder.doc_number) click.echo("\t" + pretty_change({ 'action': 'POST', 'node': node_to_dict(initial_node) })) # search for label for version, changes in builder.changes_in_sequence(): if node_label in changes: click.echo("> " + version) for change in changes[node_label]: click.echo("\t" + pretty_change(change))
def test_pretty_changes(self): """Verify the output for a variety of "changes" """ self.assertEqual(changes.pretty_change({'action': 'DELETE'}), 'Deleted') self.assertEqual(changes.pretty_change({'action': 'RESERVE'}), 'Reserved') self.assertEqual(changes.pretty_change({'action': 'KEEP'}), 'Mentioned but not modified') self.assertEqual( changes.pretty_change({ 'action': 'DESIGNATE', 'destination': ['123', '43', 'a', '2'] }), 'Moved to 123-43-a-2') node = {'text': 'Some Text'} change = {'action': 'PUT', 'node': node} self.assertEqual(changes.pretty_change(change), 'Modified: Some Text') change['action'] = 'POST' self.assertEqual(changes.pretty_change(change), 'Added: Some Text') node['title'] = 'A Title' self.assertEqual(changes.pretty_change(change), 'Added (title: A Title): Some Text') change['action'] = 'PUT' self.assertEqual(changes.pretty_change(change), 'Modified (title: A Title): Some Text') change['field'] = '[title]' self.assertEqual(changes.pretty_change(change), 'Title changed to: A Title') del node['title'] change['field'] = '[a field]' self.assertEqual(changes.pretty_change(change), 'A Field changed to: Some Text')
pass from regparser.builder import tree_and_builder from regparser.notice.changes import node_to_dict, pretty_change from regparser.tree.struct import find if __name__ == "__main__": parser = argparse.ArgumentParser(description="Node Watcher") parser.add_argument( 'node_label', help='Label for the node you wish to watch. e.g. 1026-5-a') parser.add_argument('filename', help='XML file containing the regulation') parser.add_argument('title', type=int, help='Title number') args = parser.parse_args() initial_tree, builder = tree_and_builder(args.filename, args.title) initial_node = find(initial_tree, args.node_label) if initial_node: print("> " + builder.doc_number) print("\t" + pretty_change( {'action': 'POST', 'node': node_to_dict(initial_node)})) # search for label for version, changes in builder.changes_in_sequence(): if args.node_label in changes: print("> " + version) for change in changes[args.node_label]: print("\t" + pretty_change(change))
pass from regparser.builder import tree_and_builder from regparser.notice.changes import node_to_dict, pretty_change from regparser.tree.struct import find if __name__ == "__main__": parser = argparse.ArgumentParser(description="Node Watcher") parser.add_argument( 'node_label', help='Label for the node you wish to watch. e.g. 1026-5-a') parser.add_argument('filename', help='XML file containing the regulation') parser.add_argument('title', type=int, help='Title number') args = parser.parse_args() initial_tree, builder = tree_and_builder(args.filename, args.title) initial_node = find(initial_tree, args.node_label) if initial_node: print("> " + builder.doc_number) print("\t" + pretty_change({ 'action': 'POST', 'node': node_to_dict(initial_node) })) # search for label for version, changes in builder.changes_in_sequence(): if args.node_label in changes: print("> " + version) for change in changes[args.node_label]: print("\t" + pretty_change(change))