Пример #1
0
def find_python_version(pylst):
    lst = []
    ids = []
    for interp in pylst:
        try:
            std, err = cover.exec_cmd([interp, "-V"])
            version = err.strip()
            if not version:
                # python 3.4+
                version = std.strip()
            if version[:6] == "Python":
                shver = version[6:].strip().replace(" ", "-")
                nid = shver
                nidn = 0
                while nid in ids:
                    nidn += 1
                    nid = shver + "-%d" % nidn
                ids.append(nid)
                lst.append((interp, nid, version))
            else:
                cover.err("Not a python", version)
                # no python found
                continue
        except:
            traceback.print_exc()
    return lst
Пример #2
0
def do_test(testfile, interps, dests, stats, hint=""):
    cover.log("Test", hint, ":", os.path.basename(testfile))
    info = cover.read_cover_info(testfile)
    resall = ""
    # prepare
    # do tests
    hasherr = []
    for interp in interps:
        if len(interps) < 6:
            resall += (interp[1] + " - ")
        res, desc = do_test_one(testfile, interp, info, dests[interp[1]])
        if res == "hasherror":
            hasherr.append(desc)
            #cover.log("HASH =", desc)
        # update statistic
        stats["_"]["_"] += 1
        stats["_"][res] = stats["_"].get(res, 0) + 1
        stats[interp[1]]["_"] += 1
        stats[interp[1]][res] = stats[interp[1]].get(res, 0) + 1
        resall += (res + " " * 10)[:6].upper()
        resall += "  "
    cover.log(resall)
    # test if all hash
    if len(interps) == len(hasherr):
        cover.err("All hashes wrong")
Пример #3
0
def find_python_version(pylst):
    lst = []
    ids = []
    for interp in pylst:
        try:
            std, err = cover.exec_cmd([interp, "-V"])
            version = err.strip()
            if not version:
                # python 3.4+
                version = std.strip()
            if version[:6] == "Python":
                shver = version[6:].strip().replace(" ", "-")
                nid = shver
                nidn = 0
                while nid in ids:
                    nidn += 1
                    nid = shver + "-%d" % nidn
                ids.append(nid)
                lst.append((interp, nid, version))
            else:
                cover.err("Not a python", version)
                # no python found
                continue
        except:
            traceback.print_exc()
    return lst
Пример #4
0
def do_test(testfile, interps, dests, stats, hint = ""):
    cover.log("Test", hint, ":", os.path.basename(testfile))
    info = cover.read_cover_info(testfile)
    resall = ""
    # prepare
    # do tests
    hasherr = []
    for interp in interps:
        if len(interps) < 6:
            resall += (interp[1] + " - ")
        res, desc = do_test_one(testfile, interp, info, dests[interp[1]])
        if res == "hasherror":
            hasherr.append(desc)
            #cover.log("HASH =", desc)
        # update statistic
        stats["_"]["_"] += 1
        stats["_"][res] = stats["_"].get(res, 0) + 1
        stats[interp[1]]["_"] += 1
        stats[interp[1]][res] = stats[interp[1]].get(res, 0) + 1
        resall += (res + " " * 10)[:6].upper()
        resall += "  "
    cover.log(resall)
    # test if all hash
    if len(interps) == len(hasherr):
        cover.err("All hashes wrong")
