Ejemplo n.º 1
0
def action_make_encrypt_pyc(actparams):
    '''
    将pyc进行途游方式的加密处理,加密后必须使用途游的pypy-enc进行运行
    '''
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0
    service = params['service']

    # 加密处理
    if service['encodepyc']:
        mylog.log('加密运行处理')
        compilepath = service['paths']['bin']
        cmd = 'find %s -name "*.py" | xargs rm -fr' % (compilepath)
        status, output = commands.getstatusoutput(cmd)
        if status != 0:
            mylog.log('ERRROR !!', '加密模式,游戏工程py文件删除失败:', compilepath)
            mylog.log(status, output)
            return 0
        pycfiles = myfiles.find_py_files(compilepath, '.pyc', False)
        for pycfile in pycfiles:
            __tuyoo_enc_pyc_file__('%s/%s' % (compilepath, pycfile))
        mylog.log('加密运行处理完成')

    return 1
Ejemplo n.º 2
0
def action_push_bin(actparams):
    '''
    推动所有的编译输出文件到所有服务器,bin、script、webroot目录
    '''
    params = myhelper.action_common_init(actparams)
    if not params :
        return 0
    return push_dirs_to_all_server(params, '推送编译代码', DIR_ALL_MAKE)
Ejemplo n.º 3
0
def action_push_webroot(actparams):
    '''
    推送编译输出的wenroot目录到所有的服务器
    '''
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0
    return push_dirs_to_all_server(params, '推送WEB代码', DIR_MAKE_WEBROOT)
Ejemplo n.º 4
0
def action_push_configure(actparams):
    '''
    推送编译输出的游戏配置文件到所有服务器,script目录
    '''
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0
    return push_dirs_to_all_server(params, '推送配置代码', DIR_MAKE_SCRIPT)
Ejemplo n.º 5
0
def action_make_end(actparams):
    '''
    结束进行有写操作的make命令集合
    '''
    params = myhelper.action_common_init(actparams)
    if not params :
        return 0

    myhelper.save_last_output(params)
    return 1
Ejemplo n.º 6
0
def action_make_begin(actparams):
    '''
    开始进行有写操作的make命令集合
    '''
    params = myhelper.action_common_init(actparams)
    if not params :
        return 0
    params['_make_time_'] = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')

    return 1
Ejemplo n.º 7
0
def action_make_copy_source(actparams):
    '''
    拷贝源代码工程的etc、src、src-robot、webroot到编译输出目录,按照配置文件的工程列表进行顺序覆盖拷贝
    '''
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0
    service = params['service']

    # 创建所有的路径
    allpaths = service['paths']
    for mp in allpaths:
        if not myfiles.make_path(allpaths[mp]):
            return 0

    # 拷贝源文件到bin的install路径
    compilepath = service['paths']['bin']
    webroot = service['paths']['webroot']

    cpfpaths = ['%s/shscript' % (params['__pyscript_path__'])]
    cptpaths = [service['paths']['script'] + '/shscript']

    for proj in service['projects']:
        projpath = proj['path']
        cpfpaths.append('%s/etc' % (projpath))
        cpfpaths.append('%s/src' % (projpath))
        cpfpaths.append('%s/src-robot' % (projpath))
        cpfpaths.append('%s/webroot' % (projpath))

        cptpaths.append(compilepath)
        cptpaths.append(compilepath)
        cptpaths.append(compilepath)
        cptpaths.append(webroot)

    if not myfiles.link_files_all(cpfpaths, cptpaths):
        return 0
    if service['corporation'] == 'momo':
        myfiles.delete_path(webroot + '/8')
        myfiles.delete_path(webroot + '/block')
        myfiles.delete_path(webroot + '/chinesechess')
        myfiles.delete_path(webroot + '/dizhu')
        myfiles.delete_path(webroot + '/dizhu2')
        myfiles.delete_path(webroot + '/douniu')
        myfiles.delete_path(webroot + '/douniu2')
        myfiles.delete_path(webroot + '/gomoku')
        myfiles.delete_path(webroot + '/scmahjong')
        myfiles.delete_path(webroot + '/scmahjong2')
        myfiles.delete_path(webroot + '/sdk')
        myfiles.delete_path(webroot + '/t3card2')
        myfiles.delete_path(webroot + '/t3flush')
        myfiles.delete_path(webroot + '/texas')
        myfiles.delete_path(webroot + '/hall6')

    return 1
Ejemplo n.º 8
0
def action_make_webroot(actparams):
    '''
    压缩处理当前的编译输出路径的webroot中的js、html文件
    '''
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0

    # 压缩webroot
    __mini_webroot__(params)

    return 1
Ejemplo n.º 9
0
def action_clean_all(actparams):
    '''
    清空运行期的所有目录log、bireport
    '''
    mylog.log(mylog.wrap_color_cyan('清除所有机器的编译、日志内容'))
    params = myhelper.action_common_init(actparams)
    if not params :
        return 0

    haserror = mutil_thread_server_action(params, thread_action_clean_all)
    if haserror :
        mylog.error('清除所有机器的编译、日志内容失败 !!')
        return 0

    mylog.log(mylog.wrap_color_cyan('清除所有机器的编译、日志内容完成'))
    return 1
Ejemplo n.º 10
0
def action_backup(actparams):
    '''
    备份当前的所有内容、工程文件、编译输出文件,测试模式不进行任何备份
    '''
    mylog.log('备份全部代码')
    params = myhelper.action_common_init(actparams, True)
    if not params :
        mylog.log('找不到上次的编译结果,无法备份')
        return 1
    
    backfile = tar_gzip_folders(params, PACK_TYPE_TAR_GZIP, DIR_ALL)
    if not backfile :
        mylog.error('备份失败')
        return 0
    mylog.log('备份成功')
    return 1
Ejemplo n.º 11
0
def action_stop(actparams):
    '''
    服务整体全部停止服务
    '''
    mylog.log(mylog.wrap_color_cyan('开始停止服务'))
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0

    haserror = mutil_thread_server_action(params, thread_action_stop)
    if haserror:
        mylog.error('停止服务失败 !!')
        return 0

    mylog.log('停止服务完成')
    return 1
Ejemplo n.º 12
0
def action_clean_log(actparams):
    '''
    清空运行期的所有目录log、bireport
    '''
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0

    service = params['service']
    allpaths = [
        service['paths']['log'],
        service['paths']['bireport'],
    ]
    for mp in allpaths:
        if not myfiles.delete_path(mp):
            return 0
    return 1
Ejemplo n.º 13
0
def action_clean_bin(actparams):
    '''
    清空编译输出的所有目录bin、script、webroot
    '''
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0

    service = params['service']
    allpaths = [
        service['paths']['bin'],
        service['paths']['script'],
        #                 service['paths']['webroot'],
        service['paths']['hotfix'],
    ]
    for mp in allpaths:
        if not myfiles.delete_path(mp):
            return 0
    return 1
Ejemplo n.º 14
0
def action_make_copy_webroot(actparams):
    '''
    拷贝源代码工程的webroot到编译输出目录,按照配置文件的工程列表进行顺序覆盖拷贝
    '''
    params = myhelper.action_common_init(actparams)
    if not params :
        return 0
    service = params['service']

    # 创建所有的路径
    webroot = service['paths']['webroot']
    if not myfiles.make_path(webroot) :
        return 0

    # 拷贝源文件到bin的install路径
    cpfpaths = []
    cptpaths = []
    for proj in service['projects'] :
        projpath = proj['path']
        cpfpaths.append('%s/webroot' % (projpath))
        cptpaths.append(webroot)

    if not myfiles.copy_files_all(cpfpaths, cptpaths) :
        return 0

    if service['corporation'] == 'momo' :
        myfiles.delete_path(webroot + '/8')
        myfiles.delete_path(webroot + '/block')
        myfiles.delete_path(webroot + '/chinesechess')
        myfiles.delete_path(webroot + '/dizhu')
        myfiles.delete_path(webroot + '/dizhu2')
        myfiles.delete_path(webroot + '/douniu')
        myfiles.delete_path(webroot + '/douniu2')
        myfiles.delete_path(webroot + '/gomoku')
        myfiles.delete_path(webroot + '/scmahjong')
        myfiles.delete_path(webroot + '/scmahjong2')
        myfiles.delete_path(webroot + '/sdk')
        myfiles.delete_path(webroot + '/t3card2')
        myfiles.delete_path(webroot + '/t3flush')
        myfiles.delete_path(webroot + '/texas')
        myfiles.delete_path(webroot + '/hall6')
    
    return 1
Ejemplo n.º 15
0
def execute_hot_cmd(actparams, act_name, hotcmd_params):

    mylog.log('开始' + act_name)
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0

    service = params['service']
    script = service['_script_hotcmd_']
    status, outputs = exec_index_script_on_first_server(
        params, script, hotcmd_params)
    if status != 0:
        mylog.error(act_name + '失败')
        mylog.error(outputs)
        return 0

    datas = get_status_json_datas(outputs)

    if datas.get('result', -1) != 0:
        mylog.log(act_name + '失败')
        mylog.error(outputs)
        return 0

    iserror = 0
    process = datas.get('process')
    if isinstance(process, dict):
        for prockey, presult in process.items():
            result = presult.get('result', {})
            ok = result.get('ok', 0)
            if ok != 1:
                iserror = 1
                mylog.error(prockey, result, presult.get('error', {}))
            else:
                mylog.log(prockey, result)

    if iserror:
        mylog.log(act_name + '失败')
        return 0

    mylog.log(act_name + '成功')
    return 1
Ejemplo n.º 16
0
def action_start(actparams):
    '''
    服务整体全部重新启动
    '''
    mylog.log('准备启动服务')
    params = myhelper.action_common_init(actparams)
    if not params :
        return 0
    
    if __action_start_clean_status__(params) :
        return 0

    mylog.log(mylog.wrap_color_cyan('开始启动服务'))

    haserror = mutil_thread_server_action(params, __thread_action_start__)
    if haserror :
        mylog.error('启动服务失败 !!')
        return 0

    mylog.log('启动服务完成')
    return 1
Ejemplo n.º 17
0
def action_make_compile_pyc(actparams):
    '''
    预编译所有的py文件到pyc,以便发现语法错误
    '''
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0
    service = params['service']

    # 编译文件
    mylog.log('开始预编译PY文件')
    compilepath = service['paths']['bin']

    makesosh = myfiles.find_py_files(compilepath, 'makeso.sh')
    for msh in makesosh:
        cmd = 'sh %s/%s' % (compilepath, msh)
        mylog.log('编译SO文件 :', msh)
        status, output = commands.getstatusoutput(cmd)
        if status != 0:
            mylog.log('ERRROR !!', '工程so文件编译失败:', compilepath)
            mylog.log(output)
            return 0

    mylog.log('编译PY文件 :', compilepath)
    pyfiles = myfiles.find_py_files(compilepath, '.py', True)
    content = '\n'.join(pyfiles)
    # 生成编译文件
    cfilepath = '%s/c.py' % (compilepath)
    myfiles.write_file('', cfilepath, content)

    pypy = myhelper.get_env('PYPY_COMPILE', service['pypy'])
    cmd = 'export PYTHONPATH=%s; %s -tt %s' % (compilepath, pypy, cfilepath)
    status, output = commands.getstatusoutput(cmd)
    if status != 0:
        mylog.log('ERRROR !!', '工程py文件编译失败:', compilepath)
        mylog.log(output)
        return 0
    commands.getstatusoutput('rm -fr ' + cfilepath)
    mylog.log('预编译PY文件成功!')
    return 1
Ejemplo n.º 18
0
def action_make_script(actparams):
    '''
    生成所有的进程启动脚本
    '''
    params = myhelper.action_common_init(actparams)
    if not params :
        return 0
    service = params['service']
    # 生成启动脚本

    process = service['process']
    srvids = {}
    for proc in process :
        if not proc['server'] in srvids :
            srvids[proc['server']] = []
        srvids[proc['server']].append(proc)

    servermap = {}
    servers = service['servers']
    for srv in servers :
        servermap[srv['id']] = srv
    
    allprocids = []
    for srvid in srvids :
        server = servermap[srvid]
        process = srvids[srvid]
        servershnames = []
        serverprocid = []
        if not __make_output_script__(params, service, server, process, servershnames, serverprocid) :
            return 0
        server['_scripts_'] = servershnames
        server['_procids_'] = serverprocid
        allprocids.extend(serverprocid)

    service['_allprocids_'] = allprocids
    commands.getoutput('chmod -R +x %s/*' % (service['paths']['script']))

    return 1
Ejemplo n.º 19
0
def action_hotfix(actparams):
    '''
    推送hotfix目录下的所有文件到各个服务器,并在各个服务器执行给出的文件
    '''
    mylog.log('准备HOTFIX')
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0
    service = params['service']

    # 创建所有的路径
    hotfixdir = service['paths']['hotfix']
    if not myfiles.make_path(hotfixdir):
        return 0

    # 拷贝源文件到bin的install路径
    cpfpaths = []
    cptpaths = []
    for proj in service['projects']:
        projpath = proj['path']
        cpfpaths.append('%s/hotfix' % (projpath))
        cptpaths.append(hotfixdir)

    if not myfiles.copy_files_all(cpfpaths, cptpaths):
        return 0

    hotfixpy = actparams['hotfix']
    hotfixpy = hotfixdir + '/' + hotfixpy
    if not myfiles.file_exists(hotfixpy):
        mylog.error('没有找到HOTFIX文件', hotfixpy)
        return 0

    if not push_dirs_to_all_server(params, '推送HOTFIX代码', DIR_HOTFIX):
        return 0

    return execute_hot_cmd(actparams, 'HOTFIX', 'exec_hotfix_py ' + hotfixpy)
Ejemplo n.º 20
0
def action_make_configure(actparams, pypath=None):
    '''
    读取本地当前的配置文件内容,生成配置JSON文件,生成配置装载的脚本
    '''
    params = myhelper.action_common_init(actparams)
    if not params:
        return 0

    service = params['service']

    # 每次执行配置文件时,使用__service__.json和__outputs__.json进行数据交换
    compilepath = service['paths']['bin']
    sfile = compilepath + '/__service__.json'
    myfiles.write_file('', sfile, json.dumps(service))

    ofile = compilepath + '/__outputs__.json'
    myfiles.write_file('', ofile, json.dumps({}))

    i = 1
    mcount = len(service['projects']) * 2
    for proj in service['projects']:
        pyfile = proj['configure_py']
        mylog.log('装载游戏配置 [%d/%d] :' % (i, mcount), pyfile)
        i += 1
        basepy = myfiles.get_parent_dir(service['projects'][0]['configure_py'])
        if not __execute_game_config_py__(service, basepy, pyfile, sfile,
                                          ofile, pypath):
            return 0

        pyfile = proj['configure_json']
        mylog.log('装载游戏配置 [%d/%d] :' % (i, mcount), pyfile)
        i += 1
        basepy = myfiles.get_parent_dir(
            service['projects'][0]['configure_json'])
        if not __execute_game_config_py__(service, basepy, pyfile, sfile,
                                          ofile, pypath):
            return 0

    patchpy = myfiles.get_parent_dir(compilepath) + '/patch_config.py'
    if myfiles.file_exists(patchpy):
        cmd = 'pypy ' + patchpy + ' ' + ofile
        mylog.log('执行游戏配置文件补丁:', cmd)
        status, output = commands.getstatusoutput(cmd)
        for l in output.split('\n'):
            mylog.log(l)
        if status != 0:
            mylog.error('游戏配置文件补丁失败:', patchpy)
            mylog.error(status, output)
            return 0

    outputs = myfiles.read_json_file(ofile)
    cmdlist = []
    configuredatas = outputs.get('configuredatas', {})
    for k, v in configuredatas.items():
        cmdlist.append(['set', k, v])

    if not __write_redis_config_script__(params, service, cmdlist):
        return 0

    commands.getstatusoutput('rm -fr ' + sfile)
    commands.getstatusoutput('rm -fr ' + ofile)
    return 1