python的一些代码

# -*- 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)
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值