def main(args):
    global cf,rsync_conf    
    cf = ConfigParser.ConfigParser()    
    ABSPATH=os.path.abspath(sys.argv[0])
    #conf 路径
    rsync_conf=os.path.dirname(ABSPATH)+"/rsync.conf"
    cf.read(rsync_conf)
    ############变量区域###########    
    #当前时间格式2016-01-06_13-36
    nowtime = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")
    #参数解析
    option,args = parser_command()    
    #备份路径
    backup_path = "/data/backup/%s/%s/%s"%(option.platform,option.os,nowtime)
    #创建备份目录
    mkdir_p(backup_path)

    test_port = cf.getint("test","port")
    test_ip  = cf.get("test","server")
    #update存放在测试服上的位置
    client_dir = cf.get("test","client_dir") 
    #rsync信息
    cdn_server =  cf.get(option.platform,"server")
    cdn_user = cf.get(option.platform,"user")
    #test_passfile 是代表测试服务器存在pass的路径,后续与163进行统一存放
    cdn_pass_file = cf.get(option.platform,"passfile")
    cdn_dir = cf.get(option.platform,"dir")
    cdn_url = cf.get(option.platform,"url")
    lang = cf.get(option.platform,"lang")
    #需要备份的update url
    back_update = cf.get(option.platform,"back_channel_%s"%option.os)
    if not back_update:back_update="update_%s_%s.xml"%(lang,option.os)
    back_update_url = cdn_url + "/" + option.os +"/" + back_update
    #备份
    down_xml(backup_path,back_update_url,verbose=option.verbose)
    #连接测试服
    try:
        SSH = ssh(host=test_ip,port=test_port)
        if option.platform == "qq":
            update_xml = "update_000028.xml update_000184.xml"
            local_file_path = client_dir + update_xml
            #存放cdn 目录
            Rsync_file(cdn_pass_file,cdn_user,cdn_dir,cdn_server,local_file_path,option.os,sshconnect=SSH,verbose=option.verbose)
        elif option.single_file: 
            local_file_path = client_dir + option.single_file
            Rsync_file(cdn_pass_file,cdn_user,cdn_dir,cdn_server,local_file_path,option.os,sshconnect=SSH,verbose=option.verbose)
        else:
            #排除一些文件
            local_file_path = client_dir + "*"
            #如果要排除一些文件,使用下面的格式,exclue_file=excule_xml
            excule_xml =[ e for e in cf.get(option.platform,"exclude_update").split(",")]
            if len(excule_xml) == 0 or excule_xml[0] == "":
                excule_xml=None
            Rsync_file(cdn_pass_file,cdn_user,cdn_dir,cdn_server,local_file_path,option.os,sshconnect=SSH,exclue_file=excule_xml,verbose=option.verbose)
 
    except KeyboardInterrupt:
        warn("程序被强行停止!!") 
    except Exception,err:
        error(err) 
def main(args):
    try:
        global cf,rsync_conf    
        cf = ConfigParser.ConfigParser()    
        ABSPATH=os.path.abspath(sys.argv[0])
        #conf 路径
        rsync_conf=os.path.dirname(ABSPATH)+"/rsync.conf"
        #列表路径
        server_list_path = os.path.dirname(os.path.dirname(ABSPATH)) + "/dzmo-client/server_list"
        mkdir_p(server_list_path)
        ##########################################  清空server_list目录 ##########################################
        os.popen("rm -rf %s/*"%server_list_path)
        cf.read(rsync_conf)
        #参数解析
        option,args = parser_command()
        #测试模式
        if option.test:
            Test = "true"
        else:
            Test = "false"
        if option.verbose:
            verbose = True
        else:
            verbose = False
        #排除选服xml
        exclude_str=None
        if option.exclude:  
            exclude_str="" 
            x=lambda tables: ["server_list_%s.xml"%t for t in tables.split(",")]
            exclude_str=x(option.exclude)

        #包含的xml
        clude_str=None
        if option.clude:
            clude_str=""
            for c in option.clude.split(","):
                c = "server_list_%s.xml"%c
                clude_str = clude_str + " " + c

        cdn_server = cf.get(option.platform,"server")
        cdn_user = cf.get(option.platform,"user")
        passfile = cf.get(option.platform,"passfile")  
        file_list = cf.get(option.platform,"file_list")
        cdn_dir = cf.get(option.platform,"dir")
        #目前H2没有other 这里暂时保留
        if option.platform == "tszn":
            file_list_url = "%s?os=%s&test=%s&other=%s"%(file_list,option.os,Test,option.platform)
        else:
            file_list_url = "%s?os=%s&test=%s&other="%(file_list,option.os,Test)
            #print file_list_url
        #下载server_list
        ##########################################  第一步 下载 server_list  ##########################################
        #print file_list_url
        down_all_server_list(server_list_path,file_list_url)
        #同步到cdn
        ##########################################  第二步 同步 server_list  ##########################################
        if clude_str:
            local_file_path = server_list_path + "/" + clude_str
        else:
            local_file_path = server_list_path + "/*"   
        sub_dir = option.os + "/server_list/" + option.version + "/"
        Rsync_file(passfile,cdn_user,cdn_dir,cdn_server,local_file_path,sub_dir,exclue_file=exclude_str,verbose=verbose)
        #cdn刷新
        if option.platform == "xmzh":
            for root,dirs,files in os.walk(server_list_path):
                for f in files:
                    url = "http://file.i2igame.com/devilprincess/android/server_list/%s/%s"%(option.version,f)
                    curl='''https://api.ccu.akamai.com/ccu/v2/queues/default -H "Content-Type:application/json" -d '{"objects" : ["%s"]}' -u [email protected]:"haoyue612"'''%url
                    cmd = "curl %s"%curl
                    #print cmd
                    run = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
                    stdout,stderr = run.communicate()
                    if run.returncode != 0:
                        print stderr,stdout
                    else:
                        if eval(stdout)["httpStatus"] == 201:
                            success("/%s/%s 刷新成功..."%(option.version,f))

        #pass
    except IOError,err:
        warn(err)
