Exemplo n.º 1
0
def write_layers(client, only_title, only_part):
    """Write all layers that match the filtering criteria. If CFR title/part
    are used to filter, only process CFR layers. Otherwise, process all
    layers."""
    for layer_dir in utils.relevant_paths(entry.Layer.cfr(), only_title,
                                          only_part):
        _, cfr_title, cfr_part, version_id = layer_dir.path
        for layer_name in layer_dir:
            layer = (layer_dir / layer_name).read()
            doc_id = version_id + '/' + cfr_part
            client.layer(layer_name, 'cfr', doc_id).write(layer)

    if only_title is None and only_part is None:
        non_cfr_doc_types = [doc_type for doc_type in entry.Layer()
                             if doc_type != 'cfr']
        for doc_type in non_cfr_doc_types:
            for doc_id in entry.Layer(doc_type):
                for layer_name in entry.Layer(doc_type, doc_id):
                    layer = entry.Layer(doc_type, doc_id, layer_name).read()
                    client.layer(layer_name, doc_type, doc_id).write(layer)
Exemplo n.º 2
0
def is_stale(cfr_title, cfr_part, version_id):
    """Modify and process dependency graph related to a single SxS layer"""
    deps = dependency.Graph()
    layer_entry = entry.Layer(cfr_title, cfr_part, version_id, 'analyses')

    # Layers depend on their associated tree
    deps.add(layer_entry, entry.Tree(cfr_title, cfr_part, version_id))
    # And on all notices which came before
    for sxs_entry in previous_sxs(cfr_title, cfr_part, version_id):
        deps.add(layer_entry, sxs_entry)

    deps.validate_for(layer_entry)
    return deps.is_stale(layer_entry)
Exemplo n.º 3
0
def sxs_layers(cfr_title, cfr_part):
    """Build SxS layers for all known versions."""
    logger.info("Build SxS layers - %s CFR %s", cfr_title, cfr_part)

    tree_dir = entry.Tree(cfr_title, cfr_part)
    for version_id in tree_dir:
        if is_stale(cfr_title, cfr_part, version_id):
            tree = (tree_dir / version_id).read()
            notices = [
                sxs.read()
                for sxs in previous_sxs(cfr_title, cfr_part, version_id)
            ]
            layer_json = SectionBySection(tree, notices).build()
            entry.Layer(cfr_title, cfr_part, version_id,
                        'analyses').write(layer_json)
Exemplo n.º 4
0
def stale_layers(doc_entry, doc_type):
    """Return the name of layer dependencies which are now stale. Limit to a
    particular doc_type"""
    deps = dependency.Graph()
    layer_dir = entry.Layer(doc_type, *doc_entry.path)
    for layer_name in LAYER_CLASSES[doc_type]:
        # Layers depend on their associated tree
        deps.add(layer_dir / layer_name, doc_entry)
    if doc_type == 'cfr':
        # Meta layer also depends on the version info
        deps.add(layer_dir / 'meta', entry.Version(*doc_entry.path))

    for layer_name in LAYER_CLASSES[doc_type]:
        layer_entry = layer_dir / layer_name
        deps.validate_for(layer_entry)
        if deps.is_stale(layer_entry):
            yield layer_name
Exemplo n.º 5
0
def write_layers(client, only_title, only_part):
    """Write all layers that match the filtering criteria. If CFR title/part
    are used to filter, only process CFR layers. Otherwise, process all
    layers."""
    for layer_entry in utils.relevant_paths(entry.Layer.cfr(), only_title,
                                            only_part):
        _, _, cfr_part, version_id, layer_name = layer_entry.path
        layer = layer_entry.read()
        doc_id = version_id + '/' + cfr_part
        client.layer(layer_name, 'cfr', doc_id).write(layer)

    if only_title is None and only_part is None:
        for sub_entry in entry.Layer().sub_entries():
            if sub_entry.path[0] == 'cfr':
                continue
            doc_type, doc_id, layer_name = sub_entry.path
            layer = sub_entry.read()
            client.layer(layer_name, doc_type, doc_id).write(layer)