Ejemplo n.º 1
0
def export_archive(archive_path: str,
                   scheme: str,
                   workspace="",
                   project="",
                   configuration="release"):
    """
    导出 archive
    :param scheme:
    :param archive_path:
    :param workspace:
    :param project:
    :param configuration:
    :return:
    """
    # 2. 配置参数
    archive_args = ["xcodebuild", "archive"]
    # 2.1 判断是否xcworkspace工程(cocoapods)
    if workspace.endswith(".xcworkspace"):
        archive_args += ["-workspace", workspace]
    else:
        archive_args += ["-project", project]
    archive_args += ["-scheme", scheme]
    archive_args += ["-configuration", configuration]
    archive_args += ["-archivePath", archive_path]
    archive_args.append("-quiet")

    print("开始导出archive...")
    print("执行:", " ".join(archive_args))
    if os.system(" ".join(archive_args)):
        raise BuildException('执行导出archive失败')
    # 判断是否成功
    if os.path.isfile(os.path.join(archive_path, "Info.plist")):
        print("导出archive成功: " + archive_path)
    else:
        raise BuildException("导出archive失败!")
Ejemplo n.º 2
0
    def __upload_binary(cls, cert, request):
        if not isinstance(request, FirRequest):
            raise BuildException('fir请求参数类型错误')
        # 拿到相应的token
        if not isinstance(cert, FirCertResponse):
            raise BuildException("fir 解析数据出错")
        cert_key = cert.cert_binary.key
        cert_token = cert.cert_binary.token
        cert_upload_url = cert.cert_binary.upload_url
        print('解析凭证成功')
        print('开始上传,请稍等...')
        with open(request.file, 'rb') as f:
            file = {'file': f}
            param = {
                "key":  cert_key,
                "token": cert_token,
                'x:version': request.version,
                'x:build': request.build,
                "x:name": request.name,
                "x:changelog": request.changelog
            }
            requests.packages.urllib3.disable_warnings()
            req = requests.post(cert_upload_url, files=file, data=param, verify=False)
            json_resp = dict(json.loads(req.content))

            is_completed = json_resp.get('is_completed')
            download_url = json_resp.get('download_url')
            release_id = json_resp.get('release_id')
            resp_obj = FirBinaryResponse(is_completed, download_url, release_id)
        return resp_obj
Ejemplo n.º 3
0
 def put_text(cls, object_name, text):
     if not cls.__check_config():
         raise BuildException("没有阿里oss相关配置")
     if not object_name:
         raise BuildException("上传件不存在")
     cls.__get_ali_oss().put_object(object_name, text)
     full_url = urljoin(cls.__get_ali_oss().oss_url, object_name)
     print("上传成功: " + full_url)
     return full_url
Ejemplo n.º 4
0
 def put_object(self, object_name: str, data):
     print("正在上传到阿里云:", object_name)
     # 这里使用 utf8 编码会乱码
     try:
         res = self._bucket.put_object(object_name, data.encode('gbk'))
         print(res.__dict__)
         if res.status != 200:
             raise BuildException("上传到阿里云(返回结果失败)")
     except Exception as e:
         raise BuildException("上传到阿里云失败")
Ejemplo n.º 5
0
 def put_file(self, object_name: str, file_path: str):
     print("正在上传到阿里云:", object_name, file_path)
     try:
         res = self._bucket.put_object_from_file(object_name, file_path, progress_callback=self.__print_percent)
         print(res.resp.response)
         if res.status != 200:
             raise BuildException("上传到阿里云(返回结果失败)")
     except Exception as e:
         print(e)
         raise BuildException("上传到阿里云失败")
Ejemplo n.º 6
0
 def upload(cls, file_path):
     if not len(PGY_USER_KEY) or not len(PGY_API_KEY):
         # UserWarning
         raise BuildException("请检查蒲公英配置~")
     if not Path(file_path).is_file():
         raise BuildException("要上传的文件不存在:")
     print("开始上传: " + file_path)
     result = cls.__upload(file_path)
     print("上传成功: https://www.pgyer.com/" + result['buildShortcutUrl'])
     return result
Ejemplo n.º 7
0
 def put_file(cls, object_name, file_path):
     if not cls.__check_config():
         raise BuildException("没有阿里oss相关配置")
     if not object_name:
         raise BuildException("上传文件名不存在")
     if not cls.__check_file_path(file_path):
         raise BuildException("上传件不存在")
     cls.__get_ali_oss().put_file(object_name, file_path)
     # 上传成功
     full_url = urljoin(cls.__get_ali_oss().oss_url, object_name)
     return full_url
Ejemplo n.º 8
0
 def __load_info(self):
     self.__load_plist_path(self.project_path)
     if not len(self._info_plist_path):
         raise BuildException("iOS 工程加载失败")
     self.__load_version_info()
     # 1. 读取工程信息
     self.__load_xcode_project_info()
     # 2. 读取应用 id
     self.__load_application_id()
     # 3. 加载应用名称
     self.__load_application_name()
     # 4. 判断是否加载成功
     if not len(self.application_id) or not len(self.version_code):
         raise BuildException("iOS 工程加载失败2")
Ejemplo n.º 9
0
    def upload(cls, request):
        if not isinstance(request, FirRequest):
            raise BuildException('fir请求参数类型错误')

        if not request.api_token:
            raise BuildException('api_token不能为空')
        if not os.path.isfile(request.file):
            raise BuildException('要上传fir的文件不存在')
        cert_resp = Fir.__get_cert(request.type, request.bundle_id, request.api_token)
        binary_resp = Fir.__upload_binary(cert_resp, request)
        if not binary_resp.is_completed:
            raise BuildException('fir上传失败')
        print('上传到fir成功')
        return FirResponse(cert_resp, binary_resp, request)
Ejemplo n.º 10
0
def export_ipa(archive_file_path: str, export_ipa_dir: str,
               export_ipa_path: str, export_plist_path: str):
    """
    导出 ipa
    :param archive_file_path:
    :param export_ipa_dir:
    :param export_ipa_path:
    :param export_plist_path:
    :return:
    """

    args = ["xcodebuild", "-exportArchive"]
    args += ["-archivePath", archive_file_path]
    args += ["-exportPath", export_ipa_dir]
    args += ["-exportOptionsPlist", export_plist_path]
    args += ["-allowProvisioningUpdates", "-quiet"]
    print("正在导出ipa...")
    print("执行:", " ".join(args))
    if os.system(" ".join(args)):
        return False
    # 判断是否成功
    print(export_ipa_path)
    if os.path.isfile(export_ipa_path):
        print("导出ipa成功!")
        return export_ipa_path
    else:
        raise BuildException("导出ipa失败!")
Ejemplo n.º 11
0
 def upload(cls, ipa: str, user_name: str, password: str):
     # 0. 检查帐号
     if not user_name or not password:
         raise BuildException("没有配置apple帐号")
     # 1. 验证ipa
     cls.__verify_ipa(ipa, user_name, password)
     # 2. 开始上传
     cls.__upload_ipa(ipa, user_name, password)
Ejemplo n.º 12
0
 def __upload(cls, file_path: str):
     with open(file_path, "rb") as f:
         # 文件
         files = {"file": f}
         # header 信息
         headers = {"enctype": "multipart/form-data"}
         # 字段数据
         data = {"userKey": PGY_USER_KEY, "_api_key": PGY_API_KEY}
         # 开始请求
         try:
             r = requests.post(cls.end_point,
                               headers=headers,
                               data=data,
                               files=files)
             response = r.json()
             if response["code"] != 0:
                 raise BuildException("上传到蒲公英失败")
             return response["data"]
         except Exception:
             raise BuildException("上传到蒲公英失败2")
Ejemplo n.º 13
0
 def __build(self):
     # 1. 删除旧包
     print("正在清除旧包...")
     self.__remove_all()
     # 2. 打包apk
     print("开始打包apk...")
     self.__build_apk()
     print(self.default_apk_path)
     # 3. 判断文件是否成功
     if not Path(self.default_apk_path).is_file():
         raise BuildException("文件不存在,打包失败")
     # 4. 重命名
     self.__rename_apk()
Ejemplo n.º 14
0
 def new(cls, data):
     obj = cls()
     if not data.get('cert'):
         raise BuildException('获取fir上传凭证失败')
     obj.id = data.get('id')
     obj.type = data.get('type')
     obj.short = data.get('short')
     obj.storage = data.get('storage')
     obj.form_method = data.get('form_method')
     obj.cert = data.get('cert')
     obj.cert_icon = cls.Cert.new(obj.cert.get('icon'))
     obj.cert_binary = cls.Cert.new(obj.cert.get('binary'))
     return obj
Ejemplo n.º 15
0
 def __upload_ipa(cls, ipa: str, user_name: str, password: str):
     args = [
         cls._al_tool_path, "--upload-app", "-t ios", "-f", ipa, "-u",
         user_name, "-p", password
     ]
     print("执行命令:", " ".join(args))
     print("正在上传中,时间较长,请耐心等待...")
     process = subprocess.Popen(" ".join(args),
                                shell=True,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT)
     process.wait()
     res = process.stdout.read().decode('utf-8')
     # 2.1 验证是否成功
     verify_str = "No errors uploading"
     if verify_str not in res:
         raise BuildException(cls.__get_error_message(res))
     print("上传成功:SUCCESS")
Ejemplo n.º 16
0
 def __verify_ipa(cls, ipa: str, user_name: str, password: str):
     # 1. 验证 ipa
     args = [
         cls._al_tool_path, "--validate-app", "-f", ipa, "-u", user_name,
         "-p", password
     ]
     print("执行命令:", " ".join(args))
     print("正在验证中...")
     process = subprocess.Popen(" ".join(args),
                                shell=True,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT)
     process.wait()
     res = process.stdout.read().decode('utf-8')
     # 1.1. 验证是否成功
     verify_str = "No errors validating archive at"
     if verify_str not in res:
         print("验证失败")
         raise BuildException(cls.__get_error_message(res))
     print("验证成功:SUCCESS")
Ejemplo n.º 17
0
 def __init__(self, path):
     self._format_apk_name = ""
     if not os.path.isdir(os.path.join(path, "app")):
         raise BuildException("Android:工程信息读取错误")
     self.path = path
     self.__load_data()
Ejemplo n.º 18
0
 def __build_apk(self):
     if os.system("cd {} && ./gradlew assembleRelease".format(self.path)):
         raise BuildException("gradle 打包失败~")