#getparameterlist.py
#程序功能 根据给定的文件,把相关的信息抓出来,形成一个参数配置报告
#功能待完善 目前只写了一部分

#!/usr/bin/python
# -*- coding:gbk -*-
import ConfigParser
import re
import os
import string
import xml.etree.ElementTree as ET

tree = ET.parse('xmlTest.xml')
root = tree.getroot()


def getpluginbylib(libname,par):
    for country in root.iter('plugin'):
        t=country.attrib
        if t.get("lib") == libname:
            for child in country.getchildren():
                 return child.attrib.get(par)
def line():
    print '--------------------------------------------------------------'

def logstring(loglevel):
   if  '0' == loglevel:
        logstring = '调试级别'
   if  '1' == loglevel:
        logstring = '一般级别'
   if  '2' == loglevel:
        logstring = '告警级别'
   if  '3' == loglevel:
        logstring = '错误级别'
   if  '4' == loglevel:
        logstring = '异常级别'
   return logstring

print '日志有关参数'
print '每个日志大小:' + getpluginbylib("cloud_dlog","max_file_size")
print '日志级别:' + logstring(getpluginbylib("cloud_dlog","default_level"))
print '日志路径:' + getpluginbylib("cloud_dlog","log_path")

line()

print 'F2参数'
print '对外端口:' + getpluginbylib("fsc_channel_f2","port")


def subgetpluginbylib(libname,par):
    for country in root.iter('plugin'):
        t=country.attrib
        if t.get("lib") == libname:
            for child in country.getchildren():
                 for subchild in child.getchildren():
                     return subchild.attrib.get(par)
line()
print "逻辑名:" + subgetpluginbylib("fsc_f2hsdb", "logic_name")
print "数据库名:" + subgetpluginbylib("fsc_f2hsdb", "data_source_type")
print "用户名:" + subgetpluginbylib("fsc_f2hsdb", "user_name")
print "密码:" + subgetpluginbylib("fsc_f2hsdb", "password")
print "心跳:" + subgetpluginbylib("fsc_f2hsdb", "heartbeat_time") + '毫秒'

line()
print "couchbase桶名:" + subgetpluginbylib("cloud_dcache", "bucket_name")
print "couchbase服务器IP" + subgetpluginbylib("cloud_dcache", "server")
print "密码:" + subgetpluginbylib("cloud_dcache", "passwd")

def InitConfigParser(inifilename):
    cp= ConfigParser.ConfigParser()
    cp.read(inifilename)
    return cp
line()
cp=InitConfigParser("t2sdk.ini")
print "task.ini文件配置"
print "服务器名称: " + cp.get("t2sdk", "servers")

line()
print "程序版本"
print "后台程序版本:"
# print os.system("dir ")


line()
print "mysql客户端配置【my.cnf】"
cp=InitConfigParser("my.cnf")
print "客户端字符编码:" + cp.get("client", "default-character-set")

line()


print '表同步的配置'

f= open('ta_mdb_cfg.xml')
try:
      for line in f:
          if re.match("tablename", line.replace('<','').replace('>','').replace('\"','').replace(' ','')):
            print line

finally:
     f.close()

注:附件放在七牛云存储上

测试文件附件下载

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