Пример #5
0
def download_pack(packname):
    packs = cover.load_res_packs()
    if packname not in packs:
        cover.err("Unknown pack \"%s\"" % packname)
        return
    name, url, filename, dest, valid = packs[packname]
    cover.log("Downloading: " + name)
    destdir = os.path.join(cover.basepath, *dest)
    if not os.path.exists(destdir):
        os.makedirs(destdir)
    zippath = os.path.join(cover.basepath, filename)
    if not os.path.exists(zippath):
        u = urlopen(url)
        meta = u.info()
        file_size = int(meta.get("Content-Length"))
        cover.log("Downloading:", file_size, "bytes")
        with open(zippath, "wb") as f:
            file_size_dl = 0
            while True:
                buff = u.read(64 * 1024)
                if not buff:
                    break
                file_size_dl += len(buff)
                f.write(buff)
                cover.log("  ", file_size_dl * 100. / file_size, "%")
    # unpack
    cover.log("Extracting")
    import zipfile, re
    with open(zippath, "rb") as fh:
        z = zipfile.ZipFile(fh)
        for name in z.namelist():
            if not re.match(valid, name):
                cover.log("  skip " + name)
                continue
            cover.log("  ok ", name)
            with open(os.path.join(destdir, *name.split("/")), "wb") as outfile:
                outfile.write(z.read(name))
    # check extracted
    for res, (hs, tags, pack) in cover.load_res_list().items():
        if pack != packname: continue
        fp = os.path.join(cover.basepath, *res.split("/"))
        if not os.path.exists(fp):
            cover.err("Resource \"%s\" not found" % res)
            return
        if cover.file_hash(fp) != hs:
            cover.err("Resource \"%s\" damaged (hash mismatch)" % res)
            return
        pass
    cover.log("Done")
Пример #6
0
def main():
    cover.log("Test PyFPDF")

    testsn = []
    interpsn = []
    autodownloadres = False
    args = sys.argv[1:]
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--hash":
            if len(args) == 0:
                cover.log("Param without value")
                return usage()
            return hasher(args[0], args[1:])
        if arg == "--help":
            print(cover.PACKHASH)
            return usage()
        elif arg == "--test":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                testsn += read_list(value[1:])
            else:
                testsn.append(value)
        elif arg == "--interp":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                interpsn += read_list(value[1:])
            else:
                interpsn.append(value)
        elif arg == "--listtests":
            return list_tests()
        elif arg == "--listinterps":
            return print_interps(find_python_version(search_python()))
        elif arg.startswith("--download"):
            return download_pack(arg[10:])
        elif arg == "--ignore-res-hash":
            cover.common.RESHASH = "{IGNORE}"
        elif arg == "--ignore-pack-hash":
            cover.common.PACKHASH = "{IGNORE}"
        elif arg == "--autodownload":
            autodownloadres = True
        else:
            cover.log("Unknown param")
            return usage()

    if len(testsn) == 0:
        tests = search_tests()
    else:
        # cheack all tests
        tests = []
        for test in testsn:
            test = test.strip()
            fn = os.path.join(cover.basepath, "cover", "test_" + test + ".py")
            if os.path.exists(fn):
                tests.append(fn)
            else:
                cover.err("Test \"%s\" not found" % test)
                return

    if len(interpsn) == 0:
        interps = find_python_version(search_python())
    else:
        # cheack all tests
        interps = []
        for interp in interpsn:
            fn = os.path.abspath(interp)
            if os.path.exists(fn):
                interps.append(fn)
            else:
                cover.err("Interpreter \"%s\" not found" % test)
                return
        interps = find_python_version(interps)

    # check if need res
    if autodownloadres:
        usedres = []
        usedpacks = []
        for test in tests:
            settings = cover.read_cover_info(test)
            for res in settings.get("res", []):
                if res in usedres:
                    continue
                usedres.append(res)
        allres = cover.load_res_list()
        for ures in usedres:
            if ures in allres:
                hs, tags, pack = allres[ures]
                if pack and pack not in usedpacks:
                    usedpacks.append(pack)
        for pack in usedpacks:
            download_pack(pack)

    do_all_test(interps, tests)
