Skip to content

Instantly share code, notes, and snippets.

@davidszotten
Created May 18, 2017 09:47
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 davidszotten/4c103815e2dfa6b5f0bdabf2969f3e19 to your computer and use it in GitHub Desktop.
Save davidszotten/4c103815e2dfa6b5f0bdabf2969f3e19 to your computer and use it in GitHub Desktop.
import re
import sys
def finder(sourcelines):
result = []
inside = False
for line in sourcelines:
match = re.match(r"""(\w+) = patterns\(""", line)
if match:
inside = True
name = match.groups()[0]
result.append('{} = ['.format(name))
elif inside and re.match(r'\s*\)', line):
result.append(']')
inside = False
elif inside and re.match(r"""\s*(''|""),""", line):
pass
elif line == 'from django.conf.urls import patterns, url':
result.append('from django.conf.urls import url')
else:
result.append(line)
if inside:
result.append('qqDS') # find and fix manually
return result
def main():
filename = sys.argv[1]
with open(filename) as handle:
source = handle.read()
sourcelines = source.splitlines()
with open(filename, 'w') as handle:
handle.write('\n'.join(finder(sourcelines)) + '\n')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment