# -*- encoding: utf-8 -*-
import ConfigParser
import os
import traceback
from bsa_qpwa_manage.bin.common import getLogger
logger = getLogger('bsa_qpwa_manage_appconf_data_model.log')
conf_file_path = os.environ["BASE_DIR"] + '/BSA/apps/bsa_qpwa_manage/conf/'
# def get_menuname():
# cf = ConfigParser.ConfigParser()
# path = "{}{}".format(conf_file_path, "app.conf")
# cf.read(path)
# menuname = cf.get("ui", "menuname")
#
# print menuname
# return menuname
#
#
# def change_menuname(new_name):
# cf = ConfigParser.ConfigParser()
# path = "{}{}".format(conf_file_path, "app.conf")
# cf.read(path)
# try:
# print new_name
# cf.set('ui', 'menuname', new_name)
# cf.write(open(path, "wb"))
# menuname = get_menuname()
# if new_name == menuname:
# return True
# else:
# return False
# except Exception as e:
# logger.error(traceback.format_exc())
# return False
#
#
# def restore_default_menuname():
# cf = ConfigParser.ConfigParser()
# path = "{}{}".format(conf_file_path, "app.conf")
# cf.read(path)
# try:
# cf.set('ui', 'menuname', "监管预警与处置")
# cf.write(open(path, "wb"))
# menuname = get_menuname()
# if menuname == "监管预警与处置":
# return True
# else:
# return False
# except Exception as e:
# logger.error(traceback.format_exc())
# return False
# 获取logo路径
def getLogoPath():
STATIC_URL = '/WebApi/'
base_name = os.environ["BASE_DIR"] + '/BSA/apps/bsa_qpwa_manage/'
static_path = os.path.join(STATIC_URL, 'bsa_qpwa_manage', 'static', 'styles', 'images')
# absolute_path = os.path.join(base_name, 'static', 'styles', 'images')
absolute_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static', 'styles', 'images')
return static_path, absolute_path
# 获取logo配置路径
def getLogoConfPath():
file_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + os.sep + 'conf/logo.conf'
# file_path = os.path.join(CONFIG_DIR, "logo.conf")
return file_path
# 获取xml中logo相关信息
def getLogoData():
file_path = getLogoConfPath()
rtn = {
'default_name': '监管预警与处置',
'name': '',
'default_logo': 'menuLogo.png',
'logo': ''
}
try:
conf = ConfigParser.ConfigParser()
conf.read(file_path)
rtn['default_logo'] = conf.get('logo_setting', 'default_logo')
rtn['logo'] = conf.get('logo_setting', 'logo')
rtn['default_name'] = conf.get('logo_setting', 'default_name')
rtn['name'] = conf.get('logo_setting', 'name')
except Exception, e:
logger.error(e)
return rtn
# 获取logo相关信息
def getLogoInfo():
logo_img_path, absolute_path = getLogoPath()
tmp_obj = getLogoData()
tmp_str = tmp_obj['logo'] if tmp_obj['logo'] else tmp_obj['default_logo']
logo_img_path = os.path.join(logo_img_path, tmp_str)
logo_name_text = tmp_obj['name'] if tmp_obj['name'] else tmp_obj['default_name']
return {'logo': logo_img_path, 'name': logo_name_text}
# 保存logo信息
def setLogoInfo(file, name):
file_path = getLogoConfPath()
logo_img_path, absolute_path = getLogoPath()
custom_logo_name = 'custom_logo.png'
try:
conf = ConfigParser.ConfigParser()
conf.read(file_path)
conf.set('logo_setting', 'name', name)
if file:
conf.set('logo_setting', 'logo', custom_logo_name)
data = file.read()
with open(os.path.join(absolute_path, custom_logo_name), 'w') as f:
f.write(data)
static_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), '..', '..', 'static', 'bsa_qpwa_manage', 'static',
'styles', 'images')
with open(os.path.join(os.path.abspath(static_path), custom_logo_name), 'w') as f:
f.write(data)
conf.write(open(file_path, 'w'))
except Exception, e:
logger.error(e)
# logo信息恢复默认
def resetLogoInfo():
file_path = getLogoConfPath()
try:
conf = ConfigParser.ConfigParser()
conf.read(file_path)
conf.set('logo_setting', 'logo', '')
conf.set('logo_setting', 'name', '')
conf.write(open(file_path, 'w'))
except Exception, e:
logger.error(e)