Пример #7
0
def download_pack(packname):
    if packname[:1] == "-":
        packname = packname[1:]
    packs = cover.load_res_packs()
    if packname == "_all":
        dnpacks = packs.keys()
    else:
        dnpacks = [packname]
        if packname not in packs:
            cover.err("Unknown pack \"%s\"" % packname)
            return
    for pidx, packname in enumerate(dnpacks):
        name, url, filename, dest, valid, strip = packs[packname]
        cover.log("Downloading: %d/%d %s" % (pidx + 1, len(dnpacks), name))
        destdir = os.path.join(cover.basepath, *dest)
        if not os.path.exists(destdir):
            os.makedirs(destdir)
        zippath = os.path.join(cover.basepath, filename)
        if not os.path.exists(zippath):
            u = urlopen(url)
            meta = u.info()
            try:
                file_size = int(meta.get("Content-Length"))
                cover.log("Downloading: %s bytes" % str(file_size))
            except Exception:
                file_size = None
                cover.log("Downloading:")
            with open(zippath, "wb") as f:
                file_size_dl = 0
                while True:
                    buff = u.read(64 * 1024)
                    if not buff:
                        break
                    file_size_dl += len(buff)
                    f.write(buff)
                    if file_size:
                        cover.log("  ", file_size_dl * 100. / file_size, "%")
                    else:
                        cover.log("  ", file_size_dl, "bytes")
        # unpack
        cover.log("Extracting")
        import zipfile, re
        newfiles = []
        with open(zippath, "rb") as fh:
            z = zipfile.ZipFile(fh)
            for name in z.namelist():
                if not re.match(valid, name):
                    cover.log("  skip " + name)
                    continue
                # strip slashes
                ename = name
                ns = strip
                while ns > 0:
                    ns -= 1
                    ps = ename.find("/")
                    if ps > 0:
                        ename = ename[ps + 1:]
                    else:
                        ename = ""
                        break
                if not ename:
                    cover.log("  strip " + name)
                    continue
                if name != ename:
                    cover.log("  ok " + name + " -> " + ename)
                else:
                    cover.log("  ok " + name)
                # extract
                fn = os.path.join(destdir, *ename.split("/"))
                if ename[-1:] == "/":
                    if not os.path.exists(fn):
                        os.makedirs(fn)
                else:
                    base = os.path.dirname(fn)
                    if not os.path.exists(base):
                        os.makedirs(base)
                    with open(fn, "wb") as outfile:
                        outfile.write(z.read(name))
                    newfn = "/".join(dest + ename.split("/"))
                    newfiles.append(newfn)
        # check extracted
        for res, (hs, tags, pack) in cover.load_res_list().items():
            if pack != packname: continue
            fp = os.path.join(cover.basepath, *res.split("/"))
            if not os.path.exists(fp):
                cover.err("Resource \"%s\" not found" % res)
                return
            if cover.file_hash(fp) != hs:
                if cover.common.RESHASH == "{IGNORE}":
                    cover.log("  ignore hash " + res)
                else:
                    cover.err("Resource \"%s\" damaged (hash mismatch)" % res)
                    return
            if res in newfiles:
                newfiles.remove(res)
        # check unchecked
        for fn in newfiles:
            print("  no hash for " + fn)
    cover.log("Done")
Пример #8
0
def main():
    cover.log("Test PyFPDF")

    testsn = []
    interpsn = []
    args = sys.argv[1:]
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--hash":
            if len(args) == 0:
                cover.log("Param without value")
                return usage()
            return hasher(args[0], args[1:])
        if arg == "--help":
            return usage()
        elif arg == "--test":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                testsn += read_list(value[1:])
            else:
                testsn.append(value)
        elif arg == "--interp":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                interpsn += read_list(value[1:])
            else:
                interpsn.append(value)
        elif arg == "--listtests":
            return list_tests()
        elif arg == "--listinterps":
            return print_interps(find_python_version(search_python()))
        elif arg == "--downloadfonts":
            return download_fonts()
        else:
            cover.log("Unknown param")
            return usage()

    if len(testsn) == 0:
        tests = search_tests()
    else:
        # cheack all tests
        tests = []
        for test in testsn:
            test = test.strip()
            fn = os.path.join(cover.basepath, "cover", "test_" + test + ".py")
            if os.path.exists(fn):
                tests.append(fn)
            else:
                cover.err("Test \"%s\" not found" % test)
                return

    if len(interpsn) == 0:
        interps = find_python_version(search_python())
    else:
        # cheack all tests
        interps = []
        for interp in interpsn:
            fn = os.path.abspath(interp)
            if os.path.exists(fn):
                interps.append(fn)
            else:
                cover.err("Interpretor \"%s\" not found" % test)
                return
        interps = find_python_version(interps)

    do_all_test(interps, tests)
