def sync_conf_to_subarea(request): config_name = request.GET.get('config_name') current_subarea = request.GET.get('current_subarea') subarea_list = request.GET.getlist('subarea_list') current_config_data = Config.get(config_name + '_' + current_subarea).data for sa in subarea_list: c = Config.get(config_name + '_' + sa) if not c: c = Config.create(config_name + '_' + sa) c.data = current_config_data c.put() 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) subarea_id_name_list = [] for s in subarea_list: subarea_id_name_list += [ u'分区' + s + ': ' + subareas_conf_dict[s] ] data = { 'config_name': config_name, 'config_description': config_list.get_description(config_name), 'subarea': current_subarea, 'subarea_id_name_list': subarea_id_name_list, } return 'admin/sync_subarea_done.html', data
def sync_conf_to_subarea(request): config_name = request.GET.get('config_name') current_subarea = request.GET.get('current_subarea') subarea_list = request.GET.getlist('subarea_list') current_config_data = Config.get(config_name + '_' + current_subarea).data for sa in subarea_list: c = Config.get(config_name + '_' + sa) if not c: c = Config.create(config_name + '_' + sa) c.data = current_config_data c.put() 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) subarea_id_name_list = [] for s in subarea_list: subarea_id_name_list += [u'分区' + s + ': ' + subareas_conf_dict[s]] data = { 'config_name': config_name, 'config_description': config_list.get_description(config_name), 'subarea': current_subarea, 'subarea_id_name_list': subarea_id_name_list, } return 'admin/sync_subarea_done.html', data
def generate_backup(): ''' 一天只备份一次, 在最早的一次发生(任何)配置变更后。 每天的第一次配置改动后,触发 config reload_all,备份一次改动后的所有区的内容. 每天第一次备份全部分区的全部配置时,可能会要花些时间, 但实际测试显示是很快的, 基本在1秒内全备份完成。 如果 redis 重启了,要从mongo中调出所有的配置,再备份,则可能略花点时间。 只要不是redis重启,实测速度基本可以接受。 ''' today_str = str(datetime.datetime.now().date()) #need put into redis, or when program restarted, it will re-backup conf_backup_date = RedisTool.get('conf_backup_date') #is a string if today_str == conf_backup_date: return #conf_with_multi_area = [ c['name'] for c in g_lConfig if c['use_subarea'] ] subarea_conf_obj = Config.get('subareas_conf_1') if not subarea_conf_obj: subarea_conf_obj = Config.create('subareas_conf_1') subarea_conf = eval(subarea_conf_obj.data) subarea_ids = subarea_conf.keys() # print '#### in backup, subarea_config.data=', subarea_conf # print '#### in backup, subarea_ids=', subarea_ids subarea_ids.sort() #put 1 as first for area_id in subarea_ids: all_config_name_list = get_game_config_name_list(area_id) for conf_name in all_config_name_list: full_conf_name = conf_name + '_' + area_id print '##### in config backup,', full_conf_name, '@', datetime.datetime.now( ) #need backup conf_obj.data, which has comments "# ... " conf_obj = Config.get(full_conf_name) if not conf_obj: continue #conf_bk = Config.get(full_conf_name + '_' + today_str) #if conf_bk is None: conf_bk = Config.create(full_conf_name + '_' + today_str) conf_bk.data = conf_obj.data conf_bk.put() #delete old backups old_conf_obj = Config.get(full_conf_name + '_' + conf_backup_date) if not old_conf_obj: continue old_conf_obj.delete() RedisTool.set('conf_backup_date', today_str) # str
def generate_backup(): ''' 一天只备份一次, 在最早的一次发生(任何)配置变更后。 每天的第一次配置改动后,触发 config reload_all,备份一次改动后的所有区的内容. 每天第一次备份全部分区的全部配置时,可能会要花些时间, 但实际测试显示是很快的, 基本在1秒内全备份完成。 如果 redis 重启了,要从mongo中调出所有的配置,再备份,则可能略花点时间。 只要不是redis重启,实测速度基本可以接受。 ''' today_str = str( datetime.datetime.now().date() ) #need put into redis, or when program restarted, it will re-backup conf_backup_date = RedisTool.get('conf_backup_date') #is a string if today_str == conf_backup_date: return #conf_with_multi_area = [ c['name'] for c in g_lConfig if c['use_subarea'] ] subarea_conf_obj = Config.get('subareas_conf_1') if not subarea_conf_obj: subarea_conf_obj = Config.create('subareas_conf_1') subarea_conf = eval(subarea_conf_obj.data) subarea_ids = subarea_conf.keys() # print '#### in backup, subarea_config.data=', subarea_conf # print '#### in backup, subarea_ids=', subarea_ids subarea_ids.sort() #put 1 as first for area_id in subarea_ids: all_config_name_list = get_game_config_name_list(area_id) for conf_name in all_config_name_list: full_conf_name = conf_name + '_' + area_id print '##### in config backup,', full_conf_name, '@', datetime.datetime.now() #need backup conf_obj.data, which has comments "# ... " conf_obj = Config.get(full_conf_name) if not conf_obj: continue #conf_bk = Config.get(full_conf_name + '_' + today_str) #if conf_bk is None: conf_bk = Config.create(full_conf_name + '_' + today_str) conf_bk.data = conf_obj.data conf_bk.put() #delete old backups old_conf_obj = Config.get(full_conf_name + '_' + conf_backup_date) if not old_conf_obj: continue old_conf_obj.delete() RedisTool.set('conf_backup_date', today_str) # str
def __init__(self): 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(subareas_conf) self.configs[str_subareas_confname] = eval(subareas_conf.data) self.subareas_confname = str_subareas_confname
def submit_game_settings_by_excel(request): data = {} config_name = str(request.GET.get('config_name')) subarea_default = request.POST.get('subarea_default') data['config_name'] = config_name 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])) if not config_name in canuse_config_list: data['config_value'] = make_config(request, config_name) else: x_func = eval(config_name.capitalize() +'()') files = request.FILES.get('xls', None) if not files: data['config_value'] = 'Miss files!' else: data['config_value'] = x_func.make_config(files, config_name) str_config_description = config_list.get_description(config_name) data['config_title'] = str_config_description data['subareas_conf'] = return_subareas_conf data['saved'] = False data['submit_game_settings_by_excel'] = True data['subarea_default'] = subarea_default return 'admin/game_setting.html', data
def __init__(self): 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(subareas_conf) self.configs[str_subareas_confname] = eval(subareas_conf.data) self.subareas_confname = str_subareas_confname
def get_game_config(self, config_name, subarea): #config_name, 配置名; subarea, 分区号 if not subarea: subarea = '1' subarea_config_name = self._get_subarea_config_name(config_name, subarea) if subarea_config_name not in self.configs: config_obj = Config.get(subarea_config_name) or Config.create(subarea_config_name) config_dict = eval(config_obj.data) if not config_dict and subarea != '1': # 若此分区当前配置为空, 尝试读取 1 区 配置 return self.get_game_config(config_name, '1') self.configs[subarea_config_name] = config_dict return self.configs[subarea_config_name]
def get_game_config(self, config_name, subarea): #config_name, 配置名; subarea, 分区号 if not subarea: subarea = '1' subarea_config_name = self._get_subarea_config_name( config_name, subarea) if subarea_config_name not in self.configs: config_obj = Config.get(subarea_config_name) or Config.create( subarea_config_name) config_dict = eval(config_obj.data) if not config_dict and subarea != '1': # 若此分区当前配置为空, 尝试读取 1 区 配置 return self.get_game_config(config_name, '1') self.configs[subarea_config_name] = config_dict return self.configs[subarea_config_name]
import apps.settings as settings from django.core.management import setup_environ setup_environ(settings) this_config_name = '' config_path = '' assert len(sys.argv) >= 2, 'no config_file' config_path = os.path.join(cur_dir, sys.argv[1]) assert os.path.exists(config_path), '!!!Can find COnfigfile!!' if len(sys.argv) == 3: this_config_name = sys.argv[2] from apps.models.config import Config config_dict = ast.literal_eval(open(config_path, "r").read()) for sconfig_name in config_dict: print "*Find config ", sconfig_name, "*This_config", this_config_name if this_config_name and this_config_name != sconfig_name: continue print "** load :", sconfig_name config = Config.get(sconfig_name) if not config: config = Config.create(sconfig_name) config_value = config_dict[sconfig_name] config.data = config_value config.put() print "****** load config Success!!"
def save_game_settings(request): ''' 保存配置, 多个分区的 subarea_list ''' data = {} config_value = '' config_name = request.GET.get('config_name','') subarea_list = request.POST.getlist('subarea_list') if not subarea_list: subarea_default_save = request.POST.get('subarea_default_save') subarea_list.append(subarea_default_save) u_config_description = config_list.get_description(config_name) data['config_title'] = u_config_description 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(sconfig_name) 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])) for subarea in subarea_list: sconfig_name = config_list.get_configname_by_subarea(config_name,subarea) config = Config.get(sconfig_name) if not config: config = Config.create(sconfig_name) before_config_data = config.data config_value = request.POST['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) config.put() config_update(subarea, config_name) moderator = apps.admin.auth.get_moderator_by_request(request) log_data = {} diff_result = diff_2_str(config.data, before_config_data) if diff_result: log_data['diff'] = diff_result log_data['subarea'] = subarea log_data['config_name'] = config_name log_data['before_config'] = before_config_data log_data['after_config'] = config_value log_data["username"] = moderator.username ConfigHistory.set_log(**log_data) data['config_value'] = config_value data['config_title'] = u_config_description data['subareas_conf'] = return_subareas_conf data['saved'] = True data['submit_game_settings_by_excel'] = True return render_to_response('admin/game_setting.html',data,context_instance = RequestContext(request))
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
from django.core.management import setup_environ setup_environ(settings) this_config_name = '' config_path = '' assert len(sys.argv) >= 2, 'no config_file' config_path = os.path.join(cur_dir, sys.argv[1]) assert os.path.exists(config_path), '!!!Can find COnfigfile!!' if len(sys.argv) == 3: this_config_name = sys.argv[2] from apps.models.config import Config config_dict = ast.literal_eval(open(config_path, "r").read()) for sconfig_name in config_dict: print "*Find config ", sconfig_name, "*This_config", this_config_name if this_config_name and this_config_name != sconfig_name: continue print "** load :", sconfig_name config = Config.get(sconfig_name) if not config: config = Config.create(sconfig_name) config_value = config_dict[sconfig_name] config.data = config_value config.put() print "****** load config Success!!"
def save_game_settings(request): ''' 保存配置, 多个分区的 subarea_list ''' data = {} config_value = '' config_name = request.GET.get('config_name', '') subarea_list = request.POST.getlist('subarea_list') if not subarea_list: subarea_default_save = request.POST.get('subarea_default_save') subarea_list.append(subarea_default_save) u_config_description = config_list.get_description(config_name) data['config_title'] = u_config_description 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(sconfig_name) 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])) for subarea in subarea_list: sconfig_name = config_list.get_configname_by_subarea( config_name, subarea) config = Config.get(sconfig_name) if not config: config = Config.create(sconfig_name) before_config_data = config.data config_value = request.POST['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) config.put() config_update(subarea, config_name) moderator = apps.admin.auth.get_moderator_by_request(request) log_data = {} diff_result = diff_2_str(config.data, before_config_data) if diff_result: log_data['diff'] = diff_result log_data['subarea'] = subarea log_data['config_name'] = config_name log_data['before_config'] = before_config_data log_data['after_config'] = config_value log_data["username"] = moderator.username ConfigHistory.set_log(**log_data) data['config_value'] = config_value data['config_title'] = u_config_description data['subareas_conf'] = return_subareas_conf data['saved'] = True data['submit_game_settings_by_excel'] = True return render_to_response('admin/game_setting.html', data, context_instance=RequestContext(request))
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