Exemplo n.º 1
0
def load_files_to_drive(path):
    platforms = ["android", "ios"]
    disk = GoogleDisk(with_auth=True)
    list_dirs = os.listdir(path)

    json_name = "google-services.json"

    for proj_dir in list_dirs:
        print(proj_dir)
        project_path = merge(RES_PATH, proj_dir)

        try:
            json_path = merge(project_path, "google", json_name)
            disk.replace_file(json_path, json_name, disk.get_folder_id_by_name(proj_dir))
        except Exception as e:
            print(e)

        for platform in platforms:
            try:
                platform_path = merge(project_path, platform)
                res.create_zip_res(platform_path, merge(project_path, parse_sku(proj_dir) + "-" + platform))
                print(platform_path)

                gzip_name = parse_sku(proj_dir) + "-" + platform + ".zip"
                gzip_path = merge(project_path, gzip_name)
                print(gzip_path)
                disk.replace_file(gzip_path, gzip_name, disk.get_folder_id_by_name(proj_dir))

                os.remove(gzip_path)
                print("success")
            except Exception as e:
                print("error")
Exemplo 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"))
Exemplo n.º 3
0
 def _prepare_dirs(self, dir_helper):
     try:
         dir_helper.copy_sample_project()
     except FileExistsError:
         dir_helper.remove_final_project()
         dir_helper.copy_sample_project()
     dir_helper.replace_android_driver_bundle(self.new_bundle)
     dir_helper.replace_strings(bundle=self.bundle,
                                new_bundle=self.new_bundle)
     dir_helper.replace_app_driver_dirs(
         app_name_id=parse_sku(self.new_bundle),
         bundle=self.new_bundle)  # TODO get app_sku from bundle
Exemplo n.º 4
0
def remote_validate_type(name: str,
                         res_type: str,
                         save_path: str,
                         with_save: bool = False) -> bool:
    ANDROID = "android"
    IOS = "ios"
    GOOGLE = "google"
    from std.disk.google_disk import GoogleDisk

    drive = GoogleDisk(with_auth=True)

    if res_type == ANDROID or res_type == IOS:
        res_name = parse_sku(name) + "-" + res_type + ".zip"
    elif res_type == GOOGLE:
        res_name = "google-services.json"
    else:
        raise DataEror(subcode=DataError.not_found,
                       data=DataError.not_found_mes % name)

    print("remote_validate_type before %s" % res_name)
    is_exist = drive.check(res_name, drive.get_folder_id_by_name(name))
    print("remote_validate_type after %s" % is_exist)

    if not is_exist or not with_save:
        return is_exist
    elif is_exist and with_save:
        print("remote_validate_type is_exist")
        save_path = merge(save_path, res_type)
        if not os.path.exists(save_path):
            os.makedirs(save_path)
        save_file_path = merge(save_path, res_name)
        drive.load_file(res_name, save_file_path,
                        drive.get_folder_id_by_name(name))
        if allowed_zip(res_name):
            print("remote_validate_type allowed_zip")
            print("remote_validate_type %s" % save_path)
            zip_ref = zipfile.ZipFile(save_file_path, 'r')
            zip_ref.extractall(save_path)
            zip_ref.close()
            os.remove(save_file_path)
        return True