Ejemplo n.º 3
0
def main(args):
    try:
        global cf, rsync_conf
        cf = ConfigParser.ConfigParser()
        ABSPATH = os.path.abspath(sys.argv[0])
        #conf 路径
        rsync_conf = os.path.dirname(ABSPATH) + "/rsync.conf"
        #列表路径
        server_list_path = os.path.dirname(
            os.path.dirname(ABSPATH)) + "/dzmo-client/server_list"
        mkdir_p(server_list_path)
        ##########################################  清空server_list目录 ##########################################
        os.popen("rm -rf %s/*" % server_list_path)
        cf.read(rsync_conf)
        #参数解析
        option, args = parser_command()
        #测试模式
        if option.test:
            Test = "true"
        else:
            Test = "false"
        if option.verbose:
            verbose = True
        else:
            verbose = False
        #排除选服xml
        exclude_str = None
        if option.exclude:
            exclude_str = ""
            x = lambda tables: [
                "server_list_%s.xml" % t for t in tables.split(",")
            ]
            exclude_str = x(option.exclude)

        #包含的xml
        clude_str = None
        if option.clude:
            clude_str = ""
            for c in option.clude.split(","):
                c = "server_list_%s.xml" % c
                clude_str = clude_str + " " + c

        cdn_server = cf.get(option.platform, "server")
        cdn_user = cf.get(option.platform, "user")
        passfile = cf.get(option.platform, "passfile")
        file_list = cf.get(option.platform, "file_list")
        cdn_dir = cf.get(option.platform, "dir")
        #目前H2没有other 这里暂时保留
        if option.platform == "tszn":
            file_list_url = "%s?os=%s&test=%s&other=%s" % (
                file_list, option.os, Test, option.platform)
        else:
            file_list_url = "%s?os=%s&test=%s&other=" % (file_list, option.os,
                                                         Test)
            #print file_list_url
        #下载server_list
        ##########################################  第一步 下载 server_list  ##########################################
        #print file_list_url
        down_all_server_list(server_list_path, file_list_url)
        #同步到cdn
        ##########################################  第二步 同步 server_list  ##########################################
        if clude_str:
            local_file_path = server_list_path + "/" + clude_str
        else:
            local_file_path = server_list_path + "/*"
        sub_dir = option.os + "/server_list/" + option.version + "/"
        Rsync_file(passfile,
                   cdn_user,
                   cdn_dir,
                   cdn_server,
                   local_file_path,
                   sub_dir,
                   exclue_file=exclude_str,
                   verbose=verbose)
        #cdn刷新
        if option.platform == "xmzh":
            for root, dirs, files in os.walk(server_list_path):
                for f in files:
                    url = "http://file.i2igame.com/devilprincess/android/server_list/%s/%s" % (
                        option.version, f)
                    curl = '''https://api.ccu.akamai.com/ccu/v2/queues/default -H "Content-Type:application/json" -d '{"objects" : ["%s"]}' -u [email protected]:"haoyue612"''' % url
                    cmd = "curl %s" % curl
                    #print cmd
                    run = subprocess.Popen(cmd,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE,
                                           shell=True)
                    stdout, stderr = run.communicate()
                    if run.returncode != 0:
                        print stderr, stdout
                    else:
                        if eval(stdout)["httpStatus"] == 201:
                            success("/%s/%s 刷新成功..." % (option.version, f))

        #pass
    except IOError, err:
        warn(err)