def checkfields(contents, errs, prettypath):
    refn_f = re_refn.findall(contents)
    name_f = re_name.findall(contents)
    foot_f = re_fp.findall(contents)
    data_f = re_ds.findall(contents)
    code_f = re_oc.findall(contents)

    fields = ((refn_f, "reference"), (name_f, "name"), (foot_f, "footprint"),
              (data_f, "datasheet"), (code_f, "order code"))

    for field, fn in fields:
        for value, x, y, size, orient, visible, hjust, vjust in field:
            if fn in ("reference", "name"):
                if visible != "V":
                    if "#invisible{}".format(fn) not in contents:
                        errs.append("Field {} not visible".format(fn))
            else:
                if visible != "I":
                    errs.append("Field {} visible".format(fn))
            if orient != "H":
                errs.append("Field {} not horizontal".format(fn))
            if size != "50":
                errs.append("Field {} font size not 50".format(fn))

    refn_y = int(refn_f[0][2])
    name_y = int(name_f[0][2])

    if refn_y <= name_y:
        errs.append("Component reference not above component name")

    fp = foot_f[0][0][1:-1]
    if fp.startswith("agg:"):
        fp = fp.split(":")[1] + ".kicad_mod"
        path = os.path.join(prettypath, fp)
        if not os.path.exists(path):
            errs.append("Component references non-existent footprint {}"
                        .format(fp))
    elif len(fp) > 0 and ":" not in fp:
        errs.append("Footprint '{}' does not specify a library name"
                    .format(fp))
dataset/ETHPy150Open adamgreig/agg-kicad/scripts/check_lib.py/checkfields/original