Android Auto Pack, reinforce/upload dandelion/Modify database etc Python version

Source: Internet
Author: User
#-*-Coding:utf-8-*-#!/usr/bin/env Python3 # name:alenx # pip3 Install, Paramiko # from datetime import da Tetime import Fnmatch, OS, Paramiko, Pymysql, requests #------------------------------------------------------------- -----------------------------------------------# Account Information # Branch branch = ' cz1.0.5 ' # own static server account hosts = "10.10.0.11" user Name = "Admin" passwd = "demo2088@@" # 360 consolidated account user = ' demo ' pawd = ' demo2088@@ "# build Mode Confdebug = ' Assembledebug "Confrelease =" Apkrelease "#------------------------------------------------------------------------------------ ------------------------# project root directory Project_path = "/opt/admin/android-fund/mainmodule" # export APK path Apk_path = "/opt/admin/ Android-fund/mainmodule/build/apks "#-------------------------------------------------------------------------- ----------------------------------# Static server holds file path AppPath = "/var/www/app/android_app" #----------------------------- -------------------------------------------------------------------------------# Modify Information Projectnamepath = "/opt/admin/android-fund/mainmodule/app/src/main/res/values /strings.xml "Schemepath ="/opt/admin/android-fund/mainmodule/config.gradle "Exportoptionspath ="/opt/admin/ Android-fund/mainmodule/commonlibrary/src/main/java/com/financeyun/demo "\"/commonlibrary/config/data Config.java "#-------------------------------------------------------------------------------------------------- ----------# APP URL testurl = "https://static.test.com/android_app/demotest-release.apk" Prourl = "https:// static.test.com/android_app/demo-release.apk "# dandelion Key Pgy_key =" 9c86dd6fb80a0dc8286d7xxxxx841d91 "# dandelion Apikey PGY_
Apikey = "220fd5e840f4756axxxxxxbdb80e2e80" # dandelion URL pgy_url = "Https://www.pgyer.com/apiv2/app/upload" # Version update description

