示例#1
0
    def generate_driver_google_res(self, file, name: str) -> None:

        temp_res = merge(self.temp_path, name)
        path_res_temp = merge(self.temp_path, name, GOOGLE_DRIVER)
        path_to_type = merge(self.res_path, name, GOOGLE_DRIVER)

        json_name = "google-services.json"
        json_path = merge(path_res_temp, json_name)

        if res.allowed_json(file.filename):
            res.save_json(file, path_res_temp)
            if self.validate_res_by_type(GOOGLE_DRIVER, path_res_temp):
                res.save_temp(path_res_temp, path_to_type)

                disk: GoogleDisk = GoogleDisk(with_auth=True)
                disk.replace_file(json_path, json_name, disk.get_folder_id_by_name(name))

                res.delete(temp_res)
            else:
                res.delete(temp_res)
                raise ResourceError(subcode=ResourceError.google_res,
                                    data=ResourceError.google_res_mes % "not file")
        else:
            raise ResourceError(subcode=ResourceError.file_type,
                                data=ResourceError.file_type_mes % (file.filename, "json"))
示例#2
0
 def update_res(self, old: str, new: str) -> None:
     if old != new:
         if res.name_exist(self.res_path, old):
             if not res.name_exist(self.res_path, new):
                 res.update(self.res_path, old, new)
             else:
                 raise ResourceError(subcode=ResourceError.res_exist,
                                     data=ResourceError.res_exist_mes % new)
         else:
             raise ResourceError(subcode=ResourceError.res_not_found,
                                 data=ResourceError.res_not_found_mes % old)
示例#3
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
示例#4
0
    def generate_zip_res(self, file, name: str, res_type: str) -> None:
        path_temp_res = merge(self.temp_path, name)
        path_temp_type = merge(self.temp_path, name, res_type)
        path_res_type = merge(self.res_path, name, res_type)
        zip_name = name + "-" + res_type + ".zip"

        if res.allowed_zip(file.filename):
            res.unzip_temp(file, zip_name, path_temp_res, res_type)
            try:
                # Validation and store files
                self.validate_res_by_type(res_type, path_temp_type)
                if res_type == IOS:
                    from std.migration import ios_image_migrate
                    try:
                        ios_image_migrate.create_logo_content(
                            path_temp_type, path_res_type)
                    except Exception:
                        raise ResourceError(
                            subcode=ResourceError.res_not_found,
                            data=ResourceError.ios_image_res)

                elif res_type == ANDROID or res_type == ANDROID_DRIVER or res_type == ANDROID_DRIVER_NEW:
                    res.save_temp(path_temp_type, path_res_type)
                else:
                    raise ResourceError(subcode=ResourceError.res_not_found,
                                        data=ResourceError.res_not_found_mes %
                                        res_type)

                # Create ZIP for Google
                path = merge(path_temp_res, parse_sku(name) + "-" + res_type)
                res.create_zip_res(path_res_type, path)

                # Load to Google
                gzip_name = parse_sku(name) + "-" + res_type + ".zip"
                gzip_path = merge(path_temp_res, gzip_name)
                disk: Disk = GoogleDisk(with_auth=True)
                disk.replace_file(gzip_path, gzip_name,
                                  disk.get_folder_id_by_name(name))

                # Delete temp
                res.delete(path_temp_res)
            except ResourceError as error:
                # res.delete(path_temp_res)
                raise error
        else:
            raise ResourceError(subcode=ResourceError.file_type,
                                data=ResourceError.file_type_mes %
                                (file.filename, "zip"))
示例#5
0
def unzip_temp(file, zip_name: str, temp_res_path: str, res_type: str) -> None:
    filename = file.filename

    if not filename:
        raise DataEror(subcode=DataError.not_found,
                       data=DataError.not_found_mes % filename)

    if not allowed_zip(filename):
        raise ResourceError(subcode=ResourceError.file_type,
                            data=ResourceError.file_type_mes %
                            (filename, "zip"))

    res_path = merge(temp_res_path, res_type)
    zip_path = merge(temp_res_path, zip_name)

    if os.path.exists(res_path):
        shutil.rmtree(res_path)
    os.makedirs(res_path)
    print(zip_path)
    file.save(zip_path)

    zip_ref = zipfile.ZipFile(zip_path, 'r')
    zip_ref.extractall(res_path)
    zip_ref.close()
    os.remove(zip_path)
示例#6
0
def save_json(file, path: str) -> None:
    filename = "google-services.json"

    if not allowed_json(filename):
        raise ResourceError(subcode=ResourceError.file_type,
                            data=ResourceError.file_type_mes %
                            (file.filename, "json"))
    save_path = os.path.join(path, filename)
    os.makedirs(path)
    file.save(save_path)
示例#7
0
 def validate_res_by_type(res_type: str, path_res_type: str) -> bool:
     if res_type == ANDROID:
         is_valid = res.validate_android_images(path_res_type)
     elif res_type == IOS:
         is_valid = res.validate_ios_images(path_res_type)
     elif res_type == GOOGLE:
         is_valid = res.validate_google_push(path_res_type)
     elif res_type == GOOGLE_DRIVER:
         is_valid = res.validate_google_push(path_res_type)
     elif res_type == ANDROID_DRIVER:
         is_valid = res.validate_driver_images(path_res_type)
     else:
         raise ResourceError(subcode=ResourceError.res_not_found,
                             data=ResourceError.res_not_found_mes % res_type)
     return is_valid
示例#8
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
示例#9
0
 def generate_new_res(self, name: str) -> None:
     if not res.name_exist(self.res_path, name):
         res.create(self.res_path, name)
     else:
         raise ResourceError(subcode=ResourceError.res_exist,
                             data=ResourceError.res_not_found_mes % name)
示例#10
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