-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_document
executable file
·89 lines (75 loc) · 1.91 KB
/
build_document
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
def font(name, size=12):
return f"""/{name} findfont
{size} scalefont
setfont
"""
def pos(x,y):
return f"""{x} {y} moveto"""
def text(s):
s = ''.join([hex(c)[2:] for c in s.encode()])
return f"""<{s}> show"""
cur_y = 740
num_pages = 1
def nextline():
global cur_y, num_pages
cur_y -= 12
if cur_y <= 80:
cur_y = 740
num_pages += 1
return "showpage"
return ""
truncated = False
def snip():
global cur_y
return f""" {font("TimesNew-Bold")}
newpath
{pos(70, cur_y)}
{text("--8<-- REPORT LONGER THAN 10 PAGES! TRUNCATED! --8<--")}
"""
def is_too_long():
global num_pages, cur_y
return num_pages >= 10 and cur_y <= 100 # near the end of the tenth page
def section(heading, body):
global cur_y, num_pages, truncated
if truncated:
return ""
if body.strip() == '':
return ""
res= f"""{font("TimesNew-Bold")}
newpath
{pos(70, cur_y)}
{text(heading)}
{font("Calibri")}
"""+nextline()
for l in body.split('\n'):
while len(l) > 60:
a, l = l[0:60],l[60:]
res += f"""
{pos(100, cur_y)}
{text(a)}
"""+nextline()
if is_too_long():
truncated = True
res += snip()
return res
res += f"""
{pos(100, cur_y)}
{text(l)}
"""+nextline()
if is_too_long():
truncated = True
res += snip()
return res
return res
doc = f"""
{section("Request", open("outputs/request").read())}
{section("Result Summary", open("outputs/summary").read())}
{section("Compiler Stdout", open("outputs/compilation_stdout").read())}
{section("Compiler Stderr", open("outputs/compilation_stderr").read())}
{section("Program Stdout", open("outputs/program_stdout").read())}
{section("Program Stderr", open("outputs/program_stderr").read())}
showpage
"""
with open("result.ps", "w+") as f:
f.write(doc)