本文整理汇总了Python中myutils.BetterConfigParser.items方法的典型用法代码示例。如果您正苦于以下问题:Python BetterConfigParser.items方法的具体用法?Python BetterConfigParser.items怎么用?Python BetterConfigParser.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类myutils.BetterConfigParser
的用法示例。
在下文中一共展示了BetterConfigParser.items方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: diffConfigFile
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import items [as 别名]
def diffConfigFile(tag1, tag2, fileName):
print("file:", fileName)
config1 = BetterConfigParser()
config2 = BetterConfigParser()
config1.read(tag1 + 'config/' + fileName)
config2.read(tag2 + 'config/' + fileName)
sections = list(set(config1.sections() + config2.sections()))
commonSections = [x for x in sections if x in config1.sections() and x in config2.sections()]
print("common sections:", commonSections)
for section in commonSections:
firstItemInSection = True
items1d = {x[0]:x[1] for x in config1.items(section, raw=True)}
items2d = {x[0]:x[1] for x in config2.items(section, raw=True)}
items1 = [x[0] for x in config1.items(section, raw=True)]
items2 = [x[0] for x in config2.items(section, raw=True)]
items = list(set(items1 + items2))
commonItems = list(set([x for x in items if x in items1 and x in items2]))
for item in commonItems:
if item not in os.environ:
try:
item1 = config1.get(section, item)
item2 = config2.get(section, item)
item1 = items1d[item]
item2 = items2d[item]
if item1 != item2:
if firstItemInSection:
firstItemInSection = False
print('-'*80)
print(' \x1b[34m' + fileName + '\x1b[0m: ' + section)
print('-'*80)
print(section + ':' + item)
d = difflib.Differ()
result = list(d.compare([item1], [item2]))
for line in result:
if line.startswith('+'):
color = '\x1b[31m'
elif line.startswith('-'):
color = '\x1b[32m'
elif line.startswith('?'):
color = '\x1b[34m'
print(' '+color+line+'\x1b[0m')
except Exception as e:
pass