Пример #1
0
def build_from(filename, title, act_title, act_section, generate_diffs,
               checkpoint, version_identifier):
    """Build all data from provided xml. Reads the provided file and builds
    all versions of the regulation, its layers, etc. that follow.

    \b
    FILENAME: XML file containing the regulation
    TITLE: CFR title
    """
    act_title_and_section = [act_title, act_section]
    #   First, the regulation tree
    reg_tree, builder = tree_and_builder(filename, title, checkpoint,
                                         version_identifier)
    builder.write_notices()

    #   Always do at least the first reg
    logger.info("Version %s", builder.doc_number)
    builder.write_regulation(reg_tree)
    layer_cache = LayerCacheAggregator()

    builder.gen_and_write_layers(reg_tree, act_title_and_section, layer_cache)
    layer_cache.replace_using(reg_tree)

    if generate_diffs:
        gen_diffs(reg_tree, act_title_and_section, builder, layer_cache)
Пример #2
0
def ecfr_all(title, file, act_title, act_section,
         with_all_versions=False, without_versions=False,
         without_notices=False, only_notice=None):
    """ Parse eCFR into RegML """

    # Get the tree and layers
    reg_tree, builder = tree_and_builder(
        file, title, writer_type='XML')
    layer_cache = LayerCacheAggregator()
    layers = builder.generate_layers(reg_tree,
                                     [act_title, act_section],
                                     layer_cache)

    # Do the first version
    last_version = builder.doc_number
    print("Version {}".format(last_version))
    if (only_notice is not None and builder.doc_number == only_notice) \
            or only_notice is None:
        if not without_versions:
            builder.write_regulation(reg_tree, layers=layers)

    for last_notice, old, new_tree, notices in builder.revision_generator(
            reg_tree):
        version = last_notice['document_number']
        print("Version {}".format(version))
        builder.doc_number = version
        layers = builder.generate_layers(new_tree,
                                         [act_title, act_section],
                                         layer_cache,
                                         notices)
        if (only_notice is not None and version == only_notice) or \
                only_notice is None:
            if with_all_versions:
                builder.write_regulation(new_tree, layers=layers)
            if not without_notices:
                builder.write_notice(version,
                                     old_tree=old,
                                     reg_tree=new_tree,
                                     layers=layers,
                                     last_version=last_version)
        layer_cache.invalidate_by_notice(last_notice)
        layer_cache.replace_using(new_tree)
        last_version = version
        del last_notice, old, new_tree, notices     # free some memory
Пример #3
0
def parse_regulation(args):
    """ Run the parser on the specified command-line arguments. Broken out
        into separate function to assist in profiling.
    """
    act_title_and_section = [args.act_title, args.act_section]
    #   First, the regulation tree
    reg_tree, builder = tree_and_builder(args.filename, args.title,
                                         args.checkpoint_dir, args.doc_number)
    builder.write_notices()

    #   Always do at least the first reg
    logger.info("Version %s", builder.doc_number)
    builder.write_regulation(reg_tree)
    layer_cache = LayerCacheAggregator()

    builder.gen_and_write_layers(reg_tree, act_title_and_section, layer_cache)
    layer_cache.replace_using(reg_tree)

    if args.generate_diffs:
        generate_diffs(reg_tree, act_title_and_section, builder, layer_cache)
Пример #4
0
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))
Пример #5
0
def generate_xml(filename,
                 title,
                 act_title,
                 act_section,
                 notice_doc_numbers,
                 doc_number=None,
                 checkpoint=None):

    act_title_and_section = [act_title, act_section]
    #   First, the regulation tree

    reg_tree, builder = tree_and_builder(filename,
                                         title,
                                         checkpoint,
                                         writer_type='XML')
    layer_cache = LayerCacheAggregator()
    layers = builder.generate_layers(reg_tree, act_title_and_section,
                                     layer_cache)

    # Always do at least the first reg
    logger.info("Version", builder.doc_number)
    builder.write_regulation(reg_tree, layers=layers)
    all_versions = {doc_number: FrozenNode.from_node(reg_tree)}

    for last_notice, old, new_tree, notices in builder.revision_generator(
            reg_tree):
        version = last_notice['document_number']
        logger.info("Version %s", version)
        all_versions[version] = FrozenNode.from_node(new_tree)
        builder.doc_number = version
        layers = builder.generate_layers(new_tree, act_title_and_section,
                                         layer_cache, notices)
        builder.write_regulation(new_tree, layers=layers)
        builder.write_notice(version,
                             old_tree=old,
                             reg_tree=new_tree,
                             layers=layers)
        layer_cache.invalidate_by_notice(last_notice)
        layer_cache.replace_using(new_tree)
        del last_notice, old, new_tree, notices  # free some memory
Пример #6
0
def parse_regulation(args):
    """ Run the parser on the specified command-line arguments. Broken out
        into separate function to assist in profiling.
    """

    act_title_and_section = [args.act_title, args.act_section]
    #   First, the regulation tree

    reg_tree, builder = tree_and_builder(args.filename, args.title,
                                         args.checkpoint)

    builder.write_notices()

    #   Always do at least the first reg
    logger.info("Version %s", builder.doc_number)
    builder.write_regulation(reg_tree)
    layer_cache = LayerCacheAggregator()

    builder.gen_and_write_layers(reg_tree, act_title_and_section, layer_cache)
    layer_cache.replace_using(reg_tree)

    if args.generate_diffs:
        generate_diffs(reg_tree, act_title_and_section, builder, layer_cache)
Пример #7
0
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))
Пример #8
0
    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))
Пример #9
0
    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))