Пример #9
0
def main():
    cover.log("Test PyFPDF")

    testsn = []
    interpsn = []
    args = sys.argv[1:]
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--hash":
            if len(args) == 0:
                cover.log("Param without value")
                return usage()
            return hasher(args[0], args[1:])
        if arg == "--help":
            return usage()
        elif arg == "--test":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                testsn += read_list(value[1:])
            else:
                testsn.append(value)
        elif arg == "--interp":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                interpsn += read_list(value[1:])
            else:
                interpsn.append(value)
        elif arg == "--listtests":
            return list_tests()
        elif arg == "--listinterps":
            return print_interps(find_python_version(search_python()))
        elif arg == "--downloadfonts":
            return download_fonts()
        else:
            cover.log("Unknown param")
            return usage()

    if len(testsn) == 0:
        tests = search_tests()
    else:
        # cheack all tests
        tests = []
        for test in testsn:
            test = test.strip()
            fn = os.path.join(cover.basepath, "cover", "test_" + test + ".py")
            if os.path.exists(fn):
                tests.append(fn)
            else:
                cover.err("Test \"%s\" not found" % test)
                return

    if len(interpsn) == 0:
        interps = find_python_version(search_python())
    else:
        # cheack all tests
        interps = []
        for interp in interpsn:
            fn = os.path.abspath(interp)
            if os.path.exists(fn):
                interps.append(fn)
            else:
                cover.err("Interpretor \"%s\" not found" % test)
                return
        interps = find_python_version(interps)

    do_all_test(interps, tests)
Пример #10
0
def main():
    cover.log("Test PyFPDF")

    testsn = []
    interpsn = []
    autodownloadres = False
    args = sys.argv[1:]
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--hash":
            if len(args) == 0:
                cover.log("Param without value")
                return usage()
            return hasher(args[0], args[1:])
        if arg == "--help":
            print(cover.PACKHASH)
            return usage()
        elif arg == "--test":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                testsn += read_list(value[1:])
            else:
                testsn.append(value)
        elif arg == "--interp":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                interpsn += read_list(value[1:])
            else:
                interpsn.append(value)
        elif arg == "--listtests":
            return list_tests()
        elif arg == "--listinterps":
            return print_interps(find_python_version(search_python()))
        elif arg.startswith("--download"):
            return download_pack(arg[10:])
        elif arg == "--ignore-res-hash":
            cover.common.RESHASH = "{IGNORE}"
        elif arg == "--ignore-pack-hash":
            cover.common.PACKHASH = "{IGNORE}"
        elif arg == "--autodownload":
            autodownloadres = True
        else:
            cover.log("Unknown param")
            return usage()

    if len(testsn) == 0:
        tests = search_tests()
    else:
        # cheack all tests
        tests = []
        for test in testsn:
            test = test.strip()
            fn = os.path.join(cover.basepath, "cover", "test_" + test + ".py")
            if os.path.exists(fn):
                tests.append(fn)
            else:
                cover.err("Test \"%s\" not found" % test)
                return

    if len(interpsn) == 0:
        interps = find_python_version(search_python())
    else:
        # cheack all tests
        interps = []
        for interp in interpsn:
            fn = os.path.abspath(interp)
            if os.path.exists(fn):
                interps.append(fn)
            else:
                cover.err("Interpreter \"%s\" not found" % test)
                return
        interps = find_python_version(interps)
    
    # check if need res
    if autodownloadres:
        usedres = []
        usedpacks = []
        for test in tests:
            settings = cover.read_cover_info(test)
            for res in settings.get("res", []):
                if res in usedres:
                    continue
                usedres.append(res)
        allres = cover.load_res_list()
        for ures in usedres:
            if ures in allres:
                hs, tags, pack = allres[ures]
                if pack and pack not in usedpacks:
                    usedpacks.append(pack)
        for pack in usedpacks:
            download_pack(pack)

    do_all_test(interps, tests)
