Exemple #1
0
def save_temp(src: str, dst: str) -> None:
    if os.path.exists(dst):
        shutil.rmtree(dst)
    if not os.path.exists(src):
        raise PathError(subcode=PathError.path_not_found,
                        data=PathError.path_not_found_mes % src)
    shutil.copytree(src, dst)
Exemple #2
0
def create(res_path: str, name: str) -> None:
    src = merge(res_path, name)

    if os.path.exists(src):
        raise PathError(subcode=PathError.path_exist,
                        data=PathError.path_exist_mes % src)

    os.makedirs(src)
Exemple #3
0
def update(res_path: str, old: str, new: str) -> None:
    src = merge(res_path, old)
    dst = merge(res_path, new)

    if not os.path.exists(src):
        raise PathError(subcode=PathError.path_not_found,
                        data=PathError.path_not_found_mes % src)
    os.rename(src, dst)
Exemple #4
0
def validate_driver_images(android_path: str) -> bool:
    if not os.path.exists(android_path):
        raise PathError(subcode=PathError.path_not_found,
                        data=PathError.path_not_found_mes % android_path)

    valid_dirs = ['ic_launcher', 'gootax', 'push', 'splash']
    dpi = ["-mdpi", "-hdpi", "-xhdpi", "-xxhdpi"]
    png = ".png"

    dir_list = list(map(lambda x: str(x).lower(), os.listdir(android_path)))

    logging.info("Resource with path {%s} have {%s} folders" %
                 (android_path, dir_list))

    for direct in valid_dirs:
        if direct not in dir_list:
            raise ResourceError(subcode=ResourceError.android_folder,
                                data=ResourceError.android_folder_mes % direct)

    for img_folder in dir_list:
        folder_path = merge(android_path, img_folder)

        if img_folder == "__MACOSX":
            continue
        if img_folder not in valid_dirs:
            try:
                shutil.rmtree(folder_path)
            except NotADirectoryError:
                os.remove(folder_path)
            continue

        images = list(map(lambda x: str(x).lower(), os.listdir(folder_path)))

        logging.info("Resource {%s} have {%s} images" % (img_folder, images))

        for image in images:
            if not image.startswith(img_folder):
                os.remove(merge(folder_path, image))

        for image_dpi in dpi:
            file = img_folder + image_dpi + png

            logging.info("Checking {%s} file" % file)

            if file not in images:
                raise ResourceError(subcode=ResourceError.android_image,
                                    data=ResourceError.android_image_mes %
                                    file)

    return True
Exemple #5
0
def validate_google_push(google_path: str) -> bool:
    if not os.path.exists(google_path):
        raise PathError(subcode=PathError.path_not_found,
                        data=PathError.path_not_found_mes % google_path)

    google_service = "google-services.json"
    paths = os.listdir(google_path)
    logging.info("Google path {%s} have {%s} file" % (google_path, paths))

    for path in paths:
        if path != google_service:
            raise ResourceError(subcode=ResourceError.google_res,
                                data=ResourceError.google_res_mes % path)

    return True
Exemple #6
0
def delete(path_to_res: str) -> None:
    if not os.path.exists(path_to_res):
        raise PathError(subcode=PathError.path_not_found,
                        data=PathError.path_not_found_mes % path_to_res)

    shutil.rmtree(path_to_res)
