Created
April 25, 2015 23:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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