Exemplo n.º 1
0
def _getLastOkDefines(options):
    p = getattr(options, 'poker_path', None)
    if not p:
        p = getattr(options, 'pokerpath', None)
    lastfile = p + '/._service_.json'
    datas = fsutils.readJsonFile(lastfile)
    return datas
Exemplo n.º 2
0
def _getLastOkDefines(options):
    p = getattr(options, 'poker_path', None)
    if not p :
        p = getattr(options, 'pokerpath', None)
    lastfile = p + '/._service_.json'
    datas = fsutils.readJsonFile(lastfile)
    return datas
Exemplo n.º 3
0
def make_process_list(options, machinedict, gameids):
    jname = 'poker/process.json'
    jsonfile = fsutils.appendPath(options.poker_path, jname)
    actlog.log('load %-15s :' % (jname), jsonfile)
    processlist = fsutils.readJsonFile(jsonfile, True)
    if not isinstance(processlist, dict) :
        return actlog.error(jname + ' : format error, root object must be dict'), machinedict
    return processlist, machinedict
Exemplo n.º 4
0
def make_process_list(options, machinedict, gameids):
    jname = 'poker/process.json'
    jsonfile = fsutils.appendPath(options.poker_path, jname)
    actlog.log('load %-15s :' % (jname), jsonfile)
    processlist = fsutils.readJsonFile(jsonfile, True)
    if not isinstance(processlist, dict):
        return actlog.error(
            jname + ' : format error, root object must be dict'), machinedict
    return processlist, machinedict
Exemplo n.º 5
0
    def doGet(self, name, branch, revision):
        configMod = self.configMods[name]
        if branch == 'testing':
            _file = configMod.testingFile
        elif branch == 'release':
            _file = configMod.releaseFile
        # elif branch == 'online':
        #     _file = configMod.onlineFile

        if not revision or revision.upper() == 'LOCAL':
            fileContent = fsutils.readJsonFile(_file)
        elif revision == 'HEAD':
            tempFileName = _file + '.HEAD'
            svn.export(_file, tempFileName, revision='HEAD')
            fileContent = fsutils.readJsonFile(tempFileName)

        fileContent = self.formatJson(fileContent)

        return fileContent
Exemplo n.º 6
0
    def doGet(self, name, branch, revision):
        configMod = self.configMods[name]
        if branch == 'testing':
            _file = configMod.testingFile
        elif branch == 'release':
            _file = configMod.releaseFile
        # elif branch == 'online':
        #     _file = configMod.onlineFile

        if not revision or revision.upper() == 'LOCAL':
            fileContent = fsutils.readJsonFile(_file)
        elif revision == 'HEAD':
            tempFileName = _file + '.HEAD'
            svn.export(_file, tempFileName, revision='HEAD')
            fileContent = fsutils.readJsonFile(tempFileName)

        fileContent = self.formatJson(fileContent)

        return fileContent
Exemplo n.º 7
0
 def do_http_get_process_list(self):
     jfile = fsutils.appendPath(self.options.pokerpath, '._process_.json')
     if fsutils.fileExists(jfile):
         datas = fsutils.readJsonFile(jfile)
     else:
         datas = []
     datas.sort(key=lambda x: x['type'] + x['id'])
     mo = MsgPack()
     mo.setCmd('process_list')
     mo.setResult('datas', datas)
     return mo
Exemplo n.º 8
0
    def do_http_t3flush_get_json_file(self, jsonfile):
        self._initBase()
        ftlog.debug("do_http_t3flush_get_json_file jsonfile:", jsonfile)
        if fsutils.fileExists(jsonfile):
            datas = fsutils.readJsonFile(jsonfile)
        else:
            datas = {'error': 'file "%s" not existed' % jsonfile}

        mo = MsgPack()
        mo.setCmd('json_file_data')
        mo.setResult('isOk', True)
        mo.setResult('jsonfile', jsonfile)
        mo.setResult('datas', datas)
        return mo
Exemplo n.º 9
0
    def do_http_texas_get_json_file(self, jsonfile):
        self._initBase()
        ftlog.debug("do_http_texas_gen_json_file jsonfile:", jsonfile)
        if fsutils.fileExists(jsonfile) :
            datas = fsutils.readJsonFile(jsonfile)
        else:
            datas = {'error': 'file "%s" not existed' % jsonfile}

        mo = MsgPack()
        mo.setCmd('json_file_data')
        mo.setResult('isOk', True)
        mo.setResult('jsonfile', jsonfile)
        mo.setResult('datas', datas)
        return mo 
Exemplo n.º 10
0
def get_action_list(options) :
    fpath = options.logpath
    lfs = os.listdir(fpath)
    actlist = []
    for lf in lfs :
        if lf.startswith('action.') and lf.endswith('.json') :
            af = fsutils.appendPath(fpath, lf)
            action = fsutils.readJsonFile(af)
            actlist.append(action)
    actlist.sort(key=lambda x : x['uuid'])
    
    while len(actlist) > 10 :
        remove_action(options, [actlist[0]['uuid']])
        del actlist[0]

    return actlist
Exemplo n.º 11
0
def get_action_list(options):
    fpath = options.logpath
    lfs = os.listdir(fpath)
    actlist = []
    for lf in lfs:
        if lf.startswith('action.') and lf.endswith('.json'):
            af = fsutils.appendPath(fpath, lf)
            action = fsutils.readJsonFile(af)
            actlist.append(action)
    actlist.sort(key=lambda x: x['uuid'])

    while len(actlist) > 10:
        remove_action(options, [actlist[0]['uuid']])
        del actlist[0]

    return actlist
Exemplo n.º 12
0
def __load_server_file(options, machinedict, gameids):
    mode = options.env['mode']
    processlist, machinedict = modefactory[mode].make_process_list(
        options, machinedict, gameids)
    if not processlist:
        return processlist

    allrooms = {}
    # 装载房间的配置,用于获取房间进程ID和数量
    for gameId in gameids:
        jname = 'game/' + str(gameId) + '/room/0.json'
        jsonfile = fsutils.appendPath(options.poker_path, jname)
        if fsutils.fileExists(jsonfile):
            actlog.log('load %-15s :' % (jname), jsonfile)
            rooms = fsutils.readJsonFile(jsonfile, True)
            if not isinstance(rooms, dict):
                return actlog.error(
                    jname + ' : format error, root object must be dict')
            for rid in rooms:
                if rid in allrooms:
                    return actlog.error(jname +
                                        ' : the roomId already defined !! ' +
                                        str(rid))
                allrooms[rid] = rooms[rid]

    serverlist = auto_process.auto_group_process(machinedict, processlist,
                                                 allrooms, mode)

    serverlist = strutil.replace_objevn_value(serverlist, options.env)

    checks = strutil.cloneData(serverlist)
    for _, m in options.machinedict.items():
        internet = m['internet']
        intranet = m['intranet']
        for x in xrange(len(checks) - 1, -1, -1):
            p = checks[x]
            if p['ip'] == internet or p['ip'] == intranet:
                del checks[x]

    if len(checks) > 0:
        for p in checks:
            actlog.error('can not find machine define of server ip :', p['ip'])
        return 0
    return serverlist
Exemplo n.º 13
0
 def do_http_get_json_file(self, jsonfile):
     jfile = fsutils.appendPath(self.options.pokerpath, jsonfile)
     print "DEBUG", "self.options.pokerpath:", self.options.pokerpath, "jsonfile:", jsonfile, 'jfile:', jfile
     if fsutils.fileExists(jfile):
         datas = fsutils.readJsonFile(jfile)
     else:
         if jsonfile in ('project.json', 'server.json'):
             datas = []
         # elif jsonfile in model.models:
         #     method = model.models[jsonfile].get('get')
         #     if method:
         #         datas = method()
         else:
             datas = {}
     mo = MsgPack()
     mo.setCmd('json_file_data')
     mo.setResult('jsonfile', jsonfile)
     mo.setResult('datas', datas)
     return mo
Exemplo n.º 14
0
    def calcAllStartTimes(self, days):
        '''
        获取所有比赛的所有场次的所有开赛时间

        return: {
            'mtt_chip_10w': {
                'name': '10万金币赛',
                'rooms': {
                    '8300': [
                        14232423423,
                        14232423423,
                        ...
                    ],
                    '8301': [
                        14232423423,
                        14232423423,
                        ...
                    ]
                }
            },
            'mtt_chip_100w': {...},
            ...
        }
        '''
        self._initBase()
        jsonfile = fsutils.appendPath(teamCfgDir, 'room.json')
        matchRoomConfs = fsutils.readJsonFile(jsonfile)

        allStartTimes = {}

        for roomId, roomConf in matchRoomConfs.items():
            if roomConf['typeName'] == 'mtt':
                matchConf = roomConf['matchConf']
                matchTypeId = matchConf['match_id']
                statTimeList = self.calcStartTimes(roomId, matchConf, days)
                if matchTypeId not in allStartTimes:
                    allStartTimes[matchTypeId] = {}
                    allStartTimes[matchTypeId]['name'] = roomConf['name']
                    allStartTimes[matchTypeId]['visible'] = matchConf[
                        'visible']
                    allStartTimes[matchTypeId]['rooms'] = {}
                allStartTimes[matchTypeId]['rooms'][roomId] = statTimeList
        return allStartTimes
Exemplo n.º 15
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.º 16
0
    def calcAllStartTimes(self, days):
        '''
        获取所有比赛的所有场次的所有开赛时间

        return: {
            'mtt_chip_10w': {
                'name': '10万金币赛',
                'rooms': {
                    '8300': [
                        14232423423,
                        14232423423,
                        ...
                    ],
                    '8301': [
                        14232423423,
                        14232423423,
                        ...
                    ]
                }
            },
            'mtt_chip_100w': {...},
            ...
        }
        '''
        self._initBase()
        jsonfile = fsutils.appendPath(teamCfgDir, 'room.json')
        matchRoomConfs = fsutils.readJsonFile(jsonfile)

        allStartTimes = {}

        for roomId, roomConf in matchRoomConfs.items():
            if roomConf['typeName'] == 'mtt':
                matchConf = roomConf['matchConf']
                matchTypeId = matchConf['match_id']
                statTimeList = self.calcStartTimes(roomId, matchConf, days)
                if matchTypeId not in allStartTimes:
                    allStartTimes[matchTypeId] = {}
                    allStartTimes[matchTypeId]['name'] = roomConf['name']
                    allStartTimes[matchTypeId]['visible'] = matchConf['visible']
                    allStartTimes[matchTypeId]['rooms'] = {}
                allStartTimes[matchTypeId]['rooms'][roomId] = statTimeList
        return allStartTimes
Exemplo n.º 17
0
def action(options):
    '''
    装载并检测服务启动配置文件
    '''
    alldata = options.alldata
    alldata['freetime:db'] = options.dbdict
    alldata['freetime:global'] = options.globaldict
    alldata['freetime:server'] = options.serverlist
    alldata['poker:cmd'] = options.cmddict
    alldata['poker:machine'] = options.machinedict
    alldata['poker:project'] = options.projectlist
    alldata['poker:global'] = options.pokerdict
    alldata['poker:oldcmd'] = fsutils.readJsonFile(options.poker_path + '/poker/oldcmd.json')

    config_redis = options.pokerdict['config_redis']
    changekeys, changelen = _update_redis_file_by_diff(config_redis, alldata)
    setattr(options, 'changekeys', changekeys)
    setattr(options, 'changelen', changelen)

    return 1
Exemplo n.º 18
0
def __load_poker_file(options):
    pokerfile = options.pokerfile
    actlog.log('LOAD POKER FILE      :', pokerfile)
    pokerdict = fsutils.readJsonFile(pokerfile, True)
    pokerdict['poker_path'] = options.poker_path

    if not isinstance(pokerdict, dict):
        return actlog.error('POKER FILE : format error,must be a dict')

    gameId = pokerdict.get('id', None)
    if not isinstance(gameId, int) or gameId <= 0 or gameId >= 10000:
        return actlog.error('POKER FILE : id value is wrong')

    gameName = pokerdict.get('name', None)
    if not isinstance(gameName, (str, unicode)) or len(gameName) <= 0:
        return actlog.error('POKER FILE : name value is wrong')
    if gameName.find('-') >= 0:
        return actlog.error(
            'POKER FILE : name value is wrong, can not have "-" (reserved char)'
        )

    corporation = pokerdict.get('corporation', 'tuyoo')
    if corporation not in ('tuyoo', 'momo'):
        return actlog.error(
            'POKER FILE : corporation value wrong, choice: tuyoo or momo')
    pokerdict['corporation'] = corporation

    mode = pokerdict.get('mode', 0)
    if mode not in (1, 2, 3, 4):
        return actlog.error(
            'POKER FILE : mode value must be an integer, choice : 1(online) or 2(simulation) or 3(rich test) or 4(tiny test)'
        )

    port_redis = pokerdict.get('port_redis', 0)
    if not actutils.check_port(port_redis, True):
        return actlog.error(
            'POKER FILE : port_redis, socket port number wrong ' +
            str(port_redis))
    pokerdict['port_redis'] = port_redis

    local_internet = pokerdict.get('local_internet', '')
    if not isinstance(local_internet, (str, unicode)):
        return actlog.error('POKER FILE : local_internet value is wrong')
    pokerdict['local_internet'] = local_internet

    local_intranet = __get_value(pokerdict, 'local_intranet', None)
    if not isinstance(local_intranet, (str, unicode)):
        return actlog.error('POKER FILE : local_intranet value is wrong')
    pokerdict['local_intranet'] = local_intranet

    port_http = int(__get_value(pokerdict, 'port_http', 0))
    if not actutils.check_port(port_http, True):
        return actlog.error(
            'POKER FILE : port_http, socket port number wrong ' +
            str(port_http))
    pokerdict['port_http'] = port_http

    projects_path = __get_value(pokerdict, 'projects_path', None)
    if not isinstance(projects_path, str):
        return actlog.error(
            'POKER FILE : projects_path wrong, must pointing to the projects path'
        )
    projects_path = fsutils.makeAsbpath(projects_path, pokerfile)
    if not fsutils.dirExists(projects_path):
        return actlog.error(
            'POKER FILE : projects_path, the path not exists [' +
            projects_path + ']')
    pokerdict['projects_path'] = projects_path

    output_path = __get_value(pokerdict, 'output_path', None)
    if not isinstance(output_path, str):
        return actlog.error(
            'POKER FILE : output_path wrong, must pointing to the compile output path'
        )
    output_path = fsutils.makeAsbpath(output_path, pokerfile)
    if not fsutils.dirExists(output_path):
        return actlog.error(
            'POKER FILE : output_path wrong, the path not exists [' +
            output_path + ']')
    pokerdict['output_path'] = output_path

    http = __get_value(pokerdict, 'http_sdk', '')
    if not actutils.check_http_url(http, 'POKER FILE : http_sdk'):
        return 0
    pokerdict['http_sdk'] = http

    http = __get_value(pokerdict, 'http_sdk_inner', None)
    if http != None and not actutils.check_http_url(
            http, 'POKER FILE : http_sdk_inner'):
        return 0
    pokerdict['http_sdk_inner'] = http

    http = __get_value(pokerdict, 'http_game', None)
    if http != None and not actutils.check_http_url(http,
                                                    'POKER FILE : http_game'):
        return 0
    pokerdict['http_game'] = http

    http = __get_value(pokerdict, 'http_download', None)
    if http != None and not actutils.check_http_url(
            http, 'POKER FILE : http_download'):
        return 0
    pokerdict['http_download'] = http

    http = __get_value(pokerdict, 'http_gdss', None)
    if http != None and not actutils.check_http_url(http,
                                                    'POKER FILE : http_gdss'):
        return 0
    pokerdict['http_gdss'] = http

    config_redis = __get_value(pokerdict, 'config_redis', None)
    if not isinstance(config_redis, str):
        return actlog.error(
            'POKER FILE : config_redis wrong, must pointing to the configure redis <ip>:<port>:<dbid>'
        )
    confdb = config_redis.split(':')
    if len(confdb) != 3:
        return actlog.error(
            'POKER FILE : config_redis wrong, must pointing to the configure redis <ip>:<port>:<dbid>'
        )
    pokerdict['config_redis'] = config_redis

    return pokerdict
Exemplo n.º 19
0
    def do_http_model_list(self):
        mj = getResourcePath('menu.json')
        models = fsutils.readJsonFile(mj)
        # 读取game目录下的游戏目录
        otherConfPath = fsutils.appendPath(self.options.pokerpath, 'game')
        otherconf = os.listdir(otherConfPath)
        games = []
        for gid in otherconf:
            try:
                # 创建game-游戏配置目录。由于其它游戏的配置目录都是空, 就都跳过
                if int(gid) not in [8, 30, 39]:
                    continue

                gid = str(int(gid))
                children = []
                tylog.debug("do_http_model_list|get game mode|", gid=gid)
                self.getGameConfiger(int(gid), children)
                if children:
                    games.append({'text': 'game-' + gid, 'children': children})

                # # 创建该游戏下面的所有配置目录
                # gameConfigPath = fsutils.appendPath(otherConfPath, gid)
                # gameConfigs = os.listdir(gameConfigPath)
                # for gc in gameConfigs:
                #     if str(gc) != '.svn':
                #         children.append({'text': str(gc), 'attributes':{
                #                 "purl" : "model/config/game/" + gid + '/' + gc + '.html'
                #             }}
                #         )
            except:
                tylog.error("do_http_model_list|get game mode error|", gid=gid)
        models[0]['children'].extend(games)
        # models[0]['children'].append({'text': '查看模板关联', 'attributes':{
        #                         "purl" : "model/config/game/incidence.html"
        #                     }})

        # 动态测试工具
        debugs = []
        models.append({'text': '调试工具', 'children': debugs})

        webroot = fsutils.appendPath(self.options.workpath, 'webroot', 'model',
                                     'debug')
        hfs = os.listdir(webroot)
        for hf in hfs:
            if hf.endswith('.html'):
                hc = fsutils.readFile(webroot + '/' + hf)
                t = self._findTitle(hc)
                if t:
                    purl = "model/debug/" + hf
                    debugs.append({'text': t, 'attributes': {"purl": purl}})
        debugs.sort(key=lambda x: x['text'])
        mo = MsgPack()
        mo.setCmd('model_list')
        mo.setResult('models', models)
        mo.setResult('pokerpath', self.options.pokerpath)
        mo.setResult('mgrpath', self.options.workpath)
        mo.setResult('localip', fsutils.getLocalMachineIp())
        mo.setResult(
            'title',
            '.'.join(fsutils.getLocalMachineIp()[0].split('.')[2:]) + '管理器')
        return mo