163 input_path = os.path.normpath(input_path)
164 if input_path
in visited_set:
165 print(
'Circular inclusion %s, ignoring' % input_path, file=sys.stderr)
167 visited_set.add(input_path)
169 _, file_extension = os.path.splitext(input_path)
170 override_line_endings = (file_extension
in EXTENSION_OVERRIDE_LINE_ENDINGS)
172 end_of_file_line_ending =
False
173 with open(input_path,
'rb')
as infile:
175 match = re.match(b
'\s*\{\{include\s+(.+)\}\}', line)
179 os.path.dirname(input_path),
180 match.group(1).
decode(
'utf-8')), output_file, visited_set)
182 if override_line_endings:
184 if line.endswith(WINDOWS_LINE_ENDING):
185 line = line[:-len(WINDOWS_LINE_ENDING)] + UNIX_LINE_ENDING
186 end_of_file_line_ending =
True
188 end_of_file_line_ending = line.endswith(UNIX_LINE_ENDING)
189 output_file.write(line)
192 if not end_of_file_line_ending:
193 output_file.write(UNIX_LINE_ENDING)
195 print(
'failed to include %s' % input_path, file=sys.stderr)
197 visited_set.discard(input_path)
201 parser = optparse.OptionParser()
202 parser.add_option(
'--output-dir', default=
'')
203 options, args = parser.parse_args()
204 for testcase_path
in args:
205 testcase_filename = os.path.basename(testcase_path)
206 testcase_root, _ = os.path.splitext(testcase_filename)
207 output_dir = os.path.dirname(testcase_path)
208 if options.output_dir:
209 output_dir = options.output_dir
210 intermediate_stream = io.BytesIO()
212 intermediate_stream.seek(0)
213 output_path = os.path.join(output_dir, testcase_root +
'.pdf')