コード例 #1
0
ファイル: main.py プロジェクト: flamedancer/local_qz
def view_setting_backup(request):
    config_name = request.GET.get('conf')
    subarea = request.GET.get('area')
    date_str = request.GET.get('date')
    return HttpResponse( show_config_backup(config_name=config_name,
            subarea=subarea, date_str=date_str),  
            content_type="text/plain; charset=UTF8")
コード例 #2
0
def view_setting_backup(request):
    config_name = request.GET.get('conf')
    subarea = request.GET.get('area')
    date_str = request.GET.get('date')
    return HttpResponse(show_config_backup(config_name=config_name,
                                           subarea=subarea,
                                           date_str=date_str),
                        content_type="text/plain; charset=UTF8")
コード例 #3
0
ファイル: main.py プロジェクト: flamedancer/local_qz
def setting_backup_diff(request):
    ''' config backup difference from today's config
    '''
    config_name = request.GET.get('conf')
    subarea = request.GET.get('area')
    date_str = request.GET.get('date')

    bk_data = show_config_backup(config_name=config_name,
            subarea=subarea, date_str=date_str)
#   if bk_contents in ('', None):
#       return HttpResponse('Backup of ' + date_str + 'does not exist.')

    conf = Config.get(config_name + '_' + subarea)
    if not conf:
        return HttpResponse(config_name + ' does not exist.')

    diffs = diff_2_str(conf.data, bk_data)
#   print '#### diffs="' + diffs + '", total length=', len(diffs)
    
    return HttpResponse( diffs, content_type="text/plain; charset=UTF8" )
コード例 #4
0
def setting_backup_diff(request):
    ''' config backup difference from today's config
    '''
    config_name = request.GET.get('conf')
    subarea = request.GET.get('area')
    date_str = request.GET.get('date')

    bk_data = show_config_backup(config_name=config_name,
                                 subarea=subarea,
                                 date_str=date_str)
    #   if bk_contents in ('', None):
    #       return HttpResponse('Backup of ' + date_str + 'does not exist.')

    conf = Config.get(config_name + '_' + subarea)
    if not conf:
        return HttpResponse(config_name + ' does not exist.')

    diffs = diff_2_str(conf.data, bk_data)
    #   print '#### diffs="' + diffs + '", total length=', len(diffs)

    return HttpResponse(diffs, content_type="text/plain; charset=UTF8")
