mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-05-20 03:57:38 +08:00
fix(convert): use hash to restrict the length of new filenames (#124)
Closes #123
This commit is contained in:
18
example.py
18
example.py
@ -32,6 +32,24 @@ class BasicExample(Slide):
|
||||
self.pause() # Waits user to press continue to go to the next slide
|
||||
|
||||
|
||||
class TestFileTooLong(Slide):
|
||||
"""This is used to check against solution for issue #123."""
|
||||
|
||||
def construct(self):
|
||||
import random
|
||||
|
||||
circle = Circle(radius=3, color=BLUE)
|
||||
dot = Dot()
|
||||
self.play(GrowFromCenter(circle), run_time=0.1)
|
||||
|
||||
for _ in range(30):
|
||||
direction = (random.random() - 0.5) * LEFT + (random.random() - 0.5) * UP
|
||||
self.play(dot.animate.move_to(direction), run_time=0.1)
|
||||
self.play(dot.animate.move_to(ORIGIN), run_time=0.1)
|
||||
|
||||
self.pause()
|
||||
|
||||
|
||||
class ConvertExample(Slide):
|
||||
"""WARNING: this example does not seem to work with ManimGL."""
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@ -15,11 +16,18 @@ def merge_basenames(files: List[str]) -> str:
|
||||
"""
|
||||
Merge multiple filenames by concatenating basenames.
|
||||
"""
|
||||
logger.info(f"Generating a new filename for animations: {files}")
|
||||
|
||||
dirname = os.path.dirname(files[0])
|
||||
_, ext = os.path.splitext(files[0])
|
||||
|
||||
basename = "_".join(os.path.splitext(os.path.basename(file))[0] for file in files)
|
||||
basenames = (os.path.splitext(os.path.basename(file))[0] for file in files)
|
||||
|
||||
basenames_str = ",".join(f"{len(b)}:{b}" for b in basenames)
|
||||
|
||||
# We use hashes to prevent too-long filenames, see issue #123:
|
||||
# https://github.com/jeertmans/manim-slides/issues/123
|
||||
basename = hashlib.sha256(basenames_str.encode()).hexdigest()
|
||||
|
||||
return os.path.join(dirname, basename + ext)
|
||||
|
||||
|
Reference in New Issue
Block a user