Skip to content

Instantly share code, notes, and snippets.

@pydanny
Created April 25, 2015 23:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pydanny/ddf965bbec415084fb6d to your computer and use it in GitHub Desktop.
Save pydanny/ddf965bbec415084fb6d to your computer and use it in GitHub Desktop.
The hacky script that I wrote to check the title case in Two Scoops of Django 1.8
import glob
import re
from os.path import join
import os
import shutil
try:
from titlecase import titlecase
except ImportError:
print "Please install titlecase"
regex = re.compile(r'\\(chapter|section|subsection)', re.IGNORECASE)
EXEMPTS = ()
def exempter(line):
for exempt in EXEMPTS:
if line.startswith(exempt):
return True
return line in EXEMPTS
def clean_line(line):
line = line.replace('\\chapter{', '')
line = line.replace('\\section{', '')
line = line.replace('\\subsection{', '')
line = line.replace('}', '')
line = line.replace('[', '')
line = line.replace(']', ' ')
line = line.strip()
return line
def main():
for chaptername in glob.glob("chapters/[0-9][0-9]*.tex"):
chap_number = chaptername[9:11]
with open(chaptername) as f:
lines = f.readlines()
for line in lines:
match = re.match(regex, line)
if match is None:
continue
line = clean_line(line)
if exempter(line):
continue
new_line = titlecase(line)
if new_line != line:
print "OLD: ", line
print "NEW: ", new_line
print "====================="
if __name__ == "__main__":
main()
@pydanny
Copy link
Author

pydanny commented Apr 25, 2015

Exempts are there to stop it from identifying:

Don't Use get\_user\_model() for Foreign Keys to User

as being marked for this:

Don't Use Get\_user\_model() for Foreign Keys to User

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment