Created
November 27, 2012 19:00
-
-
Save pudquick/4156268 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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