Updatedescriptiontest = "Test version" Updatedescriptionpro = "Production Version" # 0: Not updated, 1: Update, 2: force update UPDATE_AGRS = 2 # Update Description Update_note = "" "V0.8.14 Update description \r\n1, modify bug\r\n2, modify fund display style" "" #------------------------------------------------------------------------------------------------------------BaseDir = '/opt/ Admin/tpc/key ' Keystorepath = Os.path.join (BaseDir, "Demo.jks") Keystore_alias = "Financeyun" Keystore_pass = " demo123456 "Key_pass =" demo123456 "App_path = Os.path.join (Apk_path, ' *-demo.apk ') #--------------------------------- ---------------------------------------------------------------------------# SQL Inster = "INSERT into Basic_app_ Version_info (' App_Code ', ' Update_type ', ' Version ', ' App_url ', ' update_note ', ' create_time ', ' modify_time ') ' VA Lues ('%s ', '%s ', '%s ', '%s ', '%s ', '%s ', '%s ') # 360 reinforced def exec_360_jiagu (): Os.chdir ('/opt/admin/tpc/jiagu ') #  Os.system (' Java-jar jiagu.jar-login%s '% (user, pawd)) # Os.system (' Java-jar jiagu.jar-importsign%s%s%s ' % (Keystorepath, Keystore_pass, Keystore_alias, Key_pass)) Os.system (' Java-jar Jiagu.jar-config-crashlog-x86-sho Wsign ') os.system (' Java-jar jiagu.jar-jiagu%s%S-autosign '% (App_path, Apk_path)) # Search File def fnmat (sets): for file_name in Os.listdir ('%s '% Apk_path): I
            F sets = = "Test": Fnmatch.fnmatch (file_name, ' *-test.apk ') return file_name else: Fnmatch.fnmatch (file_name, ' *_jiagu_sign.apk ') return file_name # link Database insert Data def connet (Var, url): __  Instime = DateTime.Now (). Strftime ('%y-%m-%d%h:%m:%s ') Insterdata = (' ', '%s '% Update_agrs, '%s '% Var, '%s '% URL,
            '%s '% update_note, __instime, __instime) Try:conn = Pymysql.connect (host= ' 10.30.0.42 ',
            port=3306, user= ' test ', passwd= ' test@2088 ', db= ' basic ', charset= ' UTF8 ',  cursorclass=pymysql.cursors.dictcursor) cur = conn.cursor () cur.execute (inster% insterdata) except Pymysql. Mysqlerror as E:print ("Database link exception please check.") ", E) Finally:conn.commit () Cur.close () # Git Project Def git_project (): Try:print ("\033[1;35m==========>> Start git!
        <<==========\033[0m ") Os.chdir (project_path) # bran = os.popen (' git branch--merged '). Read ()  Os.system (' Git checkout. || Exit\n ') Os.system (' git fetch ') os.system (' Git checkout-b%s origin/%s '% (branch, branch)) os.sy Stem (' Git pull | | exit\n ') os.system (' Git branch--merged | | exit ') print ("\n\033[1;32m==========>> git Log <<==========\033[0m ") os.system (' Git log-3--pretty=format:%h-%CD,%an:%s" | | exit ') p Rint ("\n\033[1;32m==========>> Git success! <<==========\033[0m ") except:exit (0) # build Project def build_project (SETG): Try:print ("\033[1;35m==========>> Start build! <<==========\033[0m ") Os.chdir (project_path) if Setg = = ' Test ': #./gradlew Clean Apkrel Ease-pchannels=test Os.system ('./gradlew clean%s-pchannels=tesT | | 
        Exit '% confrelease) else:os.system ('./gradlew Clean%s-pchannels=financeyun | | exit '% confrelease) Print ("\033[1;32m==========>> build success! <<==========\033[0m ") except:exit (0) # backup file def ssh2 (seting, version): __date = DateTime.Now (). St Rftime ('%y%m%d%h%m%s ') try:ssh = Paramiko. Sshclient () Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) Ssh.connect (hosts, username, passwd, timeout=30) if seting = = ' Test ': SSH  . Exec_command (' CD%s && mv demotest-release.apk demotest-release.apk-%s-%s | | exit '% (AppPath, version, __date), Get_pty=false) Else:ssh.exec_command (' CD%s && mv Demo-release.a PK demo-release.apk-%s-%s | | Exit '% (AppPath, version, __date), get_pty=false) except Paramiko. Sshexception as E:print (' connet error: ', e) # Upload files to static server Def put_file(PS): Try:transport = Paramiko. Transport (hosts) Transport.connect (Username=username, password=passwd) sftp = Paramiko.  Sftpclient.from_transport (transport) if PS = = "Test": Remote_testfile = Fnmat (PS) testfile = "demotest-release.apk" sftp.put (Apk_path + '/' + remote_testfile, AppPath + '/' + testfile ') pri  NT ("\033[1;32m====>> Current environment is:%s <<====\033[0m"% updatedescriptiontest) Else:remote_file =
            Fnmat (PS) file = "demo-release.apk" sftp.put (Apk_path + '/' + remote_file, AppPath + '/' + file) 
    Print ("\033[1;32m====>> Current environment is:%s <<====\033[0m"% Updatedescriptionpro) Transport.close () Except Paramiko. Sftperror as E:print (' Upload error: ', e) # Upload IPA package to dandelion def uploadipato (remote_testfile, setting): File = (AP K_path + '/' + remote_testfile) try:print ("\033[1;35m==========>> upload app to Dandelion <<==========\033[0m ") file = {' file ': Open (file, ' RB ')} param = {' _api_key ': Pgy_apikey, ' buildupdate
        Description ': setting} req = Requests.post (Url=pgy_url, Files=file, data=param) code = Req.status_code 
            if code = = 200:print ("\033[1;32m============>> Upload dandelion Success <<============\033[0m") Else:
       Print ("\033[1;35m==========>> upload dandelion failed please manually upload <<==========\033[0m") except Exception as E: Exit (e) # change information def sed (SED): print ("\033[1;35m==========>> sed file! <<==========\033[0m ") # environment Change File __ENVM ="/opt/admin/android-fund/mainmodule/commonlibrary/src/main/assets/co Nfig.json "_dev = ' sed-i" s/%s/%s/g "%s"% (' dev ', ' Test ', __ENVM) _devs = ' ' sed-i ' s/%s/%s/g '%s '% (' Dev ', ' pro ', __ENVM ') _test = ' sed-i ' s/%s/%s/g '%s '% (' pro ', ' Test ', __ENVM) _pro = ' ' Sed-i ' s/%s/%s/
     G '%s '% (' test ', ' Pro ', __ENVM ') if sed = = "Test":   Os.system (_dev) Os.system (_test) Else:os.system (_devs) Os.system (_pro) # main function def main (s Eting, *args): Os.chdir (Project_path) Try: # time Begindate = DateTime.Now (). Strftime ('%y-%m-%d%h:% m:%s ') # Cleanup Project Git_project () Sed (seting) # Compile Project Build_project (seting) # uploaded to Dandelion if seting = = "Test": Remote_testfile = Fnmat (seting) Uploadipato (Remote_testfile, UPDA tedescriptiontest) Print ("\033[1;32m====>> is modifying the database ... <<====\033[0m") file_name = f Nmat (seting) file_version = file_name[:-9] Connet (file_version, Testurl) print ("\033[1 ;32m====>> is backing up files ... <<====\033[0m ") ssh2 (seting, file_version) print (" \033[1;32m==
            ==>> Current environment is:%s <<====\033[0m "% updatedescriptiontest" Else:exec_360_jiagu () Remote_testfile = Fnmat (seting) Uploadipato (Remote_testfile, Updatedescriptionpro) print ("\033[1;32m====>> is modifying the database ...
            ... <<====\033[0m ") file_name = Fnmat (seting) # file_version = file_name[:-15] File_version = File_name[:5] Connet (file_version, Prourl) print ("\033[1;32m====>> is backing up files ....") .. <<====\033[0m ") Ssh2 (seting, file_version) print (" \033[1;32m====>> The current environment is:%s <<= ===\033[0m "% updatedescriptionpro" print ("\033[1;32m====>> Uploading Files ... <<====\033[0m") # PR Int ("\033[1;32m====>> APP URL:%s <<====\033[0m"% URL) # upload to static server Put_file (seting) E Nddate = DateTime.Now (). Strftime ('%y-%m-%d%h:%m:%s ') BeginTime = Datetime.strptime (begindate, '%Y-%m-%d%H:%M:%S ') ) Endtime = Datetime.strptime (EndDate, '%y-%m-%d%h:%m:%s ') Exporttime = (endtime-begintime) pri NT ("\033[1;32m====>> the current version is:%s <<====\033[0m "% file_version" print ("\033[1;32m====>> Current branch is:%s \033[0m"% branch) Print ("\033[1;32m====>> is always used as:%s <<====\033[0m"% exporttime) except Eoferror as E:exit (' Bu ILD Error, please check! ', E. If __name__ = = "__main__": sets = input ("Please input build Setting (Test,pro):") I F sets = = "Test" or sets = = "Pro": Main (sets) Else:exit ("\033[1;31m-*-*-*-*-*-input error Please re-enter ...-*-*-*-*- *-\033[0m ")

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.