Created
December 12, 2013 16:52
-
-
Save mundry/7931214 to your computer and use it in GitHub Desktop.
Script to accumulate exclusion patterns for files and folders used in Sublime Text project files.
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
#!/usr/bin/env python | |
from collections import OrderedDict | |
from json import loads | |
SUBLIME_CONFIG_FILES = ['...'] | |
file_exclude_patterns = [] | |
folder_exclude_patterns = [] | |
def mapfn(): | |
for config_file in SUBLIME_CONFIG_FILES: | |
config = None | |
with open(config_file) as fin: | |
config = loads(fin.read()) | |
if 'folders' in config: | |
folders = config['folders'] | |
for folder in folders: | |
if 'folder_exclude_patterns' in folder: | |
folder_exclude_patterns.extend(folder['folder_exclude_patterns']) | |
if 'file_exclude_patterns' in folder: | |
file_exclude_patterns.extend(folder['file_exclude_patterns']) | |
def reducefn(data): | |
reduced = {} | |
for d in data: | |
if d in reduced: | |
reduced[d] += 1 | |
else: | |
reduced[d] = 1 | |
return reduced | |
mapfn() | |
file_exclude_patterns_reduced = OrderedDict(sorted(reducefn(file_exclude_patterns).items())) | |
folder_exclude_patterns_reduced = OrderedDict(sorted(reducefn(folder_exclude_patterns).items())) | |
print 'File exclude patterns:' | |
for pattern, count in file_exclude_patterns_reduced.iteritems(): | |
print '{}{}'.format(pattern, '{}'.format(' (x{})'.format(count) if count > 1 else '')) | |
print '\nFolder exclude patterns:' | |
for pattern, count in folder_exclude_patterns_reduced.iteritems(): | |
print '{}{}'.format(pattern, '{}'.format(' (x{})'.format(count) if count > 1 else '')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment