移動端上傳分測平臺

jc發表於2020-11-16

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=0SVN=1PGY=2TESTFLIGHT=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

相關文章