Exemple #7
0
def validate_ios_saved_images(ios_path: str) -> bool:
    if not os.path.exists(ios_path):
        raise PathError(subcode=PathError.path_not_found,
                        data=PathError.path_not_found_mes % ios_path)
    logo = "appicon"
    menulogo = "menulogo"
    logo_splash = "logo_splash"
    itunnes = "itunesartwork@2x"

    IDIOMS = ["iphone", "ipad"]

    idiom_iphone = "iphone"
    IPHONE_SCALES = ["@2", "@3"]
    IPHONE_SIZES = ["20x20", "29x29", "40x40", "60x60"]

    idiom_ipad = "ipad"
    IPAD_SIZES = ["20x20", "29x29", "40x40", "76x76", "83.5x83.5"]
    IPAD_SCALES = ["@1", "@2"]
    scales_imagesets = ["@2", "@3"]

    splash_sizes = [
        "640x960", "640x1024", "640x1136", "750x1334", "1024x768", "1125x2436",
        "1242x2208", "1431x2000", "2048x1536", "2048x2732"
    ]

    png = ".png"
    dir_list = os.listdir(ios_path)

    logging.info("Resource with path {%s} have {%s} folders" %
                 (ios_path, dir_list))

    for img_folder in dir_list:
        folder_path = merge(ios_path, img_folder)
        if img_folder == "__MACOSX":
            continue
        try:
            images = os.listdir(folder_path)
        except Exception:
            return False
        logging.info("Resource {%s} have {%s} images" % (img_folder, images))

        if img_folder == logo:
            for idiom in IDIOMS:
                if idiom == idiom_iphone:
                    for size in IPHONE_SIZES:
                        for scale in IPHONE_SCALES:
                            image = logo + "-" + idiom_iphone + size + scale + png
                            if image not in images:
                                print(f"Not image {image}")
                                return False
                if idiom == idiom_ipad:
                    for size in IPAD_SIZES:
                        for scale in IPAD_SCALES:
                            image = logo + "-" + idiom_ipad + size + scale + png
                            if image not in images:
                                print(f"Not image {image}")
                                return False

        elif img_folder == menulogo:
            for scale in scales_imagesets:
                file = img_folder + scale + png
                logging.info("Checking {%s} file" % file)
                if file not in images:
                    return False
        elif img_folder == logo_splash:
            for splash_size in splash_sizes:
                file = splash_size + png
                logging.info("Checking {%s} file" % file)
                if file not in images:
                    return False
    return True
Exemple #8
0
def validate_ios_images(ios_path: str) -> bool:
    if not os.path.exists(ios_path):
        raise PathError(subcode=PathError.path_not_found,
                        data=PathError.path_not_found_mes % ios_path)

    valid_folders = ["appicon", "menulogo", "splash"]
    app_icon = 'appicon'
    menulogo = 'menulogo'
    splash = 'splash'

    scales_double = ["", "@2x"]
    scales_triple = ["", "@2x", "@3x"]
    scales_imagesets = ["@2x", "@3x"]

    images_triple = ["icon-60", "icon-small-40", "icon-small"]
    images_double = ["icon-76"]
    images_once = ["icon-167", "icon-20", "itunesartwork@2x"]

    splash_sizes = [
        "640x960", "640x1024", "640x1136", "750x1334", "768x1024", "1125x2436",
        "1242x2208", "1431x2000", "1536x2048", "2048x2732"
    ]

    png = ".png"
    dir_list = list(map(lambda x: str(x).lower(), os.listdir(ios_path)))

    logging.info("Resource with path {%s} have {%s} folders" %
                 (ios_path, dir_list))

    for img_folder in dir_list:
        folder_path = merge(ios_path, img_folder)
        if img_folder == "__MACOSX":
            continue

        if img_folder not in valid_folders:
            try:
                shutil.rmtree(folder_path)
            except NotADirectoryError:
                os.remove(folder_path)
            continue

        images = list(map(lambda x: str(x).lower(), os.listdir(folder_path)))
        logging.info("Resource {%s} have {%s} images" % (img_folder, images))

        if img_folder == app_icon:
            for image in images_triple:
                for scale in scales_triple:
                    file = image + scale + png
                    if file not in images:
                        raise ResourceError(
                            subcode=ResourceError.ios_image,
                            data=ResourceError.ios_image_mes % img_folder +
                            file)
            for image in images_double:
                for scale in scales_double:
                    file = image + scale + png
                    if file not in images:
                        raise ResourceError(
                            subcode=ResourceError.ios_image,
                            data=ResourceError.ios_image_mes % img_folder +
                            file)
            for image in images_once:
                file = image + png
                if file not in images:
                    raise ResourceError(
                        subcode=ResourceError.ios_image,
                        data=ResourceError.ios_image_mes % img_folder + file)

        elif img_folder == menulogo:
            for scale in scales_imagesets:
                file = img_folder + scale + png
                logging.info("Checking {%s} file" % file)
                if file not in images:
                    raise ResourceError(
                        subcode=ResourceError.ios_image,
                        data=ResourceError.ios_image_mes % img_folder + file)
        elif img_folder == splash:
            for splash_size in splash_sizes:
                file = splash_size + png
                logging.info("Checking {%s} file" % file)
                if file not in images:
                    raise ResourceError(
                        subcode=ResourceError.ios_image,
                        data=ResourceError.ios_image_mes % img_folder + file)

    return True