-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.py
152 lines (130 loc) · 3.16 KB
/
builder.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import code_parser
import os
import sys
options = {
'number_of_columns': 2,
'characters_in_a_row': 80,
'expandtab': 2,
'width': 297,
'height': 210,
'margin_top': 8,
'margin_bottom': 11,
'margin_left': 8,
'margin_middle': 4,
'margin_right': 8,
'big_letter_box_percent': 0.8,
'big_letter_size_percent': 0.7,
'big_letter_colors': {
'C': (0.2, 0.2, 0.2),
'B': (0.7, 0, 0),
'DS': (0.7, 0.3, 0),
'F&M': (0.7, 0.7, 0),
'Ge': (0, 0.7, 0),
'Gr': (0, 0.7, 0.7),
'M': (0, 0, 0.7),
'Mi': (0.3, 0, 0.7),
'NT': (0.4, 0.4, 0.4),
'S': (0.4, 0.3, 0.2),
'T': (0.6, 0.6, 0.6),
},
'big_letter_font': {
'is_bold': True,
'color': (1, 1, 1),
},
'header_decorations': {
'is_bold': True,
'color': (0, 0, 0),
'bg_color': (0, 1, 0, 0.5),
'border_color': (0, 0, 0),
},
'right_wrap_decorations': {
'is_bold': True,
'color': (1, 1, 1),
'bg_color': (1, 0, 0),
},
'left_wrap_decorations': {
'is_bold': True,
'color': (1, 1, 1),
'bg_color': (0, 0, 1),
},
'page_number_decorations': {
'is_italic': True,
'color': (0, 0, 0),
},
'date_decorations': {
'is_italic': True,
'color': (0, 0, 0),
},
'page_summary_decorations': {
'is_italic': True,
'color': (0, 0, 0),
},
'latex_options': {
'input_tex': "???",
'width': "???",
'zoom': 2.5,
'border': (5, # Left.
5, # Bottom.
5, # Right.
5), # Top.
},
}
def CheckFileType(filename):
if filename.endswith('.cpp'):
return (filename, 'C++', 'default')
elif filename.endswith('.tex'):
return (filename, 'LaTeX', 'default')
else:
return (filename, 'text', 'default')
def FindAllSourceCode(code_dir):
sources = []
for (dirpath, dirnames, filenames) in os.walk(code_dir):
for filename in filenames:
path = os.path.join(dirpath, filename)
file_type = CheckFileType(path)
if file_type:
sources.append(file_type)
return sources
if len(sys.argv) != 3:
print("Usage: {} code_dir/ output.pdf".format(sys.argv[0]))
sys.exit(1)
options['code_dir'] = sys.argv[1]
options['output_pdf'] = sys.argv[2]
cp = code_parser.CodeParser(options)
files = []
try:
with open('FILES', 'r') as f:
all_sources = [CheckFileType(x) for x in f.read().split('\n') if x.strip() and x.strip()[0] != '#']
from_file = True
except FileNotFoundError:
all_sources = FindAllSourceCode(options['code_dir'])
from_file = False
for filename, lang, style in all_sources:
files.append({"filename": filename,
"lang": lang,
"style": style})
def key_to_compare(f):
global options
filename = os.path.relpath(f["filename"], options["code_dir"])
directory = os.path.dirname(filename)
basename = os.path.basename(filename)
if directory == "":
dir_weight = 0
if basename == "geany-config":
basename = "1"
if basename == "makra.cpp":
basename = "2"
elif basename == "Rzeczy_Na_Dzien_Probny.cpp":
basename = "3"
else:
print(f'{f = }', file=sys.stderr);
# assert False
return (directory, basename.lower())
if not from_file:
files.sort(key=key_to_compare)
for f in files:
new_options = dict(options)
new_options['lang'] = f['lang']
new_options['style'] = f['style']
cp.AddCodeFile(f['filename'], new_options)
cp.GeneratePdf(options)