Skip to content

Commit 7fc16e7

Browse files
committed
Update preprocess.py to Python 3
1 parent fe3e900 commit 7fc16e7

3 files changed

Lines changed: 26 additions & 26 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PDFLATEX=pdflatex -shell-escape
33
all: comprog.pdf
44

55
comprog.pdf: comprog.tex
6-
python2 preprocess.py
6+
python3 preprocess.py
77
$(PDFLATEX) comprog
88
$(PDFLATEX) comprog
99
$(PDFLATEX) comprog

comprog.pdf

31.5 KB
Binary file not shown.

preprocess.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
def mkhash(dat):
99
conc = ""
1010
for i in dat:
11-
conc += re.sub('\s*', '', i) + "\n"
12-
yield hashlib.md5(conc.decode('utf8')).hexdigest()[:2]
11+
conc += re.sub(r'\s*', '', i) + "\n"
12+
yield hashlib.md5(conc.encode('utf8')).hexdigest()[:2]
1313

1414
for path, dirs, files in os.walk('./code'):
1515
for f in files:
@@ -23,31 +23,31 @@ def mkhash(dat):
2323
pass
2424

2525
dat = [ line for line in open(p).read().splitlines() if not line.startswith('// vim: ') and not line.startswith('# vim: ') ]
26-
out = open(q, 'w')
2726

28-
warning = False
29-
error = False
30-
last = False
31-
for dat, hash in zip(dat, mkhash(dat)):
27+
with open(q, 'w') as out:
28+
warning = False
29+
error = False
3230
last = False
33-
s = dat.lstrip(' ')
34-
add = len(dat) - len(s)
35-
if add > 0:
36-
s = ' ' + s
37-
add -= 1
38-
s = '-'*add + s
39-
if(len(s) > MARGIN):
40-
print>>out, s
41-
warning = True
42-
last = True
43-
if len(s) > MARGIN+4:
44-
error = True
45-
print len(s), MARGIN
46-
print repr(s)
47-
else:
48-
if len(s) < MARGIN:
49-
s = s+' '
50-
print>>out, s.ljust(MARGIN, '-') + "//" + hash
31+
for dat, hash in zip(dat, mkhash(dat)):
32+
last = False
33+
s = dat.lstrip(' ')
34+
add = len(dat) - len(s)
35+
if add > 0:
36+
s = ' ' + s
37+
add -= 1
38+
s = '-'*add + s
39+
if(len(s) > MARGIN):
40+
out.write('%s\n' % s)
41+
warning = True
42+
last = True
43+
if len(s) > MARGIN+4:
44+
error = True
45+
print('%d %s' % (len(s), MARGIN))
46+
print(repr(s))
47+
else:
48+
if len(s) < MARGIN:
49+
s = s+' '
50+
out.write('%s//%s\n' % (s.ljust(MARGIN, '-'), hash))
5151

5252
if last:
5353
error = True

0 commit comments

Comments
 (0)