Created
August 15, 2017 15:28
-
-
Save Perif/68f1531553837c62d4e92370378029a7 to your computer and use it in GitHub Desktop.
Quick and dirty config reader for check_config on docker compatibility script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use it on output : https://raw.githubusercontent.com/moby/moby/master/contrib/check-config.sh | |
import re | |
section = '^([A-Z][a-zA-Z0-9_ ]+)+(?:)' | |
subsection = '"([^"]*)"' | |
category = '([A-Z0-9_]+[A-Z]+)' | |
fname='test.txt' | |
with open(fname) as f: | |
content = f.readlines() | |
# you may also want to remove whitespace characters like `\n` at the end of each line | |
content = [x.strip() for x in content] | |
for l in content: | |
if len(l.strip()) == 0: | |
continue | |
if re.findall(section,l): | |
print '>', re.findall(section,l)[0] | |
if re.findall(subsection,l): | |
print '-', re.findall(subsection,l)[0] | |
if re.findall(category,l): | |
activated = 0 if 'missing' in l else 1 | |
print "%35s : %d" %(re.findall(category,l)[0], activated) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment