Skip to content
Snippets Groups Projects
Commit 085c42c5 authored by tuhe's avatar tuhe
Browse files

testing again

parent 6a1d695e
Branches
No related tags found
No related merge requests found
Pipeline #7538 failed
......@@ -63,6 +63,7 @@ def pdf2png(fin, fout=None, scale_to=None, page_to_convert=None):
if scale_to is not None:
cmd += f" -scale-to {scale_to}"
execute_command(cmd.split())
return fout + ".png"
......
......@@ -22,6 +22,11 @@ def fix_handout(s):
s = s[:j2 + 1] + "[handout]" + s[j2 + 1:]
return s
def _get_osvg_labels():
pass
def set_svg_background_images(lecture_tex, verbose=False,
fix_broken_osvg_files=False,
recompile_on_change=True,
......@@ -43,6 +48,14 @@ def set_svg_background_images(lecture_tex, verbose=False,
SVG_TMP_DIR = MAIN_TEX_DIR + "/" + SVG_EDIT_RELPATH + "/" + SVG_TMP_RELPATH
SVG_OSVG_DIR = MAIN_TEX_DIR + "/" + SVG_EDIT_RELPATH
force_fix_broken_osvg_files = [] if force_fix_broken_osvg_files is None else force_fix_broken_osvg_files
NO_SVG_TMP_DIR = SVG_TMP_DIR + "/no_svg_tmp"
# if not os.path.isdir(NO_SVG_TMP_DIR):
# os.mkdir(NO_SVG_TMP_DIR)
if os.path.isdir(NO_SVG_TMP_DIR):
for f in glob.glob(MAIN_TEX_DIR + "/*_NO_SVGS.*"):
shutil.move(f, MAIN_TEX_DIR + "/" + os.path.basename(f))
print("Slider is setting the background images for the .tex. file\n> %s" % os.path.abspath(lecture_tex))
if copy_template_resource_files:
......@@ -107,7 +120,6 @@ def set_svg_background_images(lecture_tex, verbose=False,
lecture_tex_nosvg_pdf = lecture_tex_nosvg[:-4] + ".pdf"
# lecture_tex_nosvg_tex = recursive_tex_apply(lecture_tex_nosvg)
if cache_contains_str(MAIN_TEX_DIR, key='all_tex', value=all_tex) and os.path.exists(lecture_tex_nosvg_pdf):
print("slider> Cache contains nosvg tex file")
......@@ -176,26 +188,27 @@ def set_svg_background_images(lecture_tex, verbose=False,
if clean_temporary_files:
if verbose:
print("> SlideConverter: Removing temporary dirs...")
print("> Slider: Removing temporary dirs...")
# raise Exception()
DNE = SVG_OSVG_DIR + "/do_not_edit"
if os.path.exists(SVG_TMP_DIR):
for v in glob.glob(SVG_TMP_DIR + "/*"):
for v in glob.glob(SVG_TMP_DIR + "/*.svg"):
if not v.endswith("png"):
os.remove(v)
if os.path.isdir(DNE):
shutil.rmtree(DNE)
if not os.path.isdir(NO_SVG_TMP_DIR):
os.mkdir(NO_SVG_TMP_DIR)
# for v in glob.glob(SVG_OSVG_DIR + "/x_do_not_edit*.pdf"):
for f in glob.glob(MAIN_TEX_DIR +"/*_NO_SVGS.*"):
shutil.move(f, NO_SVG_TMP_DIR +"/" + os.path.basename(f))
# if os.path.exists(DNE):
# for v in glob.glob(DNE + "/*"):
# if not v.endswith("png"):
# os.remove(v)
# Not sure I want to do add this as an option right now. It makes everything slower...
# for f in glob.glob(lecture_tex[:-4] + '_NO_SVGS*'):
# os.remove(f)
if os.path.exists(DNE):
for v in glob.glob(DNE + "/*"):
if not v.endswith("png"):
os.remove(v)
a = 234
def slide_no_by_text(pdf_file, text):
assert False
......
import os
# import pytest
import numpy as np
from PIL import Image
from unittest import TestCase
......@@ -8,9 +7,6 @@ import os
import subprocess
from slider.convert import pdf2png
from slider.slider_cli import slider_cli
# import sys
# sys.path.append(os.path.dirname(os.path.abspath(__file__)) +"/../src")
def assert_images_equal(image_1: str, image_2: str):
img1 = Image.open(image_1)
......@@ -64,11 +60,6 @@ class TestSlider(TestCase):
s = f.read()
i = s.find("</svg>")
ss = s[:i] + RECT1 + RECT2 + s[i:]
# pieces = s.split("</svg>")
# ss = s.replace("</svg>", RECT + "</svg>")
# ss = pieces[0] + "<g>" + + pieces[1]
with open(fn, 'w') as f:
f.write(ss)
slider_cli("automatic/index.tex", interactive=False)
......@@ -98,15 +89,26 @@ class TestConverter(TestCase):
# Generate the output files.
if os.path.isdir("./converted"):
shutil.rmtree("./converted")
# if os.path.isdir("./test_images"):
# shutil.rmtree("./test_images")
os.mkdir("converted")
shutil.copyfile("slideshow.pdf", "converted/slideshow.pdf")
from slider.slider_cli import slider_converter_cli
slider_converter_cli("converted/slideshow.pdf")
pdf2png("converted/slideshow_converted.pdf", fout="converted/converted_10.png", page_to_convert=10)
out = pdf2png("converted/slideshow_converted.pdf", fout="converted/converted_10.png", page_to_convert=10)
print("output file was", os.path.abspath(out), "exists?", os.path.isfile(out))
print("Current directory is", os.getcwd())
print("Content of current dir is")
import glob
for f in glob.glob("./*"):
print(f)
print("Content of tests_images is")
shutil.copyfile("converted/converted_10.png", "tests_images/converted_10.png")
# pdf2png("automatic/index.pdf", fout="automatic/index_b.png", page_to_convert=2)
# shutil.copyfile("automatic/index_a.png", "tests_images/index_a.png")
# shutil.copyfile("automatic/index_b.png", "tests_images/index_b.png")
# shutil.copyfile("automatic/index_a.png", "tests_images/index_a.png")
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment