Skip to content

Instantly share code, notes, and snippets.

@artursapek
Created November 9, 2013 19:42
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 artursapek/7389026 to your computer and use it in GitHub Desktop.
Save artursapek/7389026 to your computer and use it in GitHub Desktop.
Super primitive. Expects one class per line. Did the job
from subprocess import Popen, PIPE
import sys
import re
import os
APP_DIR = '/Users/artur/Work/Codecademy-dev/Codecademy/app/'
VIEWS = ['erb', 'mustache', 'haml']
def search(query, filetypes=[]):
args = ['grep', '-r', '-I', '--exclude=".git"']
if len(filetypes) > 0:
args.append('--include=*.{%s}' % ','.join(filetypes))
args += [query, APP_DIR]
return os.popen(' '.join(args)).readlines()
def main(argv):
with open(argv[0]) as deprecate:
contents = deprecate.readlines()
remove_us = []
classnames = re.findall(r'\.[\w\-\_]+', '\n'.join(contents))
for name in classnames:
if len(name) < 3:
continue
matches = search(name[1:], VIEWS)
num = len(matches)
print "%s matches for %s" % (num, name[1:])
if num > 0:
files_matching = map(lambda x: re.match(r'.*:', x), matches)
print '\n'.join(matches)
else:
remove_us.append(name)
print remove_us
new_contents = []
for line in contents:
if reduce(lambda a, x: a or (x[1:] in line), remove_us, False):
pass # Removing
else:
# Keeping
new_contents.append(line)
with open('%s.new' % argv[0], 'w') as updated:
updated.writelines(new_contents)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment