通用技术 移动端上传分测平台

jc · 2020年11月16日 · 1260 次阅读

app 上传分测平台:
0.fir
1.svn
2.pgy
3.testflight

class Upload():

    def __init__(self, job_id,file, upload_type):
        '''
        :param file:上传文件
        :param upload_type:上传类型,FIR=0,SVN=1,PGY=2,TESTFLIGHT=3,字符串类型
        '''

        self.app_path = file
        self.upload_type = upload_type

        self.log_path = path.join(os.path.expandvars('$HOME'), 'app_manage/log',
                                  Utils.get_current_time1()+ '.log')

    def svn_upload(self, svn_path, commit_msg):
        """
        :param file_path:上传文件路径
        :param svn_path:svn存放路径
        :param commit_msg:svn提交信息
        :return:提交结果,是否成功
        """
        if os.path.exists(self.app_path):
            svn_shell = 'svn import -m\"' + commit_msg + '\" ' + self.app_path + ' ' + svn_path

            if 'Committed revision ' in utils.Utils.cmd_result_msg(svn_shell, log_path=self.log_path):
                return True
            else:
                return False
        return

    def fir_upload(self, platform_name, fir_token, change_log_file):
        # gem install fir-cli
        if fir_token and os.path.exists(self.app_path):
            fir_login_shell = 'fir login ' + fir_token
            if 'Login succeed' in utils.Utils.cmd_result_msg(fir_login_shell, log_path=self.log_path):
                fir_upload_shell = 'fir publish ' + self.app_path
                if change_log_file and os.path.exists(change_log_file):
                    fir_upload_shell = fir_upload_shell + ' --changelog=' + change_log_file
                if 'Published succeed' in utils.Utils.cmd_result_msg(fir_upload_shell, log_path=self.log_path):
                    return True
        return

    def pgy_upload(self, platform_name, api_key, ukey):
        begin = Utils.get_current_time()
        if os.path.exists(self.app_path) and ukey and api_key:
            pgy_upload_shell = 'curl -F file=@' + self.app_path + ' -F uKey=' + ukey + ' -F _api_key=' + api_key + ' http://www.pgyer.com/apiv1/app/upload'
            pgy_upload_result = utils.Utils.cmd_result_msg(pgy_upload_shell, log_path=self.log_path)
            result = json.loads(pgy_upload_result, strict=False)
            if result['code'] == 0:
                upload_path = result['data']['appQRCodeURL']
                return True
            else:
                return False
        return

    def testflight_upload(self, username, password_token):
        if os.path.exists(self.app_path):
            ipa_validate_shell = "xcrun altool --validate-app -f " + self.app_path + " -t iOS -u " + username + " -p " + password_token + " --output-format xml"
            ipa_upload_shell = "xcrun altool --upload-app -f " + self.app_path + " -t iOS -u " + username + " -p " + password_token + " --output-format xml"
            if "No errors validating archive at" in utils.Utils.cmd_result_msg(ipa_validate_shell,log_path=self.log_path):
                if "No errors uploading" in utils.Utils.cmd_result_msg(ipa_upload_shell, log_path=self.log_path):
                    return True
        return

    def run(self, platform_name, fir_token, svn_path, commit_msg, ukey, api_key, username, password_token,
            change_log_file=None):
        """

        :param fir_token:fir分测平台账户token
        :param change_log_file:fir分测提交日志
        :param svn_path:svn目录
        :param commit_msg:svn提交日志
        :param ukey:蒲公英分测账号ukey
        :param api_key:蒲公英分测账号api key
        :param username:appstore使用的apple id账号
        :param password_token:appstore使用的apple id动态码
        :return:
        """

        try:

            if self.upload_type == '0' and fir_token:
                return self.fir_upload(platform_name, fir_token, change_log_file)
            elif self.upload_type == '1' and svn_path and commit_msg:
                return self.svn_upload(svn_path, commit_msg)
            elif self.upload_type == '2' and ukey and api_key:
                return self.pgy_upload(platform_name, ukey, api_key)
            elif self.upload_type == '3' and username and password_token:
                return self.testflight_upload(username, password_token)

        except Exception:
            return False
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册