Ejemplo n.º 1
0
def run(globaldb, localdb, verbose=False):

    local_db_files = list()
    work_db_files = list()

    # get DB files

    global_entries = {}
    local_entries = {}
    final_entries = {}

    verbose and print("removing %s from %s" % (localdb, globaldb))
    # parse global db
    for line, (tag, bits, mode) in util.parse_db_lines(globaldb):
        global_entries[tag] = bits
    # parse local db
    for line, (tag, bits, mode) in util.parse_db_lines(localdb):
        local_entries[tag] = bits

    for entry in global_entries:
        if entry not in local_entries:
            final_entries[entry] = global_entries[entry]
        else:
            verbose and print("Removing entry %s" % entry)

    util.write_db_lines(globaldb, final_entries)
Ejemplo n.º 2
0
def run(fn_ins, fn_out, strict=False, verbose=False):
    # tag to bits
    entries = {}
    # tag to (bits, line)
    tags = dict()
    # bits to (tag, line)
    bitss = dict()

    for fn_in in fn_ins:
        for line, (tag, bits, mode) in util.parse_db_lines(fn_in):
            line = line.strip()
            assert mode is not None or mode != "always", "strict: got ill defined line: %s" % (
                line, )

            if tag in tags:
                orig_bits, orig_line = tags[tag]
                if orig_bits != bits:
                    print("WARNING: got duplicate tag %s" % (tag, ))
                    print("  Orig line: %s" % orig_line)
                    print("  New line : %s" % line)
                    assert not strict, "strict: got duplicate tag"
            if bits in bitss:
                orig_tag, orig_line = bitss[bits]
                if orig_tag != tag:
                    print("WARNING: got duplicate bits %s" % (bits, ))
                    print("  Orig line: %s" % orig_line)
                    print("  New line : %s" % line)
                    assert not strict, "strict: got duplicate bits"

            entries[tag] = bits
            tags[tag] = (bits, line)
            if bits != None:
                bitss[bits] = (tag, line)

    util.write_db_lines(fn_out, entries)
Ejemplo n.º 3
0
def run(fn_ins, fn_out, strict=False, track_origin=False, verbose=False):
    # tag to bits
    entries = {}
    # tag to (bits, line)
    tags = dict()
    # bits to (tag, line)
    bitss = dict()

    for fn_in in fn_ins:
        for line, (tag, bits, mode, origin) in util.parse_db_lines(fn_in):
            line = line.strip()
            assert mode is not None or mode != "always", "strict: got ill defined line: %s" % (
                line, )

            if tag in tags:
                orig_bits, orig_line, orig_origin = tags[tag]
                if orig_bits != bits:
                    print(
                        "WARNING: got duplicate tag %s" % (tag, ),
                        file=sys.stderr)
                    print("  Orig line: %s" % orig_line, file=sys.stderr)
                    print("  New line : %s" % line, file=sys.stderr)
                    assert not strict, "strict: got duplicate tag"
                origin = os.path.basename(os.getcwd())
                if track_origin and orig_origin != origin:
                    origin = orig_origin + "," + origin
            if bits in bitss:
                orig_tag, orig_line = bitss[bits]
                if orig_tag != tag:
                    print(
                        "WARNING: got duplicate bits %s" % (bits, ),
                        file=sys.stderr)
                    print("  Orig line: %s" % orig_line, file=sys.stderr)
                    print("  New line : %s" % line, file=sys.stderr)
                    assert not strict, "strict: got duplicate bits"

            if track_origin and origin is None:
                origin = os.path.basename(os.getcwd())
            entries[tag] = (bits, origin)
            tags[tag] = (bits, line, origin)
            if bits != None:
                bitss[bits] = (tag, line)

    util.write_db_lines(fn_out, entries, track_origin)
Ejemplo n.º 4
0
def run(fn_in, fn_out, groups_fn, verbose=False):
    groups_in = load_groups(groups_fn)
    groups = index_masks(fn_in, groups_in)
    new_db = apply_masks(fn_in, groups)
    util.write_db_lines(fn_out, new_db)