Пример #11
0
def download_pack(packname):
    if packname[:1] == "-":
        packname = packname[1:]
    packs = cover.load_res_packs()
    if packname == "_all":
        dnpacks = packs.keys()
    else:
        dnpacks = [packname]
        if packname not in packs:
            cover.err("Unknown pack \"%s\"" % packname)
            return
    for pidx, packname in enumerate(dnpacks):
        name, url, filename, dest, valid, strip = packs[packname]
        cover.log("Downloading: %d/%d %s" % (pidx + 1, len(dnpacks), name))
        destdir = os.path.join(cover.basepath, *dest)
        if not os.path.exists(destdir):
            os.makedirs(destdir)
        zippath = os.path.join(cover.basepath, filename)
        if not os.path.exists(zippath):
            u = urlopen(url)
            meta = u.info()
            try:
                file_size = int(meta.get("Content-Length"))
                cover.log("Downloading: %s bytes" % str(file_size))
            except Exception:
                file_size = None
                cover.log("Downloading:")
            with open(zippath, "wb") as f:
                file_size_dl = 0
                while True:
                    buff = u.read(64 * 1024)
                    if not buff:
                        break
                    file_size_dl += len(buff)
                    f.write(buff)
                    if file_size:
                        cover.log("  ", file_size_dl * 100. / file_size, "%")
                    else:
                        cover.log("  ", file_size_dl, "bytes")
        # unpack
        cover.log("Extracting")
        import zipfile, re
        newfiles = []
        with open(zippath, "rb") as fh:
            z = zipfile.ZipFile(fh)
            for name in z.namelist():
                if not re.match(valid, name):
                    cover.log("  skip " + name)
                    continue
                # strip slashes
                ename = name
                ns = strip
                while ns > 0:
                    ns -= 1
                    ps = ename.find("/")
                    if ps > 0:
                        ename = ename[ps + 1:]
                    else:
                        ename = ""
                        break
                if not ename:
                    cover.log("  strip " + name)
                    continue
                if name != ename:
                    cover.log("  ok " + name + " -> " + ename)
                else:
                    cover.log("  ok " + name)
                # extract
                fn = os.path.join(destdir, *ename.split("/"))
                if ename[-1:] == "/":
                    if not os.path.exists(fn):
                        os.makedirs(fn)
                else:
                    base = os.path.dirname(fn)
                    if not os.path.exists(base):
                        os.makedirs(base)
                    with open(fn, "wb") as outfile:
                        outfile.write(z.read(name))
                    newfn = "/".join(dest + ename.split("/"))
                    newfiles.append(newfn)
        # check extracted
        for res, (hs, tags, pack) in cover.load_res_list().items():
            if pack != packname: continue
            fp = os.path.join(cover.basepath, *res.split("/"))
            if not os.path.exists(fp):
                cover.err("Resource \"%s\" not found" % res)
                return
            if cover.file_hash(fp) != hs:
                if cover.common.RESHASH == "{IGNORE}":
                    cover.log("  ignore hash " + res)
                else:
                    cover.err("Resource \"%s\" damaged (hash mismatch)" % res)
                    return
            if res in newfiles:
                newfiles.remove(res)
        # check unchecked
        for fn in newfiles:
            print("  no hash for " + fn)
    cover.log("Done")