Esempio n. 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"))
Esempio n. 2
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"))