Skip to content

Instantly share code, notes, and snippets.

@mundry
Created December 12, 2013 16:52
Show Gist options
  • Save mundry/7931214 to your computer and use it in GitHub Desktop.
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.
#!/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