Ejemplo n.º 1
0
def get_zips(directory: str) -> list:
    """
    Return a the ZIP from a specified directory after running
    some sanity checks
    """
    zips = {}
    for file in [
            os.path.join(dp, file) for dp, dn, fn in os.walk(directory)
            for file in fn
    ]:
        if file.split(".")[-1] != "zip":
            continue
        zip_name = file.split("/")[-1]

        try:
            version, buildtype, device, builddate = get_metadata_from_zip(
                zip_name)
        except IndexError:
            continue

        if buildtype.lower() not in ALLOWED_BUILDTYPES:
            continue
        if version not in ALLOWED_VERSIONS:
            continue

        if device in zips:
            if get_date_from_zip(zips[device]) > builddate:
                continue
        zips[device] = zip_name
    data = list(zips.values())
    data.sort()
    return data
Ejemplo n.º 2
0
ALLOWED_BUILDTYPES = ["Alpha", "Beta", "Official"]
ALLOWED_VERSIONS = ["9.0", "10"]
FILE_BASE: str = os.getenv("FILE_BASE", "/mnt/builds")
DEBUG = False
builds: dict = {}
zips: dict = {}

for file in [
        os.path.join(dp, file) for dp, dn, fn in os.walk(FILE_BASE)
        for file in fn
]:
    try:
        if file.split(".")[-1] != "zip":
            continue
        zip_name = file.replace(FILE_BASE, "")
        version, buildtype, device, builddate = get_metadata_from_zip(zip_name)
        if buildtype not in ALLOWED_BUILDTYPES:
            if DEBUG:
                print(
                    f"{zip_name} has a buildtype of {buildtype}, which is not allowed!",
                    file=sys.stderr,
                )
            continue
        if version not in ALLOWED_VERSIONS:
            if DEBUG:
                print(
                    f"{zip_name} has a version of {version}, which is not allowed!",
                    file=sys.stderr,
                )
            continue
        if device in zips: