Exemplo n.º 1
0
def save_action_history(options, action):
    actlistcond.acquire()
    try:
        fpath = fsutils.appendPath(options.logpath, 'action.' + action['uuid'] + '.json')
        fsutils.writeFile('', fpath, action)
    finally:
        actlistcond.release()
Exemplo n.º 2
0
def save_action_history(options, action):
    actlistcond.acquire()
    try:
        fpath = fsutils.appendPath(options.logpath,
                                   'action.' + action['uuid'] + '.json')
        fsutils.writeFile('', fpath, action)
    finally:
        actlistcond.release()
Exemplo n.º 3
0
def make_static_json_file(options, alldata):
    confs = {}
    _load_decorations(options, confs, alldata)
    _load_activity(options, confs, alldata)
    _load_gamelist2(options, confs, alldata)
    webroot = options.env['webroot_path'] + '/static_file/'
    staticjson = webroot + 'static.json'
    if not fsutils.dirExists(webroot):
        fsutils.makeDirs(webroot)
    fsutils.writeFile('', staticjson, confs)
    _remake_static_zip(options, confs, alldata)
    return 1
Exemplo n.º 4
0
def make_static_json_file(options, alldata):
    confs = {}
    _load_decorations(options, confs, alldata)
    _load_activity(options, confs, alldata)
    _load_gamelist2(options, confs, alldata)
    webroot = options.env['webroot_path'] + '/static_file/'
    staticjson = webroot + 'static.json'
    if not fsutils.dirExists(webroot) :
        fsutils.makeDirs(webroot)
    fsutils.writeFile('', staticjson, confs)
    _remake_static_zip(options, confs, alldata)
    return 1
Exemplo n.º 5
0
def action(options):
    '''
    生成所有的进程启动脚本
    '''
    bin_path = options.env['bin_path']
    config_redis = options.pokerdict.get('local_config_redis',
                                         options.pokerdict['config_redis'])
    remotepy = loadResource('remote.py')
    remotepy = remotepy.replace('${TIME}', str(datetime.now()))
    remotepy = remotepy.replace('${BIN_PATH}', bin_path)
    remotepy = remotepy.replace('${LOG_PATH}', options.env['log_path'])
    remotepy = remotepy.replace('${REDIS_CONFIG}', config_redis)

    cfilepath = fsutils.appendPath(bin_path, 'remote.py')
    fsutils.writeFile('', cfilepath, remotepy)

    if options.pokerdict['mode'] <= 2:
        sendmail = '1'
    else:
        sendmail = '0'

    while1sh = loadResource('while1.sh')
    while1sh = while1sh.replace('${SENDMAIL}', sendmail)
    while1sh = while1sh.replace('${BIN_PATH}', bin_path)
    while1sh = while1sh.replace('${LOG_PATH}', options.env['log_path'])

    if os.environ.get('RUN_IN_DOCKER', 0):
        # 在开发docker模式下,设置PYTHONPATH环境变量
        paths = []
        for proj in options.projectlist:
            src = fsutils.appendPath(proj['path'], 'src')
            if fsutils.dirExists(src):
                paths.append(src)
            else:
                src = fsutils.appendPath(proj['path'], 'freetime')
                if fsutils.dirExists(src):
                    paths.append(proj['path'])
        paths.reverse()
        paths = ':'.join(paths)
        while1sh = while1sh.replace('${DOCKER_PROJECT_PATH}', paths)
        actlog.log('makeControlInDocker PYTHONPATH=', paths)

    shfile = fsutils.appendPath(bin_path, 'while1.sh')
    fsutils.writeFile('', shfile, while1sh)
    os.chmod(shfile, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

    return 1
Exemplo n.º 6
0
def action(options):
    '''
    生成所有的进程启动脚本
    '''
    bin_path = options.env['bin_path']
    config_redis = options.pokerdict.get('local_config_redis', options.pokerdict['config_redis'])
    remotepy = loadResource('remote.py')
    remotepy = remotepy.replace('${TIME}', str(datetime.now()))
    remotepy = remotepy.replace('${BIN_PATH}', bin_path)
    remotepy = remotepy.replace('${LOG_PATH}', options.env['log_path'])
    remotepy = remotepy.replace('${REDIS_CONFIG}', config_redis)

    cfilepath = fsutils.appendPath(bin_path, 'remote.py')
    fsutils.writeFile('', cfilepath, remotepy)

    if options.pokerdict['mode'] <= 2 :
        sendmail = '1'
    else:
        sendmail = '0'

    while1sh = loadResource('while1.sh')
    while1sh = while1sh.replace('${SENDMAIL}', sendmail)
    while1sh = while1sh.replace('${BIN_PATH}', bin_path)
    while1sh = while1sh.replace('${LOG_PATH}', options.env['log_path'])

    if os.environ.get('RUN_IN_DOCKER', 0):
        # 在开发docker模式下,设置PYTHONPATH环境变量
        paths = []
        for proj in options.projectlist:
            src = fsutils.appendPath(proj['path'], 'src')
            if fsutils.dirExists(src):
                paths.append(src)
            else:
                src = fsutils.appendPath(proj['path'], 'freetime')
                if fsutils.dirExists(src):
                    paths.append(proj['path'])
        paths.reverse()
        paths = ':'.join(paths)
        while1sh = while1sh.replace('${DOCKER_PROJECT_PATH}', paths)
        actlog.log('makeControlInDocker PYTHONPATH=', paths)

    shfile = fsutils.appendPath(bin_path, 'while1.sh')
    fsutils.writeFile('', shfile, while1sh)
    os.chmod(shfile, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

    return 1
Exemplo n.º 7
0
    def do_http_set_json_file(self, jsonfile, jsondata):
        jfile = fsutils.appendPath(self.options.pokerpath, jsonfile)
        jsondata = json.dumps(jsondata,
                              indent=2,
                              separators=(', ', ' : '),
                              sort_keys=True,
                              ensure_ascii=False)
        lines = jsondata.split('\n')
        for x in xrange(len(lines)):
            lines[x] = lines[x].rstrip()
        jsondata = '\n'.join(lines)

        fsutils.writeFile('', jfile, jsondata)
        datas = fsutils.readJsonFile(jfile)
        mo = MsgPack()
        mo.setCmd('json_file_data')
        mo.setResult('jsonfile', jsonfile)
        mo.setResult('datas', datas)
        return mo
Exemplo n.º 8
0
def action(options):
    """
    预编译所有的py文件到pyc,以便发现语法错误
    """
    if os.environ.get('RUN_IN_DOCKER', 0):
        # 在开发docker模式下,webroot为link模式,无需拷贝
        if not makeSoInDocker(options):
            return 0
        actlog.log('docker mode skip compiler pyc !')
        return 1

    # 编译SO文件
    bin_path = options.env['bin_path']
    # LINUX WIN32
    if platform.system() == 'Darwin':
        makesosh = [
            os.path.join('freetime', 'core', 'cffi', 'makeso.sh'),
            os.path.join('poker', 'util', 'cffi', 'makeso.sh'),
        ]
    elif platform.system() == 'Windows':
        _, makesosh = fsutils.findTreeFiles(
            bin_path, ['.*' + os.path.sep + '(makeso.cmd)$'], ['.*\\.svn.*'])
    else:
        _, makesosh = fsutils.findTreeFiles(
            bin_path, ['.*' + os.path.sep + '(makeso.sh)$'], ['.*\\.svn.*'])

    if len(makesosh) == 0:
        actlog.log('run C/C++ compiler   : not found !!')

    for msh in makesosh:
        cmd = bin_path + os.path.sep + msh
        os.chmod(cmd, stat.S_IRWXU | stat.S_IRWXG)
        actlog.log('run C/C++ compiler   :', msh)
        status, output = commands.getstatusoutput(cmd)
        if status != 0:
            actlog.log('C/C++ compiler ERROR !!', cmd)
            actlog.log(output)
            return 0

    # 只有再Linux运行环境下才进行预编译
    if platform.system() != 'Linux':
        return 1

    # 生成编译文件
    pkgs = []
    pyfiles = options._pyfiles
    for pyf in pyfiles:
        if pyf.endswith('.py') and pyf.find('hotfix') < 0:
            pkg = '    import ' + '.'.join(pyf.split(os.path.sep)[1:])
            pkg = pkg[0:-3]
            if pkg.endswith('__init__'):
                pkg = pkg[0:-9]
            pkgs.append(pkg)
    content = '''
# -*- coding: utf-8 -*-
# author time : %s
import sys
from twisted.internet import reactor # 确保reactor第一时间初始化, 否则可能莫名其妙的crash
if sys.getdefaultencoding().lower() != 'utf-8' :
    reload(sys)
    sys.setdefaultencoding("utf-8")
try:
%s
except:
    print sys.path
    raise
''' % (str(datetime.now()), '\n'.join(pkgs))
    cfilepath = bin_path + os.path.sep + '_compiler.py'
    fsutils.writeFile('', cfilepath, content)

    actlog.log('run PYPY  compiler   :', cfilepath)
    pypy = strutil.getEnv('PYPY', 'pypy')
    cmd = '%s -tt %s' % (pypy, cfilepath)
    status, output = commands.getstatusoutput(cmd)
    if status != 0:
        actlog.log('ERROR !!', 'compile py files false !', status, cfilepath)

        lines = output.split('\n')
        for line in lines:
            actlog.log(line)
        return 0
    else:
        # fsutils.deleteFile(cfilepath)
        for pyf in pyfiles:
            if pyf.endswith('.py'):
                f = bin_path + os.path.sep + pyf + 'c'
                if fsutils.fileExists(f):
                    fsutils.deleteFile(f)

    return 1
Exemplo n.º 9
0
def action(options):
    '''
    装载并检测服务启动配置文件
    '''
    alldata = {}
    setattr(options, 'alldata', alldata)

    actlog.log('options.poker_path->', options.poker_path)
    checkprojects = options.checkprojects
    loadsprojs = set()
    datas, allGameIds = load_project_datas_all(options.poker_path + '/game/',
                                               options)
    alldata.update(datas)
    for cproj in checkprojects:
        projectdir = fsutils.appendPath(options.poker_path, cproj)
        loadsprojs.add(projectdir)
        datas = load_project_datas_room(projectdir, options)
        alldata.update(datas)
    allGameIds.sort()
    options.pokerdict['config.game.ids'] = allGameIds
    actlog.log('config.game.ids->', allGameIds)
    alldata['poker:map.activityid'] = readJsonData(
        options.poker_path + '/poker/map.activityid.json', options)
    alldata['poker:map.bieventid'] = readJsonData(
        options.poker_path + '/poker/map.bieventid.json', options)
    alldata['poker:map.giftid'] = readJsonData(
        options.poker_path + '/poker/map.giftid.json', options)

    # 重gdss获取数据
    ret = _syncDataFromGdss(options, 'poker:map.clientid', dict,
                            'getClientIdDict')
    if not ret:
        return ret

    ret = _syncDataFromGdss(options, 'poker:map.productid', dict,
                            'getProductIdDict')
    if not ret:
        return ret

    ret = make_static_json.make_static_json_file(options, alldata)
    if not ret:
        return ret

    outpath = options.pokerdict['output_path']
    fsutils.writeFile(outpath, 'out.redis.json', alldata)
    fsutils.writeFile(outpath, 'out.poker.global.json', options.pokerdict)
    fsutils.writeFile(options.poker_path, '._confdata_.json', alldata)

    patchpy = os.path.dirname(outpath) + '/patch_config.py'
    if os.path.isfile(patchpy):
        cmd = 'pypy ' + patchpy + ' ' + outpath
        actlog.log('执行游戏配置文件补丁:', cmd)
        status, output = commands.getstatusoutput(cmd)
        for l in output.split('\n'):
            actlog.log(l)
        if status != 0:
            actlog.error('游戏配置文件补丁失败:', patchpy)
            actlog.error(status, output)
            return 0
        if output and output.find('REMAKE_STATIC') >= 0:
            actlog.log('find REMAKE_STATIC !')
            alldata = json.loads(filterComment(outpath + '/out.redis.json'))
            ret = make_static_json.make_static_json_file(options, alldata)
            if not ret:
                return ret
            fsutils.writeFile(outpath, 'out.redis.json', alldata)
            fsutils.writeFile(options.poker_path, '._confdata_.json', alldata)
    return 1
Exemplo n.º 10
0
def action(options):
    '''
    装载并检测服务启动配置文件
    '''
    alldata = {}
    setattr(options, 'alldata', alldata)

    actlog.log('options.poker_path->', options.poker_path)
    checkprojects = options.checkprojects
    loadsprojs = set()
    datas, allGameIds = load_project_datas_all(options.poker_path + '/game/', options)
    alldata.update(datas)
    for cproj in checkprojects:
        projectdir = fsutils.appendPath(options.poker_path, cproj)
        loadsprojs.add(projectdir)
        datas = load_project_datas_room(projectdir, options)
        alldata.update(datas)
    allGameIds.sort()
    options.pokerdict['config.game.ids'] = allGameIds
    actlog.log('config.game.ids->', allGameIds)
    alldata['poker:map.activityid'] = readJsonData(options.poker_path + '/poker/map.activityid.json', options)
    alldata['poker:map.bieventid'] = readJsonData(options.poker_path + '/poker/map.bieventid.json', options)
    alldata['poker:map.giftid'] = readJsonData(options.poker_path + '/poker/map.giftid.json', options)

    # 重gdss获取数据
    ret = _syncDataFromGdss(options, 'poker:map.clientid', dict, 'getClientIdDict')
    if not ret:
        return ret

    ret = _syncDataFromGdss(options, 'poker:map.productid', dict, 'getProductIdDict')
    if not ret:
        return ret

    ret = make_static_json.make_static_json_file(options, alldata)
    if not ret:
        return ret

    outpath = options.pokerdict['output_path']
    fsutils.writeFile(outpath, 'out.redis.json', alldata)
    fsutils.writeFile(outpath, 'out.poker.global.json', options.pokerdict)
    fsutils.writeFile(options.poker_path, '._confdata_.json', alldata)

    patchpy = os.path.dirname(outpath) + '/patch_config.py'
    if os.path.isfile(patchpy):
        cmd = 'pypy ' + patchpy + ' ' + outpath
        actlog.log('执行游戏配置文件补丁:', cmd)
        status, output = commands.getstatusoutput(cmd)
        for l in output.split('\n'):
            actlog.log(l)
        if status != 0:
            actlog.error('游戏配置文件补丁失败:', patchpy)
            actlog.error(status, output)
            return 0
        if output and output.find('REMAKE_STATIC') >= 0:
            actlog.log('find REMAKE_STATIC !')
            alldata = json.loads(filterComment(outpath + '/out.redis.json'))
            ret = make_static_json.make_static_json_file(options, alldata)
            if not ret:
                return ret
            fsutils.writeFile(outpath, 'out.redis.json', alldata)
            fsutils.writeFile(options.poker_path, '._confdata_.json', alldata)
    return 1
Exemplo n.º 11
0
def action(options):
    """
    预编译所有的py文件到pyc,以便发现语法错误
    """
    if os.environ.get('RUN_IN_DOCKER', 0):
        # 在开发docker模式下,webroot为link模式,无需拷贝
        if not makeSoInDocker(options):
            return 0
        actlog.log('docker mode skip compiler pyc !')
        return 1

    # 编译SO文件
    bin_path = options.env['bin_path']
    # LINUX WIN32
    if platform.system() == 'Darwin':
        makesosh = [
            os.path.join('freetime', 'core', 'cffi', 'makeso.sh'),
            os.path.join('poker', 'util', 'cffi', 'makeso.sh'),
        ]
    elif platform.system() == 'Windows':
        _, makesosh = fsutils.findTreeFiles(bin_path, ['.*' + os.path.sep + '(makeso.cmd)$'], ['.*\\.svn.*'])
    else:
        _, makesosh = fsutils.findTreeFiles(bin_path, ['.*' + os.path.sep + '(makeso.sh)$'], ['.*\\.svn.*'])

    if len(makesosh) == 0:
        actlog.log('run C/C++ compiler   : not found !!')

    for msh in makesosh:
        cmd = bin_path + os.path.sep + msh
        os.chmod(cmd, stat.S_IRWXU | stat.S_IRWXG)
        actlog.log('run C/C++ compiler   :', msh)
        status, output = commands.getstatusoutput(cmd)
        if status != 0:
            actlog.log('C/C++ compiler ERROR !!', cmd)
            actlog.log(output)
            return 0

    # 只有再Linux运行环境下才进行预编译
    if platform.system() != 'Linux':
        return 1

    # 生成编译文件
    pkgs = []
    pyfiles = options._pyfiles
    for pyf in pyfiles:
        if pyf.endswith('.py') and pyf.find('hotfix') < 0:
            pkg = '    import ' + '.'.join(pyf.split(os.path.sep)[1:])
            pkg = pkg[0:-3]
            if pkg.endswith('__init__'):
                pkg = pkg[0:-9]
            pkgs.append(pkg)
    content = '''
# -*- coding: utf-8 -*-
# author time : %s
import sys
from twisted.internet import reactor # 确保reactor第一时间初始化, 否则可能莫名其妙的crash
if sys.getdefaultencoding().lower() != 'utf-8' :
    reload(sys)
    sys.setdefaultencoding("utf-8")
try:
%s
except:
    print sys.path
    raise
''' % (str(datetime.now()), '\n'.join(pkgs))
    cfilepath = bin_path + os.path.sep + '_compiler.py'
    fsutils.writeFile('', cfilepath, content)

    actlog.log('run PYPY  compiler   :', cfilepath)
    pypy = strutil.getEnv('PYPY', 'pypy')
    cmd = '%s -tt %s' % (pypy, cfilepath)
    status, output = commands.getstatusoutput(cmd)
    if status != 0:
        actlog.log('ERROR !!', 'compile py files false !', status, cfilepath)

        lines = output.split('\n')
        for line in lines:
            actlog.log(line)
        return 0
    else:
        # fsutils.deleteFile(cfilepath)
        for pyf in pyfiles:
            if pyf.endswith('.py'):
                f = bin_path + os.path.sep + pyf + 'c'
                if fsutils.fileExists(f):
                    fsutils.deleteFile(f)

    return 1
Exemplo n.º 12
0
def action(options):
    '''
    装载并检测服务启动配置文件
    '''
    projectlist, game_packages, gameids = __load_project_file(options)
    if not projectlist:
        return 0
    setattr(options, 'projectlist', projectlist)
    options.pokerdict['game_packages'] = game_packages

    otherconf = os.listdir(fsutils.appendPath(options.poker_path, 'game'))
    conf_projects = []
    for oc in otherconf:
        try:
            gid = int(oc)
            if gid in gameids:
                conf_projects.append('game/' + str(gid))
        except:
            pass
    if 'game/9998' not in conf_projects:
        conf_projects.append('game/9998')
    options.pokerdict['conf.projects'] = conf_projects
    #     actlog.log('projectlist=', projectlist)

    machinedict = __load_machine_file(options)
    if not machinedict:
        return 0
    setattr(options, 'machinedict', machinedict)

    myenv = options.env
    for mid, mdefs in machinedict.items():
        myenv[mid + '.internet'] = mdefs['internet']
        myenv[mid + '.intranet'] = mdefs['intranet']
    #     actlog.log('machinedict=', machinedict)

    globaldict = __load_global_file(options)
    if not globaldict:
        return 0
    setattr(options, 'globaldict', globaldict)
    #     actlog.log('globaldict=', globaldict)

    options.pokerdict['log_path'] = globaldict['log_path']
    myenv['log_path'] = globaldict['log_path']

    dbdict = __load_db_file(options)
    if not dbdict:
        return 0
    setattr(options, 'dbdict', dbdict)
    #     actlog.log('dbdict=', dbdict)

    myenv['db.mysql.all'] = dbdict['mysql'].keys()
    myenv['db.redis.all'] = dbdict['redis'].keys()

    serverlist = __load_server_file(options, machinedict, gameids)
    if not serverlist:
        return 0
    setattr(options, 'serverlist', serverlist)
    #     actlog.log('serverlist=', serverlist)

    cmddict = __load_cmd_file(options)
    if not cmddict:
        return 0
    setattr(options, 'cmddict', cmddict)
    #     actlog.log('cmddict=', cmddict)

    #     rooms = __load_rooms_file(options)
    #     if not rooms :
    #         return 0
    #     setattr(options, 'rooms', rooms)
    #     actlog.log('cmddict=', cmddict)

    datas = {}
    datas['env'] = options.env
    datas['pokerdict'] = options.pokerdict
    datas['projectlist'] = options.projectlist
    datas['machinedict'] = options.machinedict
    datas['globaldict'] = options.globaldict
    datas['dbdict'] = options.dbdict
    datas['serverlist'] = options.serverlist
    datas['cmddict'] = options.cmddict

    fsutils.writeFile(options.poker_path, '._service_.json', datas)
    fsutils.writeFile(options.poker_path, '._process_.json',
                      datas['serverlist'])
    fsutils.writeFile(options.poker_path, '._confprojects_.json',
                      conf_projects)

    outpath = options.pokerdict['output_path']
    fsutils.writeFile(outpath, 'out.datas.json', datas)
    fsutils.writeFile(outpath, 'out.db.json', datas['dbdict'])
    fsutils.writeFile(outpath, 'out.poker.global.json', datas['pokerdict'])
    fsutils.writeFile(outpath, 'out.freetime.global.json', datas['globaldict'])
    fsutils.writeFile(outpath, 'out.server.json', datas['serverlist'])

    if fsutils.fileExists(outpath + '/out.server.json.base'):
        s1 = fsutils.readFile(outpath + '/out.server.json.base')
        s2 = fsutils.readFile(outpath + '/out.server.json')
        if s1.strip() != s2.strip():
            raise Exception('the server.ison changed !! can not go !!')

    slist = []
    for k in datas['serverlist']:
        slist.append(
            str(k['type']) + str(k['id']) + ' ' +
            str(k['ip'] + ' ' + str(k.get('agent', ''))))
    slist.sort()
    slist = '\n'.join(slist)
    fsutils.writeFile(outpath, 'out.process.list', slist)

    return 1