Chinaunix首页 | 论坛 | 博客
  • 博客访问: 628862
  • 博文数量: 149
  • 博客积分: 3901
  • 博客等级: 中校
  • 技术积分: 1558
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-16 14:33
文章分类

全部博文(149)

文章存档

2014年(2)

2013年(10)

2012年(32)

2011年(21)

2010年(84)

分类: Python/Ruby

2010-07-07 16:23:06




代码:

#!/usr/bin/python
#encoding: utf-8
import ConfigParser,os,sys
import traceback
import datetime

config_path = "/data/shell/gmodel/pengyou/conf/"


def getConfig(ttime=datetime.datetime.now().strftime("%Y-%m-%d"),
                thour=datetime.datetime.now().strftime("%H")):
    config = {}
    rp={"@Y":ttime.split('-')[0],
        "@M":ttime.split('-')[1],
        "@D":ttime.split('-')[2],
        "@H":thour,
    }
    for root, dirs, files in os.walk(config_path):
        for file in files :
            try :
                ft = '.conf'
                if ft in file and file.index(ft) >0 and len(file)-len(ft) == file.index(ft) :
                    configObj = ConfigParser.RawConfigParser()
                    configObj.optionxform=str
                    configObj.read(root+'/'+file)
                    for sc in configObj.sections() :
                        if config.has_key( sc ) : print " Conflict - "+sc
                        config[ sc ] = {}
                        for k,v in configObj.items(sc) :
                            for rk in rp.keys():
                                v=v.replace(rk,rp[rk])
                            config[ sc ][ k ] = v
            except :
                exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
                traceback.print_exception(exceptionType, exceptionValue, exceptionTraceback,limit=2)
    return config


阅读(821) | 评论(0) | 转发(0) |
0

上一篇:python 日志 输出

下一篇:vim pydiction 插件

给主人留下些什么吧!~~