コード例 #5
0
ファイル: main.py プロジェクト: flamedancer/local_qz
def game_setting(request,request_info=None, return_dict=False):
    """游戏配置
    """
    if not request_info:
        request_info = request.REQUEST
    data = {}
    subarea = request_info.get('subarea')
    categories = config_list.get_conflist_by_subarea(subarea)
    config_name = request_info.get('config_name')
    saved = False

    sconfig_name = config_list.get_configname_by_subarea(config_name,subarea)
    str_subareas_confname = config_list.get_configname_by_subarea('subareas_conf', '1')
    subareas_conf = Config.get(str_subareas_confname)
    if not subareas_conf:
        subareas_conf = Config.create(str_subareas_confname)

    subareas_conf_dict = eval(subareas_conf.data)

    return_subareas_conf = []
    for key in sorted(subareas_conf_dict.keys()):
        return_subareas_conf.append((key, subareas_conf_dict[key]))
    data['config_title'] = config_list.get_description(config_name)
    data['config_title'] += '__%s' % config_name
    if sconfig_name:
        #修改具体的一个
        config = Config.get(sconfig_name)
        if not config:
            config = Config.create(sconfig_name)
        config_value = config.data
        if request.method == 'POST':
            before_config = config_value
            if not return_dict:
                config_md5sum_from_web = request.POST['config_md5sum'] #before this update
                if type( config_value ) == unicode:
                    config_md5sum_calculated = hashlib.md5( config_value.strip().encode('utf-8') ).hexdigest()
                else:
                    config_md5sum_calculated = hashlib.md5( config_value.strip() ).hexdigest()

                if config_md5sum_from_web !=  config_md5sum_calculated:
                    return HttpResponse('<script>alert("配置内容, 已被别人修改过. 请重新刷新,再作修改。");</script>')

            config_value = request_info['config_value'].encode('utf-8').replace('\r','').strip()
            config.data = config_value
            if config_name != 'ruby_skill_params_config':
                verify_info = verify_game_config(config_name, eval(config_value))
            # 通过ruby的配置  简化技能的配置
            else:
                verify_info = _config_skill_params_by_ruby(config_value, request)
            if verify_info != '':
                return HttpResponse('<script>alert("%s");history.go(-1)</script>' % verify_info)
            config.put()
            config_update(subarea, config_name)

            moderator = apps.admin.auth.get_moderator_by_request(request)
            username,date,subarea,configname,REMOTE_ADDR = moderator.username,datetime.datetime.now(),subarea, data['config_title'], request.META["REMOTE_ADDR"]
            UpdateConfRecord.record(username, date, subarea, configname, REMOTE_ADDR)
            saved = True

            
            log_data = {}
            diff_result = diff_2_str(config_value, before_config)
            if diff_result:
                log_data['diff'] = diff_result
                log_data['subarea'] = subarea
                log_data['config_name'] = config_name
                log_data['before_config'] = before_config
                log_data['after_config'] = config_value
                log_data["username"] =  moderator.username
                ConfigHistory.set_log(**log_data)


            #多分区,保存配置后,要允许运营同学 同步到其它分区。
            config_use_subarea = False 
            for g in config_list.g_lConfig:
                if g['name'] == config_name and g['use_subarea']:
                    config_use_subarea = True 
                    break

            if config_use_subarea:
                #本配置, 不同的分区,有差别, 要同步到其它分区
                same_contents_subareas = {}
                diff_contents_subareas = {}
                for other_subarea_id, other_subarea_name in subareas_conf_dict.items():
                    if other_subarea_id == subarea:
                        continue

                    other_subarea = Config.get(config_name + '_' + other_subarea_id)
                    if not other_subarea:
                        other_subarea = Config.create(config_name + '_' + other_subarea_id)
                    #print '#### other_subarea.data=', other_subarea.data.encode('utf8')
                    #print '#### config_value=', config_value
                    #print '#### other_subarea.data == config_value ', other_subarea.data == config_value
                    if other_subarea.data == config_value or other_subarea.data.encode('utf8') == config_value:
                        same_contents_subareas[other_subarea_id] = other_subarea_name
                    else:
                        diff_contents_subareas[other_subarea_id] = other_subarea_name

                data = {'subarea': subarea, 'config_name': config_name}
                data['config_description'] = config_list.get_description(config_name)
                data['subarea_name'] = subareas_conf_dict[subarea]
                data['same_contents_subareas'] = same_contents_subareas
                data['diff_contents_subareas'] = diff_contents_subareas
                return 'admin/sync_conf_to_subarea.html', data

    else:
        #显示所有
        config_value = None
    data['subarea'] = subarea
    data['subareas_conf'] = return_subareas_conf
    #data['g_l_config'] = g_l_config
    data['categories'] = categories
    data['config_name'] = config_name
    data['config_value'] = beautify_config_value (config_value)
    data['saved'] = saved
    data['updateconfrecord'] = UpdateConfRecord.infos()['infos_list']
    if return_dict:
        return data

    data['config_error'] = ''
    if subarea == '1' and not config_name:
        data['config_error'] = check_config_error()

    #print '#### data[config_error]=', data['config_error']

    if config_value:
        if type( config_value ) == unicode:
            config_md5sum_calculated = hashlib.md5( config_value.strip().encode('utf-8') ).hexdigest()
        else:
            config_md5sum_calculated = hashlib.md5( config_value.strip() ).hexdigest()
        data['config_md5sum'] = config_md5sum_calculated

    #data['app_name'] = settings.APP_NAME
    #data['environment_type'] = settings.ENVIRONMENT_TYPE

    #show config backup
    conf_backup_date = RedisTool.get('conf_backup_date')

    data['conf_backup_date'] = conf_backup_date
    data['backup_diff_from_now'] = {}
    data['changed_from_today'] = []    #from today's early morning backup

    if config_name: #display one specific config (in certain subarea)
        old_conf_data = show_config_backup(config_name=config_name, 
               subarea=subarea, date_str=conf_backup_date)

        if old_conf_data in ('', None): #never backed up yet
            data['backup_diff_from_now'] = ''
        elif Config.get(config_name + '_' + subarea):
            if old_conf_data == Config.get(config_name + '_' + subarea).data:
                data['backup_diff_from_now'] = ''
            else:
                data['backup_diff_from_now'] = 'Yes'

    else: #display overview of all config
      if subarea:
        for conf_name in config_list.get_game_config_name_list(subarea=subarea):
            conf_obj = Config.get(conf_name + '_' + subarea)
            if not conf_obj:
                continue

            morning_conf_data = show_config_backup( config_name=conf_name, 
                                subarea=subarea, date_str=conf_backup_date)
            if morning_conf_data:   #if '', i.e. not exist/backed up yet, 
                                    #don't display
                if conf_obj.data != morning_conf_data:
                    data['changed_from_today'] += [
                         '<a href="/admin/game_setting/?config_name=' + 
                         conf_name + '&subarea=' + subarea + '">' + conf_name + '(' + subarea + ')</a>' ]
        data['changed_from_today'] = ', '.join(data['changed_from_today'])

    return 'admin/game_setting.html', data
