-
-
Save MarkusH/838f07e540faaf9ec528 to your computer and use it in GitHub Desktop.
Revisions
-
MarkusH renamed this gist
Apr 28, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
MarkusH revised this gist
Apr 28, 2015 . 1 changed file with 14 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,19 @@ #!/usr/bin/env python3 """ From @pydanny at https://gist.github.com/pydanny/ddf965bbec415084fb6d Git Integration =============== 1. Move .git/hooks/pre-commit.sample to .git/hooks/pre-commit 2. Add:: ./hackychecktitlecase.py exit $? after the leading comments to prevent commits of "invalid" headlines. """ import glob @@ -76,4 +89,4 @@ def main(): if __name__ == "__main__": sys.exit(main()) -
MarkusH revised this gist
Apr 28, 2015 . 1 changed file with 19 additions and 21 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,8 @@ import re import sys from collections import defaultdict try: from titlecase import titlecase except ImportError: @@ -39,15 +41,12 @@ def clean_line(line): def main(): fixes = defaultdict(list) for file in glob.glob("content/*.tex"): with open(file) as f: lines = f.readlines() for lineno, line in enumerate(lines, 1): match = re.match(regex, line) if match is None: @@ -57,25 +56,24 @@ def main(): continue new_line = titlecase(line) if new_line != line: fixes[file].append((lineno, line, new_line)) if fixes: print('There are titlecase errors') print('=' * 79) for file, changes in fixes.items(): print(file) for lineno, line, new_line in changes: print('-' * 79) print('#: %d' % lineno) print('-: %s' % line) print('+: %s' % new_line) print('=' * 79) return 1 print('No titlecase errors :)') return 0 if __name__ == "__main__": sys.exit(main()) -
MarkusH revised this gist
Apr 27, 2015 . 1 changed file with 39 additions and 16 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,22 @@ #!/usr/bin/env python3 """ From @pydanny at https://gist.github.com/pydanny/ddf965bbec415084fb6d """ import glob import re import sys try: from titlecase import titlecase except ImportError: print("Please install titlecase") regex = re.compile(r'\\(section|subsection|subsubsection)', re.IGNORECASE) EXEMPTS = () def exempter(line): for exempt in EXEMPTS: if line.startswith(exempt): @@ -21,9 +25,12 @@ def exempter(line): def clean_line(line): line = line.replace('\\section{', '') line = line.replace('\\subsection{', '') line = line.replace('\\subsubsection{', '') line = line.replace('\\section*{', '') line = line.replace('\\subsection*{', '') line = line.replace('\\subsubsection*{', '') line = line.replace('}', '') line = line.replace('[', '') line = line.replace(']', ' ') @@ -32,15 +39,16 @@ def clean_line(line): def main(): needs_fixes = False for file in glob.glob("content/*.tex"): with open(file) as f: lines = f.readlines() print('=' * 79) print(file) for lineno, line in enumerate(lines, 1): match = re.match(regex, line) if match is None: continue @@ -49,10 +57,25 @@ def main(): continue new_line = titlecase(line) if new_line != line: needs_fixes = True print('-' * 79) print('Line %d' % lineno) print('OLD: %s' % line) print('NEW: %s' % new_line) print('=' * 79) return needs_fixes if __name__ == "__main__": sys.exit(main()) ### Git Integration: # 1. Move .git/hooks/pre-commit.sample to .git/hooks/pre-commit # 2. Add: # ./hackychecktitlecase.py # exit $? # after the leading comments to prevent commits of "invalid" headlines. ### -
pydanny created this gist
Apr 25, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ 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()