Skip to content

Instantly share code, notes, and snippets.

@pudquick pudquick/process.py
Created Nov 27, 2012

Embed
What would you like to do?
import sys, os.path
settings_file = sys.argv[1]
id_list_file = sys.argv[2]
f = open(settings_file)
settings = f.read()
f.close()
f = open(id_list_file)
ids = f.read()
f.close()
# Get every line, split by new lines, otherwise unmodified
settings = [x for x in settings.split('\n')]
# Get every id, split by whitespace (newlines, tabs, spaces, etc.)
ids = ids.split()
mode = 0
for i, line in enumerate(settings):
# Only pay attention to lines with content
if line.strip():
if (mode == 0) and line.startswith('['):
# New block, see if id matches
if line.strip('[]') in ids:
# Block matches, start commenting
settings[i] = ';' + settings[i]
mode = 1
elif (mode == 1):
settings[i] = ';' + settings[i]
else:
# No content = end of block = reset mode
mode = 0
fname, fext = os.path.splitext(settings_file)
f = open(fname + '_out' + fext, 'w')
f.write('\n'.join(settings))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.