コード例 #6
0
def game_setting(request, request_info=None, return_dict=False):
    """游戏配置
    """
    if not request_info:
        request_info = request.REQUEST
    data = {}
    subarea = request_info.get('subarea')
    categories = config_list.get_conflist_by_subarea(subarea)
    config_name = request_info.get('config_name')
    saved = False

    sconfig_name = config_list.get_configname_by_subarea(config_name, subarea)
    str_subareas_confname = config_list.get_configname_by_subarea(
        'subareas_conf', '1')
    subareas_conf = Config.get(str_subareas_confname)
    if not subareas_conf:
        subareas_conf = Config.create(str_subareas_confname)

    subareas_conf_dict = eval(subareas_conf.data)

    return_subareas_conf = []
    for key in sorted(subareas_conf_dict.keys()):
        return_subareas_conf.append((key, subareas_conf_dict[key]))
    data['config_title'] = config_list.get_description(config_name)
    data['config_title'] += '__%s' % config_name
    if sconfig_name:
        #修改具体的一个
        config = Config.get(sconfig_name)
        if not config:
            config = Config.create(sconfig_name)
        config_value = config.data
        if request.method == 'POST':
            before_config = config_value
            if not return_dict:
                config_md5sum_from_web = request.POST[
                    'config_md5sum']  #before this update
                if type(config_value) == unicode:
                    config_md5sum_calculated = hashlib.md5(
                        config_value.strip().encode('utf-8')).hexdigest()
                else:
                    config_md5sum_calculated = hashlib.md5(
                        config_value.strip()).hexdigest()

                if config_md5sum_from_web != config_md5sum_calculated:
                    return HttpResponse(
                        '<script>alert("配置内容, 已被别人修改过. 请重新刷新,再作修改。");</script>'
                    )

            config_value = request_info['config_value'].encode(
                'utf-8').replace('\r', '').strip()
            config.data = config_value
            if config_name != 'ruby_skill_params_config':
                verify_info = verify_game_config(config_name,
                                                 eval(config_value))
            # 通过ruby的配置  简化技能的配置
            else:
                verify_info = _config_skill_params_by_ruby(
                    config_value, request)
            if verify_info != '':
                return HttpResponse(
                    '<script>alert("%s");history.go(-1)</script>' %
                    verify_info)
            config.put()
            config_update(subarea, config_name)

            moderator = apps.admin.auth.get_moderator_by_request(request)
            username, date, subarea, configname, REMOTE_ADDR = moderator.username, datetime.datetime.now(
            ), subarea, data['config_title'], request.META["REMOTE_ADDR"]
            UpdateConfRecord.record(username, date, subarea, configname,
                                    REMOTE_ADDR)
            saved = True

            log_data = {}
            diff_result = diff_2_str(config_value, before_config)
            if diff_result:
                log_data['diff'] = diff_result
                log_data['subarea'] = subarea
                log_data['config_name'] = config_name
                log_data['before_config'] = before_config
                log_data['after_config'] = config_value
                log_data["username"] = moderator.username
                ConfigHistory.set_log(**log_data)

            #多分区,保存配置后,要允许运营同学 同步到其它分区。
            config_use_subarea = False
            for g in config_list.g_lConfig:
                if g['name'] == config_name and g['use_subarea']:
                    config_use_subarea = True
                    break

            if config_use_subarea:
                #本配置, 不同的分区,有差别, 要同步到其它分区
                same_contents_subareas = {}
                diff_contents_subareas = {}
                for other_subarea_id, other_subarea_name in subareas_conf_dict.items(
                ):
                    if other_subarea_id == subarea:
                        continue

                    other_subarea = Config.get(config_name + '_' +
                                               other_subarea_id)
                    if not other_subarea:
                        other_subarea = Config.create(config_name + '_' +
                                                      other_subarea_id)
                    #print '#### other_subarea.data=', other_subarea.data.encode('utf8')
                    #print '#### config_value=', config_value
                    #print '#### other_subarea.data == config_value ', other_subarea.data == config_value
                    if other_subarea.data == config_value or other_subarea.data.encode(
                            'utf8') == config_value:
                        same_contents_subareas[
                            other_subarea_id] = other_subarea_name
                    else:
                        diff_contents_subareas[
                            other_subarea_id] = other_subarea_name

                data = {'subarea': subarea, 'config_name': config_name}
                data['config_description'] = config_list.get_description(
                    config_name)
                data['subarea_name'] = subareas_conf_dict[subarea]
                data['same_contents_subareas'] = same_contents_subareas
                data['diff_contents_subareas'] = diff_contents_subareas
                return 'admin/sync_conf_to_subarea.html', data

    else:
        #显示所有
        config_value = None
    data['subarea'] = subarea
    data['subareas_conf'] = return_subareas_conf
    #data['g_l_config'] = g_l_config
    data['categories'] = categories
    data['config_name'] = config_name
    data['config_value'] = beautify_config_value(config_value)
    data['saved'] = saved
    data['updateconfrecord'] = UpdateConfRecord.infos()['infos_list']
    if return_dict:
        return data

    data['config_error'] = ''
    if subarea == '1' and not config_name:
        data['config_error'] = check_config_error()

    #print '#### data[config_error]=', data['config_error']

    if config_value:
        if type(config_value) == unicode:
            config_md5sum_calculated = hashlib.md5(
                config_value.strip().encode('utf-8')).hexdigest()
        else:
            config_md5sum_calculated = hashlib.md5(
                config_value.strip()).hexdigest()
        data['config_md5sum'] = config_md5sum_calculated

    #data['app_name'] = settings.APP_NAME
    #data['environment_type'] = settings.ENVIRONMENT_TYPE

    #show config backup
    conf_backup_date = RedisTool.get('conf_backup_date')

    data['conf_backup_date'] = conf_backup_date
    data['backup_diff_from_now'] = {}
    data['changed_from_today'] = []  #from today's early morning backup

    if config_name:  #display one specific config (in certain subarea)
        old_conf_data = show_config_backup(config_name=config_name,
                                           subarea=subarea,
                                           date_str=conf_backup_date)

        if old_conf_data in ('', None):  #never backed up yet
            data['backup_diff_from_now'] = ''
        elif Config.get(config_name + '_' + subarea):
            if old_conf_data == Config.get(config_name + '_' + subarea).data:
                data['backup_diff_from_now'] = ''
            else:
                data['backup_diff_from_now'] = 'Yes'

    else:  #display overview of all config
        if subarea:
            for conf_name in config_list.get_game_config_name_list(
                    subarea=subarea):
                conf_obj = Config.get(conf_name + '_' + subarea)
                if not conf_obj:
                    continue

                morning_conf_data = show_config_backup(
                    config_name=conf_name,
                    subarea=subarea,
                    date_str=conf_backup_date)
                if morning_conf_data:  #if '', i.e. not exist/backed up yet,
                    #don't display
                    if conf_obj.data != morning_conf_data:
                        data['changed_from_today'] += [
                            '<a href="/admin/game_setting/?config_name=' +
                            conf_name + '&subarea=' + subarea + '">' +
                            conf_name + '(' + subarea + ')</a>'
                        ]
            data['changed_from_today'] = ', '.join(data['changed_from_today'])

    return 'admin/game_setting.html', data