Include input file path in error messages.

This commit is contained in:
Michael Schwarz 2015-09-30 18:12:10 +02:00
parent 9f3e7bf14d
commit 39be44f16d
2 changed files with 41 additions and 34 deletions

View file

@ -34,21 +34,24 @@ def _asymptote(in_path, out_path, asymptote_dir, working_dir):
@util.main
def main(in_path, out_path):
_, out_suffix = os.path.splitext(out_path)
with util.TemporaryDirectory() as temp_dir:
absolute_in_path = os.path.abspath(in_path)
temp_out_path = os.path.join(temp_dir, 'out.pdf')
try:
_, out_suffix = os.path.splitext(out_path)
# Asymptote creates A LOT of temp files (presumably when invoking LaTeX) and leaves some of them behind. Thus we run asymptote in a temporary directory.
loaded_files = _asymptote(absolute_in_path, 'out', os.path.dirname(absolute_in_path), temp_dir)
if not os.path.exists(temp_out_path):
raise util.UserError('Asymptote did not generate a PDF file for input file {}.', in_path)
# All dependencies as paths relative to the project root.
dependencies = set(map(os.path.relpath, loaded_files))
# Write output files.
make.write_dependencies(out_path + '.d', out_path, dependencies - { in_path })
shutil.copyfile(temp_out_path, out_path)
with util.TemporaryDirectory() as temp_dir:
absolute_in_path = os.path.abspath(in_path)
temp_out_path = os.path.join(temp_dir, 'out.pdf')
# Asymptote creates A LOT of temp files (presumably when invoking LaTeX) and leaves some of them behind. Thus we run asymptote in a temporary directory.
loaded_files = _asymptote(absolute_in_path, 'out', os.path.dirname(absolute_in_path), temp_dir)
if not os.path.exists(temp_out_path):
raise util.UserError('Asymptote did not generate a PDF file.', in_path)
# All dependencies as paths relative to the project root.
dependencies = set(map(os.path.relpath, loaded_files))
# Write output files.
make.write_dependencies(out_path + '.d', out_path, dependencies - { in_path })
shutil.copyfile(temp_out_path, out_path)
except util.UserError as e:
raise util.UserError('While processing {}: {}', in_path, e)

View file

@ -38,22 +38,26 @@ def _unfuck_svg_document(temp_svg_path):
@util.main
def main(in_path, out_path):
_, out_suffix = os.path.splitext(out_path)
with util.TemporaryDirectory() as temp_dir:
temp_svg_path = os.path.join(temp_dir, os.path.basename(in_path))
try:
_, out_suffix = os.path.splitext(out_path)
shutil.copyfile(in_path, temp_svg_path)
_unfuck_svg_document(temp_svg_path)
export_effect = effect.ExportEffect()
export_effect.affect(args = [temp_svg_path], output = False)
with open(out_path, 'w') as file:
if out_suffix == '.dxf':
export_effect.write_dxf(file)
elif out_suffix == '.asy':
export_effect.write_asy(file)
else:
raise Exception('Unknown file type: {}'.format(out_suffix))
with util.TemporaryDirectory() as temp_dir:
temp_svg_path = os.path.join(temp_dir, os.path.basename(in_path))
shutil.copyfile(in_path, temp_svg_path)
_unfuck_svg_document(temp_svg_path)
export_effect = effect.ExportEffect()
export_effect.affect(args = [temp_svg_path], output = False)
with open(out_path, 'w') as file:
if out_suffix == '.dxf':
export_effect.write_dxf(file)
elif out_suffix == '.asy':
export_effect.write_asy(file)
else:
raise Exception('Unknown file type: {}'.format(out_suffix))
except util.UserError as e:
raise util.UserError('While processing {}: {}', in_path, e)