Skip to content

Instantly share code, notes, and snippets.

@jdunck
Last active August 29, 2015 14:10
Show Gist options
  • Save jdunck/2eae256ec800e82b537a to your computer and use it in GitHub Desktop.
Save jdunck/2eae256ec800e82b537a to your computer and use it in GitHub Desktop.
Find old-style (pre django 1.5) {% url %} tags
"""Given a list of files, print out the file extensions"""
import sys
for l in sys.stdin:
print l[:-1].rsplit('.')[-1]
Find: "\{\%\W*url +([-_a-zA-Z:0-9]+)\W"
Replace: "{% url '\1' "
(Don't forget you'll also need
{% load url from future %} if on 1.5.
----
If you'd like to whittle the tree down to just files that could possibly have old-style urls:
Find files in tree that have the {% url tag in them at all:
# find filenames with "{% url " or "{%url " (since both work).
$ grep --binary-file=without-match --ignore-case --recursive --files-with-matches --extended-regexp '\{\% ?url' * > file-list
# strip that list down to just extensions:
$ python ../../ext.py < file-list > matching-extensions
# find the extensions that need to be searched/replaced:
$ (sort --ignore-case matching-extensions | uniq ) < matching-extensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment