Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created November 27, 2012 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pudquick/4156268 to your computer and use it in GitHub Desktop.
Save pudquick/4156268 to your computer and use it in GitHub Desktop.
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