精华内容
下载资源
问答
  • python自动化打包java maven工程,并上传至服务器,简化服务器war上传步骤和节约时间
  • Python自动化打包业务和认证平台

    千次阅读 2014-11-29 18:01:25
    Python 自动化打包业务和认证平台,本机只需执行脚本,远程即可自动部署。

    Python自动化打包业务和认证平台

    1.文档摘要

    Python 自动化打包业务和认证平台,本机只需执行脚本,远程即可自动部署。

    2.更新日志

    2014-11-28

    文档版本为「1.0」,文档名为「Python自动化打包业务和认证平台 V1.0」,备注为「文档正式版,已测试通过」,By Robin。

    3.版本信息

    本机 XXX:

    系统版本:Mac OS X 10.9.4
    主机名:XXX
    IP:xxx.xxx.xxx.xxx
    Python:2.7.5

    远程机 XXX:

    系统版本:Debian 7.6
    主机名:XXX
    IP:xxx.xxx.xxx.xxx
    Python:2.7.3
    JDK:1.8.25
    Maven:3.2.3
    SVN:1.6.17

    4.先决条件

    本机安装软件:

    Python 2.7.5
    sshpass 1.0.5

    安装包如下:

    apt-get: python python-pip python-dev subversion subversion-tools
    pip: fabric

    远程服务器安装软件:

    JDK:1.8.25
    Maven:3.2.3
    SVN:1.6.17

    安装包如下:

    dos2unix subversion subversion-tools

    5.脚本详解

    5.1 软件概要

    本软件包括两个Python脚本以及一个配置文件。目录结构如下:

    tree auto_deploy_app
    

    auto_deploy_app
    |– auto_deploy_app_remote.py
    |– auto_deploy_app_v_final.py
    `– config.conf

    0 directories, 3 files

    其中,「auto_deploy_app_remote.py」是主执行脚本,用于显示帮助以及调用相应函数。「auto_deploy_app_v_final.py」是核心执行脚本,实现所有的相关功能。「config.conf」是脚本的配置文件。

    该脚本实现的功能如下:

    • 打印帮助
    • 部署准备
    • 检出项目
    • 更新项目
    • 部署业务平台
    • 部署认证平台
    • 启动、关闭、重启业务平台
    • 启动、关闭、重启认证平台

    5.2 脚本帮助

    我们通过如下命令可以获得该脚本的帮助。

    ./auto_deploy_app_remote.py -h
    
    Auto deploy application to the remote web server. Write in Python.
     Version 1.0. By Robin Wen. Email:dbarobinwen@gmail.com
    
     Usage auto_deploy_app.py [-hcustrakgdwp]
       [-h | --help] Prints this help and usage message
       [-p | --deploy-prepare] Deploy prepared. Run as root
       [-c | --svn-co] Checkout the newarkstg repo via svn
       [-u | --svn-update] Update the newarkstg repo via svn
       [-s | --shutdown-core] Shutdown the core platform via the stop.sh scripts
       [-t | --startup-core] Startup the core platform via the startup.sh scripts
       [-r | --restart-core] Restart the core platform via the restart.sh scripts
       [-a | --shutdown-auth] Shutdown the auth platform via the stop.sh scripts
       [-k | --startup-auth] Startup the auth platform via the startup.sh scripts
       [-g | --restart-auth] Restart the auth platform via the restart.sh scripts
       [-d | --deploy-core-platform] Deploy core platform via mvn
       [-w | --deploy-auth-platform] Deploy auth platform via mvn
    

    在脚本名后加上「-h 或者 –help」表示打印帮助。
    同理,加上「-p | –deploy-prepare」表示部署准备,加上「-c | –svn-co」表示检出项目,加上「-u | –svn-update」表示更新项目,加上「-s | –shutdown-core」表示关闭业务平台,加上「-t | –startup-core」表示启动业务平台,加上「-r | –restart-core」表示重启业务平台,加上「-a | –shutdown-auth」表示关闭认证平台,加上「–startup-auth」表示启动认证平台,加上「-g | –restart-auth」表示重启认证平台,加上「-d | –deploy-core-platform」表示部署业务平台,加上「-w | –deploy-auth-platform」表示部署认证平台。

    5.3 脚本概述

    如前所述,「auto_deploy_app_remote.py」是主执行脚本,用于显示帮助以及调用相应函数。「auto_deploy_app_v_final.py」是核心执行脚本,实现所有的相关功能。核心执行脚本采用Fabric实现远程执行命令,主执行脚本再通过fab -f 脚本名 任务名调用相应方法。

    主执行脚本和核心执行脚本的方法名基本一致,主执行脚本包括如下方法:main(argv)、usage()、svn_co()、svn_update()、shutdown_core()、startup_core()、restart_core()、shutdown_auth()、startup_auth()、restart_auth()、deploy_core_platform()、deploy_auth_platform()和deploy_prepare()。

    核心执行脚本包括如下方法:main(argv)、usage()、svn_co()、svn_update()、shutdown_core()、startup_core()、restart_core()、shutdown_auth()、startup_auth()、restart_auth()、deploy_core_platform()、deploy_auth_platform()、deploy_prepare()和getConfig()。

    主执行脚本:

    • main(argv) 主函数
    • usage() 使用说明函数
    • svn_co() 检出项目函数
    • svn_update() 更新项目函数
    • shutdown_core() 关闭业务平台方法
    • startup_core() 启动业务平台方法
    • restart_core() 重启业务平台方法
    • shutdown_auth() 关闭认证平台方法
    • startup_auth() 启动认证平台方法
    • restart_auth() 重启认证平台方法
    • deploy_core_platform() 部署业务平台方法
    • deploy_auth_platform() 部署认证平台方法
    • deploy_prepare() 部署准备方法

    主执行脚本内容如下:

    #!/usr/bin/env python
    #encoding:utf-8
    # Author: Robin Wen
    # Date: 11/25/2014 10:51:54
    # Desc: Auto deploy core-platform and auth to remote server. Main scripts.
    
    # Import necessary packages.
    import os
    import sys, getopt
    import socket
    import string
    import shutil
    import getopt
    import syslog
    import errno
    import logging
    import tempfile
    import datetime
    import subprocess
    import json
    import ConfigParser
    
    from operator import itemgetter
    from functools import wraps
    from getpass import getpass, getuser
    from glob import glob
    from contextlib import contextmanager
    
    from fabric.api import env, cd, prefix, sudo, run, hide, local, put
    from fabric.contrib.files import exists, upload_template
    from fabric.colors import yellow, green, blue, red
    
    try:
        import json
    except importError:
        import simplejson as json
    
    script_name='auto_deploy_app_v_final.py'
    log_path='/var/logs'
    
    """
    -----------------------------------------------------------------------------
    Auto deploy core-platform and auth to tomcat.
    
    Use the -h or the --help flag to get a listing of options.
    
    Program: Deploy application
    Author: Robin Wen
    Date: November 25, 2014
    Revision: 1.0
    """
    
    # Main function.
    def main(argv):
        try:
            # If no arguments print usage
            if len(argv) == 0:
                usage()
                sys.exit()
    
            # Receive the command line arguments. The execute the corresponding function.
            if sys.argv[1] == "-h" or sys.argv[1] == "--help":
                usage()
                sys.exit()
            elif sys.argv[1] == "-p" or sys.argv[1] == "--deploy-prepare":
                deploy_prepare()
            elif sys.argv[1] == "-c" or sys.argv[1] == "--svn-co":
                svn_co()
            elif sys.argv[1] == "-u" or sys.argv[1] == "--svn-update":
                svn_update()
            elif sys.argv[1] == "-s" or sys.argv[1] == "--shutdown-core":
                shutdown_core()
            elif sys.argv[1] == "-t" or sys.argv[1] == "--startup-core":
                startup_core()
            elif sys.argv[1] == "-r" or sys.argv[1] == "--restart-core":
                restart_core()
            elif sys.argv[1] == "-a" or sys.argv[1] == "--shutdown-auth":
                shutdown_auth()
            elif sys.argv[1] == "-k" or sys.argv[1] == "--startup-auth":
                startup_auth()
            elif sys.argv[1] == "-g" or sys.argv[1] == "--restart-auth":
                restart_auth()
            elif sys.argv[1] == "-d" or sys.argv[1] == "--deploy-core-platform":
                deploy_core_platform()
            elif sys.argv[1] == "-w" or sys.argv[1] == "--deploy-auth-platform":
                deploy_auth_platform() 
        except getopt.GetoptError, msg:
            # If an error happens print the usage and exit with an error       
            usage()
            sys.exit(errno.EIO)
    
    """
    Prints out the usage for the command line.
    """
    # Usage funtion.
    def usage():
        usage = [" Auto deploy application to the remote web server. Write in Python.\n"]
        usage.append("Version 1.0. By Robin Wen. Email:dbarobinwen@gmail.com\n")
        usage.append("\n")
        usage.append("Usage auto_deploy_app.py [-hcustrakgdwp]\n")
        usage.append("  [-h | --help] Prints this help and usage message\n")
        usage.append("  [-p | --deploy-prepare] Deploy prepared. Run as root\n")
        usage.append("  [-c | --svn-co] Checkout the newarkstg repo via svn\n")
        usage.append("  [-u | --svn-update] Update the newarkstg repo via svn\n")
        usage.append("  [-s | --shutdown-core] Shutdown the core platform via the stop.sh scripts\n")
        usage.append("  [-t | --startup-core] Startup the core platform via the startup.sh scripts\n")
        usage.append("  [-r | --restart-core] Restart the core platform via the restart.sh scripts\n")
        usage.append("  [-a | --shutdown-auth] Shutdown the auth platform via the stop.sh scripts\n")
        usage.append("  [-k | --startup-auth] Startup the auth platform via the startup.sh scripts\n")
        usage.append("  [-g | --restart-auth] Restart the auth platform via the restart.sh scripts\n")
        usage.append("  [-d | --deploy-core-platform] Deploy core platform via mvn\n")
        usage.append("  [-w | --deploy-auth-platform] Deploy auth platform via mvn\n")
        message = string.join(usage)
        print message
    
    # Checkout the newarkstg repo via svn function.
    def svn_co():
    
        print green('Checkout the newarkstg repo via svn.')
        print 'Logs output to the '+log_path+'/svn_co.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/svn_co.log")
        os.system("fab -f "+script_name+" svn_co > "+log_path+"/svn_co.log")
    
        print green('Checkout finished!')
    
    # Update the newarkstg repo via svn function.
    def svn_update():
    
        print green('Update the newarkstg repo via svn.')
        print 'Logs output to the '+log_path+'/svn_update.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/svn_update.log")
        os.system("fab -f "+script_name+" svn_update > "+log_path+"/svn_update.log")
    
        print green('Update finished!')
    
    # Shutdown the core platform via the stop.sh scripts function.
    def shutdown_core():
    
        print green('Shutdown the core platform via the stop.sh scripts.')
        print 'Logs output to the '+log_path+'/shutdown_core.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/shutdown_core.log")
        os.system("fab -f "+script_name+" shutdown_core > "+log_path+"/shutdown_core.log")
    
        print green('Shutdown the core platform finished!')
    
    # Startup the core platform via the startup.sh scripts function.
    def startup_core():
    
        print green('Startup the core platform via the startup.sh scripts.')
        print 'Logs output to the '+log_path+'/startup_core.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/startup_core.log")
        os.system("fab -f "+script_name+" startup_core > "+log_path+"/startup_core.log")
    
        print green('Startup the core platform finished!')
    
    # Restart the core platform via the restart.sh scripts function.
    def restart_core():
        print green('Restart the core platform via the restart.sh scripts.')
        print 'Logs output to the '+log_path+'/restart_core.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/restart_core.log")
        os.system("fab -f "+script_name+" restart_core > "+log_path+"/restart_core.log")
    
        print green('Restart the core platform finished!')
    
    # Shutdown the auth platform via the stop.sh scripts function.
    def shutdown_auth():
    
        print green('Shutdown the auth platform via the stop.sh scripts.&##39;)
        print 'Logs output to the '+log_path+'/shutdown_auth.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/shutdown_auth.log")
        os.system("fab -f "+script_name+" shutdown_auth > "+log_path+"/shutdown_auth.log")
    
        print green('Shutdown the auth platform finished!')
    
    # Startup the auth platform via the startup.sh scripts function.
    def startup_auth():
    
        print green('Startup the auth platform via the startup.sh scripts.')
        print 'Logs output to the '+log_path+'/startup_auth.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/startup_auth.log")
        os.system("fab -f "+script_name+" startup_auth > "+log_path+"/startup_auth.log")
    
        print green('Startup the authplatform finished!')
    
    # Restart the auth platform via the restart.sh scripts function.
    def restart_auth():
        print green('Restart the core platform via the restart.sh scripts.')
        print 'Logs output to the '+log_path+'/restart_auth.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/restart_auth.log")
        os.system("fab -f "+script_name+" restart_auth> "+log_path+"/restart_auth.log")
    
        print green('Restart the core platform finished!')
    
    # Deploy core platform via mvn function.
    def deploy_core_platform():
    
        print green('Deploy core platform via mvn.')
        print 'Logs output to the '+log_path+'/deploy_core_platform.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/deploy_core_platform.log")
        os.system("fab -f "+script_name+" deploy_core_platform > "+log_path+"/deploy_core_platform.log")
    
        print green('Congratulations! Deploy core platform finished!')
    
    # Deploy auth platform via mvn.
    def deploy_auth_platform():
    
        print green('Deploy auth platform via mvn.')
        print 'Logs output to the '+log_path+'/deploy_auth_platform.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/deploy_auth_platform.log")
        os.system("fab -f "+script_name+" deploy_auth_platform > "+log_path+"/deploy_auth_platform.log")
    
        print green('Congratulations! Deploy auth platform finished!')
        print red('Attention! If you want take a glance of the deploy log, contact the system administrator.')
    
    def deploy_prepare():
    
        print green('Deploy prepared. Run as root.')
        # Install jdk 1.8.25.
        print red('This program require jdk 1.8.25. Make sure jdk and tomcat work out before all of your operations.')
        #Install Maven
        print green('Install maven.')
        print 'Logs output to the '+log_path+'/deploy_prepare.log'
    
        os.system('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        os.system("echo '' > "+log_path+"/deploy_prepare.log")
        os.system("fab -f "+script_name+" deploy_prepare > "+log_path+"/deploy_prepare.log")
    
        print green('Deploy prepared finished.')
    
    # The entrance of program.
    if __name__=='__main__':
        main(sys.argv[1:])
    

    核心执行脚本

    方法和主执行脚本基本一致,相同的不赘述。核心执行脚本还提供getConfig()方法,用于读取配置文件。

    核心执行脚本内容如下:

    #!/usr/bin/env python
    #encoding:utf-8
    # Author: Robin Wen
    # Date: 11/25/2014 10:51:54
    # Desc: Auto deploy core-platform and auth to remote server. Core scripts.
    
    # Import necessary packages.
    import os
    import sys, getopt
    import socket
    import string
    import shutil
    import getopt
    import syslog
    import errno
    import logging
    import tempfile
    import datetime
    import subprocess
    import json
    import ConfigParser
    
    from operator import itemgetter
    from functools import wraps
    from getpass import getpass, getuser
    from glob import glob
    from contextlib import contextmanager
    
    from fabric.api import env, cd, prefix, sudo, run, hide, local, put
    from fabric.contrib.files import exists, upload_template
    from fabric.colors import yellow, green, blue, red
    
    try:
        import json
    except importError:
        import simplejson as json
    
    # Configuration file name.
    config_file='config.conf'
    
    # Get configuration from the Config 
    def getConfig(section, key):
        config = ConfigParser.ConfigParser()
        path = os.path.split(os.path.realpath(__file__))[0] + '/'+config_file
        config.read(path)
        return config.get(section, key)
    
    # Log path
    log_path=getConfig("other", "remote_log_path")
    
    # Remote server hosts.
    hosts=getConfig("remote", "remote_usr")+"@"+getConfig("remote", "remote_ip")+":"+getConfig("remote", "remote_port")
    
    # Remote server password.
    password=getConfig("remote", "remote_pwd")
    
    env.hosts=[hosts,]
    env.password = password
    
    # Remote server ip.
    remote_ip=getConfig("remote", "remote_ip")
    
    # Remote server username.
    remote_usr=getConfig("remote", "remote_usr")
    
    # Remote server password.
    remote_pwd=getConfig("remote", "remote_pwd")
    
    # Declare multiple variables.
    
    # Core platform path.
    core_platform_path=getConfig("core_path", "core_platform_path")
    
    # Core platform configuration file path.
    core_platform_config_path=getConfig("core_path", "core_platform_config_path")
    
    # Auth platform path.
    auth_path=getConfig("auth_path", "auth_path")
    
    # Auth platform configuration path.
    auth_platform_config_path=getConfig("auth_path", "auth_platform_config_path")
    
    # Core platform config api path
    core_platform_config_api_path=getConfig("core_path", "core_platform_config_api_path")
    
    # Core platform config auth path
    core_platform_config_auth_path=getConfig("core_path", "core_platform_config_auth_path")
    
    # Auth platform configuration api path.
    auth_platform_config_api_path=getConfig("auth_path", "auth_platform_config_api_path")
    
    # Auth platform configuration auth path.
    auth_platform_config_auth_path=getConfig("auth_path", "auth_platform_config_auth_path")
    
    # Svn main directory of newarkstg repo.
    svn_ns_dir=getConfig("svn_path", "svn_ns_dir")
    
    # Svn core platform path.
    svn_core_platform_path=getConfig("svn_path", "svn_core_platform_path")
    
    # Svn core platform target path.
    svn_core_platform_target_path=getConfig("svn_path", "svn_core_platform_target_path")
    
    # Database address.
    db_addr=getConfig("database", "db_addr")
    
    # Database username.
    db_usr=getConfig("database", "db_usr")
    
    # Datbase password.
    db_pwd=getConfig("database", "db_pwd")
    
    # SVN username.
    svn_username=getConfig("svn", "svn_username")
    
    # SVN password.
    svn_password=getConfig("svn", "svn_password")
    
    # SVN url.
    svn_url=getConfig("svn", "svn_url")
    
    # Memcached server ip.
    memcached_ip=getConfig("memcached", "memcached_ip")
    
    # Memcached server port.
    memcached_port=getConfig("memcached", "memcached_port")
    
    # Local ip address. Deploy the application on the localhost by default.
    ip_addr=getConfig("remote", "remote_ip")
    
    # Core platform version.
    core_version=getConfig("other", "core_version")
    
    # Api port
    api_port=getConfig("other", "api_port")
    
    # Core platform bundles path
    core_platform_bundles_path=getConfig("core_path", "core_platform_bundles_path")
    
    # Auth platform bundles path
    auth_platform_bundles_path=getConfig("auth_path", "auth_platform_bundles_path")
    
    # Core platform jar name
    core_platform_jar=getConfig("other", "core_platform_jar")
    
    # Auth platform jar name
    auth_platform_jar=getConfig("other", "auth_platform_jar")
    
    # Core jar
    core_jar=getConfig("other", "core_jar")
    
    # Auth jar
    auth_jar=getConfig("other", "auth_jar")
    
    """
    -----------------------------------------------------------------------------
    Auto deploy core-platform and auth to tomcat.
    
    Use the -h or the --help flag to get a listing of options.
    
    Program: Deploy application
    Author: Robin Wen
    Date: November 25, 2014
    Revision: 1.0
    """
    # Checkout the newarkstg repo via svn function.
    def svn_co():
        print green('Checkout the newarkstg repo via svn.')
    
        # Create necessary directory
        run('mkdir -p '+svn_ns_dir+' 2>/dev/null >/dev/null')
    
        #run('ls -l '+path+'')
        with cd(svn_ns_dir):
            run('svn co --username '+svn_username+' --password '+svn_password+' '+svn_url+' '+svn_ns_dir+'')
    
        print green('Checkout finished!')
    
    # Update the newarkstg repo via svn function.
    def svn_update():
        print green('Update the newarkstg repo via svn.')
    
        # Create necessary directory
        run('mkdir -p '+svn_ns_dir+' 2>/dev/null >/dev/null')
    
        with cd(svn_ns_dir):
            run('svn update --username '+svn_username+' --password '+svn_password+' '+svn_ns_dir+'')
    
        print green('Update finished!')
    
    # Shutdown the core platform via the stop.sh scripts function.
    def shutdown_core():
        print green('Shutdown the core platform via the stop.sh scripts.')
    
        os.system('sshpass -p '+remote_pwd+' ssh -o StrictHostKeyChecking=no '+remote_usr+'@'+remote_ip+' "cd '+core_platform_path+'; ./stop.sh &" &')
    
        print green('Shutdown the core platform finished!')
    
    # Startup the core platform via the startup.sh scripts function.
    def startup_core():
        print green('Startup the core platform via the startup.sh scripts.')
    
        os.system('sshpass -p '+remote_pwd+' ssh -o StrictHostKeyChecking=no '+remote_usr+'@'+remote_ip+' "cd '+core_platform_path+'; ./startup.sh &" &')
    
        print green('Startup the core platform finished!')
    
    # Restart the core platform via the startup.sh scripts function.
    def restart_core():
        print green('Restart the core platform via the restart.sh scripts.')
    
        os.system('sshpass -p '+remote_pwd+' ssh -o StrictHostKeyChecking=no '+remote_usr+'@'+remote_ip+' "cd '+core_platform_path+'; ./restart.sh &" &')
    
        print green('Restart the core platform finished!')
    
    # Shutdown the auth platform via the stop.sh scripts function.
    
    def shutdown_auth():
        print green('Shutdown the auth platform via the stop.sh scripts.')
    
        os.system('sshpass -p '+remote_pwd+' ssh -o StrictHostKeyChecking=no '+remote_usr+'@'+remote_ip+' "cd '+auth_path+'; ./stop.sh &" &')
    
        print green('Shutdown the auth platform finished!')
    
    # Startup the auth platform via the startup.sh scripts function.
    def startup_auth():
        print green('Startup the auth platform via the startup.sh scripts.')
    
        os.system('sshpass -p '+remote_pwd+' ssh -o StrictHostKeyChecking=no '+remote_usr+'@'+remote_ip+' "cd '+auth_path+'; ./startup.sh &" &')
    
        print green('Startup the authplatform finished!')
    
    # Restart the auth platform via the startup.sh scripts function.
    def restart_auth():
        print green('Restart the core platform via the restart.sh scripts.')
    
        os.system('sshpass -p '+remote_pwd+' ssh -o StrictHostKeyChecking=no '+remote_usr+'@'+remote_ip+' "cd '+auth_path+'; ./restart.sh &" &')
    
        print green('Restart the core platform finished!')
    
    # Deploy core platform via mvn function.
    def deploy_core_platform():
        print green('Deploy core platform via mvn.')
    
        # Create necessary directory
        run('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
        run('mkdir -p '+svn_core_platform_path+' 2>/dev/null >/dev/null')
        run('mkdir -p '+svn_core_platform_target_path+' 2>/dev/null >/dev/null')
        run('mkdir -p '+core_platform_path+' 2>/dev/null >/dev/null')
    
        with cd(svn_core_platform_path):
            # Print waiting info.
            print ''
            print red('Please wait the deploy process until it automatically exit...')
    
            # Install the necessary jar.
    
            # Clear the core platform deploy log.
            run('echo "" > '+log_path+'/core_deploy.log')
            run('mvn install:install-file -Dfile='+svn_core_platform_path+'/lib/org.eclipse.osgi_3.10.0.v20140606-1445.jar -DgroupId=org.eclipse.osgi -DartifactId=org.eclipse.osgi -Dversion=3.10.0.v20140606 -Dclassifier=1445 -Dpackaging=jar > '+log_path+'/core_deploy.log')
    
            run('mvn install:install-file -Dfile='+svn_core_platform_path+'/lib/org.eclipse.osgi.services_3.4.0.v20140312-2051.jar -DgroupId=org.eclipse.osgi -DartifactId=org.eclipse.osgi.services -Dversion=3.4.0.v20140312 -Dclassifier=2051 -Dpackaging=jar >> '+log_path+'/core_deploy.log')
    
            # Pack the core platform use mvn command.
            run('mvn clean install >> '+log_path+'/core_deploy.log')
    
            # Remove the useless directory.
            run('rm -rf '+svn_core_platform_target_path+'/'+'classes')
            run('rm -rf '+svn_core_platform_target_path+'/'+'maven-archiver')
            run('rm -rf '+svn_core_platform_target_path+'/'+'maven-status')
    
        # Copy the packed core platform to the deploy directory.
        run('cp -r '+svn_core_platform_target_path+'/'+'* '+core_platform_path)
    
        # Remove the newarkstg-osgi-auth_version.jar.
        run('rm -rf '+core_platform_path+'/bundles/platform/newarkstg-osgi-auth_'+core_version+'.jar')
    
        # Change the privileges of scripts. Make it executable.
        run('chmod +x '+core_platform_path+'/'+'*.sh')
    
        # Update the service address. Use the local ip address by default.
        run("sed -i 's/^service_addr=.*$/service_addr=http:\/\/"+ip_addr+":8789\/auth\//g' "+core_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the database url.
        run("sed -i 's/^url=.*$/url=jdbc:mysql:\/\/"+db_addr+":3306\/cmms_auth\//g' "+core_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the database username.
        run("sed -i 's/^username=.*$/username="+db_usr+"/g' "+core_platform_config_auth_path+"/osgi-auth-config.properties")
        # Update the database password.
        run("sed -i 's/^password=.*$/password="+db_pwd+"/g' "+core_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the authentication server host.
        run("sed -i 's/^authentication_server_host_name=.*$/authentication_server_host_name="+ip_addr+"/g' "+core_platform_config_api_path+"/osgi-util-config.properties")
    
        # Update the memcached server ip.
        run("sed -i 's/^memcached_server_name=.*$/memcached_server_name="+memcached_ip+"/g' "+core_platform_config_api_path+"/osgi-util-config.properties")
    
        # Update the memcached server port.
        run("sed -i 's/^memcached_server_port=.*$/memcached_server_port="+memcached_port+"/g' "+core_platform_config_api_path+"/osgi-util-config.properties")
    
        # Update the memcached server ip.
        run("sed -i 's/^memcached_server_name=.*$/memcached_server_name="+memcached_ip+"/g' "+core_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the memcached server port.
        run("sed -i 's/^memcached_server_port=.*$/memcached_server_port="+memcached_port+"/g' "+core_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the bundles directory.
        run("sed -i 's/^platform\.bundles\.root\.dir=.*$/platform\.bundles\.root\.dir="+core_platform_bundles_path+"/g' "+core_platform_config_path+"/osgi-container.properties")
    
        # Update the api service configuration.
        run("sed -i 's/address=.*$/address=\"http:\/\/"+ip_addr+":"+api_port+"\" \>/g' "+core_platform_config_api_path+"/api-service.xml")
    
        # Remove the end of configuration file. ^M mark.
        run("dos2unix "+core_platform_config_auth_path+"/osgi-auth-config.properties")
        run("dos2unix "+core_platform_config_api_path+"/osgi-util-config.properties")
        run("dos2unix "+core_platform_config_path+"/osgi-container.properties")
    
        # Remove the auth directory.
        run("rm -rf "+core_platform_config_path+"/auth")
    
        print green('Congratulations! Deploy core platform finished!')
    
    # Deploy auth platform via mvn.
    def deploy_auth_platform():
        print green('Deploy auth platform via mvn.')
    
        # Create necessary directory
        run('mkdir -p '+svn_core_platform_target_path+' 2>/dev/null >/dev/null')
        run('mkdir -p '+auth_path+' 2>/dev/null >/dev/null')
    
        # Copy the packed core platform to the deploy directory.
        run("cp -r "+svn_core_platform_target_path+"/"+"* "+auth_path)
    
        # Change the privileges of scripts. Make it executable.
        run("chmod +x "+auth_path+"/"+"*.sh")
    
        # Remove the newarkstg-osgi-auth_version.jar.
        run("rm -rf "+auth_path+"/bundles/platform/newarkstg-osgi-auth_"+core_version+".jar")
    
        # Remove the busi directory.
        run("rm -rf "+auth_path+"/bundles/busi")
    
        # Update the service address. Use the local ip address by default.
        run("sed -i 's/^service_addr=.*$/service_addr=http:\/\/"+ip_addr+":8789\/auth\//g' "+auth_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the database url.
        run("sed -i 's/^url=.*$/url=jdbc:mysql:\/\/"+db_addr+":3306\/cmms_auth\//g' "+auth_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the database username.
        run("sed -i 's/^username=.*$/username="+db_usr+"/g' "+auth_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the database password.
        run("sed -i 's/^password=.*$/password="+db_pwd+"/g' "+auth_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the authentication server host.
        run("sed -i 's/^authentication_server_host_name=.*$/authentication_server_host_name="+ip_addr+"/g' "+auth_platform_config_api_path+"/osgi-util-config.properties")
    
        # Update the memcached server ip.
        run("sed -i 's/^memcached_server_name=.*$/memcached_server_name="+memcached_ip+"/g' "+auth_platform_config_api_path+"/osgi-util-config.properties")
    
        # Update the memcached server port.
        run("sed -i 's/^memcached_server_port=.*$/memcached_server_port="+memcached_port+"/g' "+auth_platform_config_api_path+"/osgi-util-config.properties")
    
        # Update the memcached server ip.
        run("sed -i 's/^memcached_server_name=.*$/memcached_server_name="+memcached_ip+"/g' "+auth_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the memcached server port.
        run("sed -i 's/^memcached_server_port=.*$/memcached_server_port="+memcached_port+"/g' "+auth_platform_config_auth_path+"/osgi-auth-config.properties")
    
        # Update the bundles directory.
        run("sed -i 's/^platform\.bundles\.root\.dir=.*$/platform\.bundles\.root\.dir="+auth_platform_bundles_path+"/g' "+auth_platform_config_path+"/osgi-container.properties")
    
        # Rename the jar.
        with cd(auth_path):
            sudo('./rename.sh '+core_platform_jar+' '+auth_platform_jar+'')
    
        # Optimize the stop scripts
        run("sed -i 's/"+core_jar+"/"+auth_jar+"/g' "+auth_path+"/stop.sh")
    
        # Remove the end of configuration file. ^M mark.
        run("dos2unix "+auth_platform_config_auth_path+"/osgi-auth-config.properties")
        run("dos2unix "+auth_platform_config_api_path+"/osgi-util-config.properties")
        run("dos2unix "+auth_platform_config_path+"/osgi-container.properties")
    
        # Remove the api directory.
        run("rm -rf "+auth_platform_config_path+"/api")
    
        print green('Congratulations! Deploy auth platform finished!')
    
    def deploy_prepare():
        print green('Deploy prepared. Run as root.')
    
        # Install jdk 1.8.25.
        print red('This program require jdk 1.8.25. Make sure jdk and tomcat work out before all of your operations.')
    
        # Install maven.
        print green('Insall maven.')
        run("wget http://apache.fayea.com/apache-mirror/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.zip")
        run("unzip -q apache-maven-3.2.3-bin.zip")
        run("mv apache-maven-3.2.3 /usr/local/maven")
        run("echo 'export M2_HOME=/usr/local/maven' >> /etc/profile")
        run("echo 'export PATH=$PATH:$M2_HOME/bin' >> /etc/profile")
        run("source /etc/profile")
        run("rm -rf apache-maven-3.2.3-bin.zip apache-maven-3.2.3")
        run("quot;mvn -version")
    
        log_path='/root/logs'
    
        run('mkdir -p '+log_path+' 2>/dev/null >/dev/null')
    
        # Clear the install_requirement.log
        run('echo "" > '+log_path+'/install_requirement.log')
    
        # Install Python and fabric on the remote server.
        run("apt-get install dos2unix python python-pip python-dev subversion subversion-tools -y > "+log_path+"/install_requirement.log")
        run("pip install fabric >> "+log_path+"/install_requirement.log")
    
        # Install Python and fabric on the local server.
        os.system("apt-get install dos2unix python python-pip python-dev subversion subversion-tools -y > "+log_path+"/install_requirement.log")
        os.system("pip install fabric >> "+log_path+"/install_requirement.log")
    
        # Install sshpass.
        print green('Install sshpass.')
        os.system("wget http://jaist.dl.sourceforge.net/project/sshpass/sshpass/1.05/sshpass-1.05.tar.gz")
        os.system("tar -zxf sshpass-1.05.tar.gz")
        os.system("cd sshpass-1.05 && ./configure && make && make install")
    
        print green('Deploy prepared finished.')
    

    5.4 配置文件概述

    完整配置文件内容如下(因涉及利益问题,所有的配置已去除,读者可以根据需要配置):

    # Database config section.
    [database]
    # Database address.
    db_addr=
    # Database username.
    db_usr=
    # Datbase password.
    db_pwd=
    
    # Remote server section.
    [remote]
    # Remote server ip.
    remote_ip=
    # Remote server port.
    remote_port=
    # Remote server username.
    remote_usr=
    # Remote server password.
    remote_pwd=
    
    # SVN path section.
    [svn_path]
    # Svn main directory of newarkstg repo.
    svn_ns_dir=
    # Svn core platform path.
    svn_core_platform_path=
    # Svn core platform target path.
    svn_core_platform_target_path=
    
    # SVN configuration section. 
    [svn]
    svn_username=
    svn_password=
    svn_url=
    
    # Core platform path config section.
    [core_path]
    # Core platform path.
    core_platform_path=
    # Core platform config path.
    core_platform_config_path=
    # Core platform config api path
    core_platform_config_api_path=
    # Core platform config auth path
    core_platform_config_auth_path=
    # Core platform bundles path
    core_platform_bundles_path=
    
    # Auth platform path config section.
    [auth_path]
    # Auth platform path.
    auth_path=
    # Auth platform configuration path.
    auth_platform_config_path=
    # Auth platform configuration api path.
    auth_platform_config_api_path=
    # Auth platform configuration auth path.
    auth_platform_config_auth_path=
    # Authplatform bundles path
    auth_platform_bundles_path=
    
    # Memcached configuration section.
    [memcached]
    # Memcached server ip.
    memcached_ip=
    # Memcached server port.
    memcached_port=
    
    # Other configuration section
    [other]
    # Core platform version.
    core_version=
    # Remote log path
    remote_log_path=
    # Api port
    api_port=
    # Core platform jar name
    core_platform_jar=
    # Auth platform jar name
    auth_platform_jar=
    # Core jar
    core_jar=
    # Auth jar
    auth_jar=
    

    接下来,我逐一进行讲解。

    配置文件包括以下段:database、remote、svn_path、svn、core_path、auth_path、memcached和other。

    每个段的说明如下:

    • database 该段定义数据库配置。
      • db_addr MySQL数据库地址。
      • db_usr MySQL数据库用户名。
      • db_pwd MySQL数据库密码。
    • remote 该段定义远程服务器登录信息。
      • remote_ip 部署远程服务器IP。
      • remote_port 部署远程服务器端口。
      • remote_usr 部署远程服务器用户名。
      • remote_pwd 部署远程服务器密码。
    • svn_path 该段定义远程服务器SVN目录。
      • svn_ns_dir 项目主SVN目录。
      • svn_core_platform_path 业务平台SVN目录。
      • svn_core_platform_target_path 业务平台Target目录,用于存放打包后的文件。
    • svn 该段定义SVN的账户信息。
      • svn_username SVN用户名。
      • svn_password SVN密码。
      • svn_url SVN地址。
    • core_path 该段定义部署后的业务平台目录。
      • core_platform_path 业务平台主目录。
      • core_platform_config_path 业务平台配置文件目录。
      • core_platform_config_api_path 业务平台API配置文件目录。
      • core_platform_config_auth_path 业务平台AUTH配置文件目录。
      • core_platform_bundles_path 业务平台Bundles目录。
    • auth_path 该段定义部署后的认证平台目录。
      • auth_path 认证平台主目录。
      • auth_platform_config_path 认证平台配置文件目录。
      • auth_platform_config_api_path 认证平台API配置文件目录。
      • auth_platform_config_auth_path 认证平台AUTH配置文件目录。
      • auth_platform_bundles_path 认证平台Bundles目录。
    • memcached 该段定义Memcached相关信息。
      • memcached_ip Memcached服务器IP。
      • memcached_port Memcached服务器端口。
    • other 该段定义其他配置信息。
      • core_version 业务平台版本号。
      • remote_log_path 远程服务器日志文件目录,用于存放部署业务平台产生的日志。
      • api_port 业务平台的API端口。
      • core_platform_jar 打包生成的业务平台jar包。
      • auth_jar 认证平台jar包。

    以上是所有的配置项,请酌情修改。

    6.脚本使用

    如果您是第一次使用该脚本打包,请依次执行如下命令:

    # 第一步编辑配置文件
    vim config.conf
    
    # 第二步显示帮助
    ./auto_deploy_app_remote.py -h
    
    # 第三步准备部署
    ./auto_deploy_app_remote.py -p
    
    # 第四步检出项目
    ./auto_deploy_app_remote.py -c
    
    # 第五步部署业务平台
    ./auto_deploy_app_remote.py -d
    
    # 第六步部署认证平台
    ./auto_deploy_app_remote.py -w
    
    # 第七步启动认证平台
    ./auto_deploy_app_remote.py -k
    
    # 第八布启动业务平台
    ./auto_deploy_app_remote.py -t
    

    注:第七步可以使用「./auto_deploy_app_remote.py -g」代替,第八步可以使用「./auto_deploy_app_remote.py -r」代替。

    如果您是使用该脚本更新项目,请依次执行如下命令:

    # 第一步如有需要编辑配置文件
    vim config.conf
    
    # 第二步显示帮助
    ./auto_deploy_app_remote.py -h
    
    # 第三步更新项目
    ./auto_deploy_app_remote.py -u
    
    # 第四步关闭认证平台
    ./auto_deploy_app_remote.py -a
    
    # 第五步关闭业务平台
    ./auto_deploy_app_remote.py -s
    
    # 第六步部署业务平台
    ./auto_deploy_app_remote.py -d
    
    # 第七步部署认证平台
    ./auto_deploy_app_remote.py -w
    
    # 第八步启动认证平台
    ./auto_deploy_app_remote.py -k
    
    # 第九布启动业务平台
    ./auto_deploy_app_remote.py -t
    

    注:第八步可以使用「./auto_deploy_app_remote.py -g」代替,第九步可以使用「./auto_deploy_app_remote.py -r」代替。

    7.GitHub地址

    python-auto-deploy:https://github.com/dbarobin/python-auto-deploy

    8.作者信息

    温国兵

    展开全文
  • Python实现iOS自动化打包
  • 主要介绍了Python实现iOS自动化打包详解步骤,文中通过示例代码以及图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
  • 主要给大家介绍了关于Python的iOS自动化打包的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
  • python脚本实现自动化打包.zip,python脚本实现自动化打包
  • 点击上方“AirPython”,选择“置顶公众号”第一时间获取 Python 技术干货!阅读文本大概需要 6 分钟。之前有读者朋友说 Airtest 官方支持将自动化脚本编译成 APK ...

    点击上方“AirPython”,选择“置顶公众号”

    第一时间获取 Python 技术干货!

    阅读文本大概需要 6 分钟。

    之前有读者朋友说 Airtest 官方支持将自动化脚本编译成 APK 直接运行,照着官方提供的文档操作了一遍,发现不少的坑,今天带大家一起来填这些坑。

    在开始编写自动化脚本之前,我们首先要下载安装 JDK,并配置 JDK 和 ADB 到环境变量中。

    以刷抖音短视频这一自动化操作为例,首先我们使用 Airtest IDE 新建一个 .air Airtest 项目。

    和常规自动化操作类似,我们需要借助 ADB 命令拿到抖音 App 的应用包名和初始 Activity,利用 start_app() 方法打开抖音。

    package_name = 'com.ss.android.ugc.aweme'
    activity_name = 'com.ss.android.ugc.aweme.splash.SplashActivity'
    
    # 部分手机需要开启模拟点击
    start_app(package_name,activity=activity_name)

    接着拿到屏幕的宽、高数值,利用 swipe() 方法模拟滑动,即可以实现切换视频的操作。

    device_attrs  = device()
    print(device_attrs.uuid)
    
    # 获取设备的高度和宽度
    width, height = device_attrs.get_current_resolution()
    
    print(width)
    print(height)
    
    # 开始刷抖音
    while True:
        # 滑动一次
        swipe( (width * 0.5, height*3/ 4),(width * 0.5, height / 4),duration=1)
        sleep(2)
    

    上面这段代码直接在 IDE 运行,自动化操作能正常运行。

    下一步,利用 Firebase 打包脚本,依次点击:Firebase - 打包多个脚本 - 选择目标脚本,等待本地生成一个 apk 文件。

    使用 adb 命令将 apk 安装到手机上,接着通过 instrument 开启自动化操作。

    # 开启自动化任务
    adb shell am instrument -w com.netease.open.airbase/android.support.test.runner.AndroidJUnitRunner
    

    坑一:运行之后很快就报错了,报 device() 方法在 kivy 中没有实现。

    官方文档提到的原生应用的 poco 没法使用,包含 device() 在内的很多方法,虽然属于 airtest 内部的方法,但是打包成 apk 识别不到。

    我们可以将宽度和高度写死,然后再进行滑动操作。

    width = 1080
    height = 2160
    
    swipe( (width * 0.5, height*1/ 4),(width * 0.5, height*3 / 4),duration=0.5)
    

    坑二:向上滑动事件处理不当。

    测试多台设备后发现,脚本代码生成的 apk 在不同设备上运行结果不一致。

    仅上面的向上滑动这一步操作,有些手机当做 长按屏幕 来消费,还有一些手机当做 下拉刷新 来处理。

    建议先在 Airtest IDE 中运行,保证脚本的正确性的前提下,再去替换改写不被 apk 识别的部分。

    总之,利用 Firebase 打包自动化脚本成 apk 单独运行还不是很稳定,另外一起打包内置的 kivy 库还需要兼容和完善,期待官方下一版本。

    本篇所有的源码我已经上传到公众号后台,回复关键字:dbapk 获取完整代码。

    如果你觉得文章还不错,请大家点个好看或者分享出去,你的肯定是我最大的鼓励和支持。

    推荐阅读

    这款黑科技,不会代码也能玩自动化,高效摸鱼

    自动化篇 | 再也不用担心老人们用智能机了

    短视频篇 | Python  带你进行短视频二次创作

    THANDKS

    - End -

    展开全文
  • Pythonselenium自动化脚本打包成一个exe.pdf
  • 主要介绍了Python selenium 自动化脚本打包成一个exe文件,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
  • 打包设置,常用development (1)app-store (2)ad-hoc (3)enterprise (4)development  enviroment = "development" # 调试模式的小篮球开关 True False  debugFlag = True # 服务端的...

    # -*- coding: utf-8 -*-

    import requests

    import os

    from biplist import *

    from mod_pbxproj import XcodeProject

     

    def CleanDirectory(dirPath):

        isexits = os.path.exists(dirPath)

        if isexits:

            for root, dirs, files in os.walk(dirPath):

                for fileName in files:

                    del_file = os.path.join(root, fileName)

                    os.remove(del_file)

        else:

            os.mkdir(dirPath)

     

    class Server():

        dev     = 0

        test    = 1

        online  = 2

        staging = 3

     

    def CodeUpdate():

        gotoRootDir = os.system("cd %s"%(os.getcwd()))

        gitFetch = os.system("git fetch --all")

        gitResetLocal = os.system("git reset --hard origin/master")

        gitPull = os.system("git pull")

     

    def ModifyInfoPlist(app_name,app_version,build_version="1.0"):

        infoPlist = readPlist('./Pocket7Games/Info.plist')

        infoPlist["CFBundleVersion"] = build_version

        infoPlist["CFBundleShortVersionString"] = app_version

        infoPlist["CFBundleDisplayName"] = app_name

        writePlist(infoPlist,"./Pocket7Games/Info.plist")

     

    def ModifyExportOptionsPlist(team_id,method,profile_id,profile_name):

        exportPlist = readPlist('./ExportOptions.plist')

        exportPlist["teamID"] = team_id

        exportPlist["method"] = method

        exportPlist["provisioningProfiles"] = {profile_id:profile_name}

        writePlist(exportPlist,"./ExportOptions.plist")

     

    def ModifyXcodeProject(bundle_id,profile_name,codesign_id,team_id):

        project = XcodeProject.Load('./Pocket7Games.xcodeproj/project.pbxproj')

        rootObject = project["rootObject"]

        projectObject = project["objects"][rootObject]["targets"]

        buildConfigurationLists = []

        for id in projectObject:

            buildConfigurationList = project["objects"][id]["buildConfigurationList"]

            buildConfigurationLists.append(buildConfigurationList)

        buildListsArr = []

        for key in buildConfigurationLists:

            buildListsArr = buildListsArr + project["objects"][key]["buildConfigurations"]

        for key in buildListsArr:

            version =  project["objects"][key]["name"].lower()

            if project["objects"][key]["buildSettings"]:

                buildSettingsArr = project["objects"][key]["buildSettings"]

                buildSettingsArr['PRODUCT_BUNDLE_IDENTIFIER'] = bundle_id

                buildSettingsArr['PROVISIONING_PROFILE_SPECIFIER'] = profile_name

                buildSettingsArr['CODE_SIGN_IDENTITY'] = codesign_id

                buildSettingsArr['CODE_SIGN_STYLE'] = "Manual"

                buildSettingsArr['DEVELOPMENT_TEAM'] = team_id

        project.save()

     

    def ModifyLinkedServer(server):

        networkDefinesPath = './Pocket7Games/NetWork/NCNetWorkDefines.h'

        networkDefinesPath_New = './Pocket7Games/NetWork/NCNetWorkDefines_New.h'

        networkDefinesPath_Bak = './Pocket7Games/NetWork/NCNetWorkDefines_Bak.h'

        with open(networkDefinesPath, 'r') as read_file, open(networkDefinesPath_New, 'w') as write_file:

            for r_line in read_file:

                if "#define HostFlag" in r_line :

                    serverString = "#define HostFlag %d\n"%(server)

                    write_file.write(serverString)

                else:

                    write_file.write(r_line)

        os.rename(networkDefinesPath, networkDefinesPath_Bak)

        os.rename(networkDefinesPath_New, networkDefinesPath)

        os.remove(networkDefinesPath_Bak)

     

    def ModifyDebugBall(show_debugball):

        debugBallPath = './Pocket7Games/AviaAppDelegate.mm'

        debugBallPath_New = './Pocket7Games/AviaAppDelegate_New.mm'

        debugBallPath_Bak = './Pocket7Games/AviaAppDelegate_Bak.mm'

        with open(debugBallPath, 'r') as read_file, open(debugBallPath_New, 'w') as write_file:

            for r_line in read_file:

                if "[[AviaDebug sharedAviaDebug] addDebugButton]" in r_line :

                    if show_debugball:

                        write_file.write("    [[AviaDebug sharedAviaDebug] addDebugButton];\n")

                    else:

                        write_file.write("//    [[AviaDebug sharedAviaDebug] addDebugButton];\n")

                else:

                    write_file.write(r_line)

        os.rename(debugBallPath, debugBallPath_Bak)

        os.rename(debugBallPath_New, debugBallPath)

        os.remove(debugBallPath_Bak)

     

    def OutputIPA():

        BuildCommandPath = "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild"

        archiveDir = "{0}/NC_iOSArchive".format(os.path.join(os.path.expanduser("~"), 'Desktop'))

        archivePath = "{0}/NC_iOSArchive/Pocket7Games".format(os.path.join(os.path.expanduser("~"), 'Desktop'))

        exportOptionsPath = os.path.abspath('ExportOptions.plist')

        CleanDirectory(archiveDir)

        cleanResult = os.system("{0} -workspace Pocket7Games.xcworkspace -scheme Pocket7Games clean".format(BuildCommandPath))

        buildResult = os.system("{0} -workspace Pocket7Games.xcworkspace -scheme Pocket7Games build".format(BuildCommandPath))

        archiveResult = os.system("{0} archive -workspace Pocket7Games.xcworkspace -scheme Pocket7Games -archivePath {1}".format(BuildCommandPath,archivePath))

        outputIPAResult = os.system("{0} -exportArchive -archivePath {1}.xcarchive -exportPath {2} -exportOptionsPlist {3}".format(BuildCommandPath,archivePath,archiveDir,exportOptionsPath))

        ipaPath = "%s.ipa"%(archivePath)

        print("ipa文件路径:{0}".format(ipaPath))

        return ipaPath

     

    def UploadToFir(ipaPath):

        firApiToken = "XXXXX"

        publishResult = os.system("fir publish {0} -T {1}".format(ipaPath,firApiToken))

     

    def NewCodeBuild(app_name,version,bundle_id,profile_name,team_id,enviroment,debugFlag,server):

        CodeUpdate()

        ModifyInfoPlist(app_name,version)

        ModifyExportOptionsPlist(team_id,enviroment,bundle_id,profile_name)

        ModifyXcodeProject(bundle_id,profile_name,"iPhone Developer",team_id)

        ModifyLinkedServer(server)

        ModifyDebugBall(debugFlag)

        ipaPath = OutputIPA()

        UploadToFir(ipaPath)

     

    #-----------------------这是分割线,下面是入口函数-----------------------

    if __name__ == '__main__':

        

    #    App的名字

        app_name = "Pocket7Games"

    #    App的版本

        version = "1.3.1"

    #    App的标识符

        bundle_id = ""

    #    开发者账号的配置文件名

        profile_name = "Pocket7Test"

    #    开发者账号的ID,常用第一个(1)   (2)

        team_id = "XXXX"

    #    打包设置,常用development  (1)app-store   (2)ad-hoc   (3)enterprise   (4)development

        enviroment = "development"

    #    调试模式的小篮球开关 True False

        debugFlag = True

    #    服务端的服务器设置,参照脚本的18~21行去修改

        server = Server().test

        

    #   **下面是执行体,不要动!!!**

        NewCodeBuild(app_name,version,bundle_id,profile_name,team_id,enviroment,debugFlag,server)

        

    注:

    fir安装命令

    sudo gem install fir-cli

    展开全文
  • 使用Python进行Android自动化打包发布

    千次阅读 2017-11-06 08:50:45
    Python刚入门,都是一些基础用法。 下面代码中需要蒲公英的uKey和api_key,需要去蒲公英的文档中获取(https://www.pgyer.com/doc/api#uploadApp) # coding:utf-8 import os, sys, time, json# os.system("sh build...

    Python刚入门,都是一些基础用法。

    实现的功能包括,从git更新代码->修改apk名称->上传到蒲公英->获取蒲公英返回的二维码地址

    下面代码中需要蒲公英的uKey和api_key,需要去蒲公英的文档中获取(https://www.pgyer.com/doc/api#uploadApp)
    这里写图片描述

    # coding:utf-8
    import os, sys, time, json
    
    # os.system("sh buildApk.sh")
    
    apkdir = os.getcwd() + "/build/outputs/apk/"
    
    
    def gitpull():
        print "**************开始更新代码**************"
        log = os.system("git pull")
        print log
        print "**************代码更新完成**************"
        # log = os.system("git log")
        # print log
    
    
    def uploadApk(file):
        print "**************开始上传APK**************"
        uKey = "your uKey" #在这里填入蒲公英平台上的uKey
        _api_key = "your api_key" #在这里填入蒲公英平台上的api_key
        upload_cmd = "curl -F \"file=@" + file + "\" -F \"uKey=" + uKey + "\" -F \"_api_key=" + _api_key + "\" https://qiniu-storage.pgyer.com/apiv1/app/upload"
        print upload_cmd
        content = os.popen(upload_cmd).read()
        print "上传返回结果 -> " + content
        print "**************上传完成**************"
        return content
    
    
    def rename():
        currentTime = time.strftime("%Y%m%d%H%M%S", time.localtime())
        appname = "mes_debug_" + currentTime + ".apk"
        os.chdir(apkdir)
        os.system("ls")
        os.rename("app-debug.apk", appname)
        return appname
    
    
    def build():
        print "**************开始构建APK**************"
        currentTime = time.strftime("%Y%m%d%H%M%S", time.localtime())
        print "当前时间:" + currentTime
    
        os.system("gradle clean build")
        appname = rename()
        print "**************APK打包完成**************"
        upload_result = uploadApk(apkdir + appname)
    
        res = json.loads(upload_result.replace("\n", ""))
        appQRCodeURL = str(res['data']['appQRCodeURL'])
    
        print "**************二维码地址 —> " + appQRCodeURL
    
    
    def startBuildApk():
        gitpull()
        build()
    
    
    startBuildApk()
    

    有了自动打包脚本,下一步就可以集成到Jenkins上了。

    参考:
    http://www.jianshu.com/p/b66d72862517

    展开全文
  • Python实现iOS自动化打包详解

    千次阅读 2018-05-10 15:19:05
    点击上方“iOS开发”,选择“置顶公众号”关键时刻,第一时间送达!可能是最简单的iOS自动化打包方式:无需手动配置证书,无需填写配置文件名称,更无需配置Bundle Id...
  • 作为一名专职前端开发的我,为了帮助解决目前...在我学习过程中,一直琢磨着如何将学习的理论与我所掌握的知识结合起来,来解决或者处理实际问题,于是就有了 前端自动化打包部署 的念头。 尽快近几年,市面上关于...
  • Python selenium 自动化脚本打包成一个exe 准备内容: 1、xx.py源码文件 该源码文件在pychram中可运行成功 2、操作环境配置 使用pip工具进行安装pyinstaller,cmd命令行执行:pip install pyinstaller 成功后提示...
  • 本文要讲的内容是通过Jenkins进行Android项目的自动化打包,通过Jenkins运行Gradle编译出apk文件后通过Python脚本上传apk到蒲公英并且上传完成后发送通知邮件。环境:Windows10+Python3.6+Java1.
  • python自动化办公

    2020-05-04 23:41:44
    python自动化办公 Excel 我在B站看的视频中学习到的 python 中 openpyxl 库调用excel的例子,并对其中单元格做计算的例子,原视频有详细介绍可以点这个链接 python教程2019版,视频只有6小时但是足够入门了。 # 03:...
  • python自动化测试

    千次阅读 2018-08-07 20:12:05
    python自动化测试(3) 自动化框架及工具 1 概述 手续的关于测试的方法论,都是建立在之前的文章里面提到的观点: 功能测试不建议做自动化 接口测试性价比最高 接口测试可以做自动化 后面所谈到的 测试自动...
  • 首先让明确下分工:什么工作给python做、什么工作给C#做? 如果要做一个通用的工具,就必须在通用和不通用之间做一个平衡!...**我的初衷是要开发一个比较通用、可扩展性好的自动化打包工具。** ...
  • 2020暑期XX银行实习-一个自动化脚本 很多人学习python,不知道从何学起。 很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手。 很多已经做案例的人,却不知道如何去学习更加高深的知识。 那么针对这...
  • Python iOS 自动打包脚本(包含上传到fir)
  • 程序说明:本程序实现将开发程序服务器中的打包文件通过该脚本上传到正式生产环境(注:生产环境和开发环境不互通)程序基本思路:将开发环境中的程序包拷贝到本地堡垒机将程序包进行解压获得解压后的文件通同步到...
  • Python自动化完成tb喵币任务

    千次阅读 2019-11-03 16:27:37
    原创 Python自动化完成tb喵币任务 置顶 ...
  • python初学者,写了一个自动打开网页,操作浏览器的程序,打包发布时出了问题, 使用pyinstal打包,打成带目录结构的可以执行,打包成exe文件则报错,提示找不到动态链接库 求大神解答

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 41,119
精华内容 16,447
关键字:

python自动化打包

python 订阅