From caa4577cd161e5c8bd4f2f57b9d6c3295672d2a3 Mon Sep 17 00:00:00 2001 From: Devin Neal Date: Mon, 3 Jun 2019 23:41:05 -0700 Subject: [PATCH] reorganize media file tree --- manim.py | 0 manimlib/constants.py | 21 +++-------- manimlib/for_3b1b_videos/pi_creature.py | 4 +- manimlib/mobject/svg/svg_mobject.py | 6 +-- manimlib/scene/scene_file_writer.py | 49 +++++++++++-------------- manimlib/utils/file_ops.py | 2 +- manimlib/utils/images.py | 3 +- manimlib/utils/sounds.py | 3 +- 8 files changed, 36 insertions(+), 52 deletions(-) mode change 100644 => 100755 manim.py diff --git a/manim.py b/manim.py old mode 100644 new mode 100755 diff --git a/manimlib/constants.py b/manimlib/constants.py index 3fb72a3f..9ce2db5e 100644 --- a/manimlib/constants.py +++ b/manimlib/constants.py @@ -20,28 +20,19 @@ if not os.path.isdir(MEDIA_DIR): "this behavior by writing a different directory to media_dir.txt." ) -VIDEO_DIR = os.path.join(MEDIA_DIR, "videos") -RASTER_IMAGE_DIR = os.path.join(MEDIA_DIR, "designs", "raster_images") -SVG_IMAGE_DIR = os.path.join(MEDIA_DIR, "designs", "svg_images") -SOUND_DIR = os.path.join(MEDIA_DIR, "designs", "sounds") -### -THIS_DIR = os.path.dirname(os.path.realpath(__file__)) -FILE_DIR = os.path.join(os.getenv("FILE_DIR", default="."), "files") -TEX_DIR = os.path.join(FILE_DIR, "Tex") -# These two may be depricated now. -MOBJECT_DIR = os.path.join(FILE_DIR, "mobjects") -IMAGE_MOBJECT_DIR = os.path.join(MOBJECT_DIR, "image") +VIDEO_DIR = os.path.join(MEDIA_DIR, "video") +ASSETS_DIR = os.path.join(MEDIA_DIR, "assets") +TEX_DIR = os.path.join(MEDIA_DIR, "Tex") -for folder in [FILE_DIR, RASTER_IMAGE_DIR, SVG_IMAGE_DIR, VIDEO_DIR, - TEX_DIR, MOBJECT_DIR, IMAGE_MOBJECT_DIR]: +for folder in [VIDEO_DIR, ASSETS_DIR, TEX_DIR]: if not os.path.exists(folder): os.makedirs(folder) TEX_USE_CTEX = False TEX_TEXT_TO_REPLACE = "YourTextHere" TEMPLATE_TEX_FILE = os.path.join( - THIS_DIR, "tex_template.tex" if not TEX_USE_CTEX - else "ctex_template.tex" + os.path.dirname(os.path.realpath(__file__)), + "tex_template.tex" if not TEX_USE_CTEX else "ctex_template.tex" ) with open(TEMPLATE_TEX_FILE, "r") as infile: TEMPLATE_TEXT_FILE_BODY = infile.read() diff --git a/manimlib/for_3b1b_videos/pi_creature.py b/manimlib/for_3b1b_videos/pi_creature.py index fa3864d3..7375c8bd 100644 --- a/manimlib/for_3b1b_videos/pi_creature.py +++ b/manimlib/for_3b1b_videos/pi_creature.py @@ -15,11 +15,11 @@ from manimlib.utils.config_ops import digest_config from manimlib.utils.space_ops import get_norm from manimlib.utils.space_ops import normalize -pi_creature_dir_maybe = os.path.join(MEDIA_DIR, "designs", "PiCreature") +pi_creature_dir_maybe = os.path.join(MEDIA_DIR, "assets", "PiCreature") if os.path.exists(pi_creature_dir_maybe): PI_CREATURE_DIR = pi_creature_dir_maybe else: - PI_CREATURE_DIR = os.path.join(FILE_DIR) + PI_CREATURE_DIR = os.path.join("assets") PI_CREATURE_SCALE_FACTOR = 0.5 diff --git a/manimlib/mobject/svg/svg_mobject.py b/manimlib/mobject/svg/svg_mobject.py index 2e27bb6c..a5dc6bc3 100644 --- a/manimlib/mobject/svg/svg_mobject.py +++ b/manimlib/mobject/svg/svg_mobject.py @@ -50,9 +50,9 @@ class SVGMobject(VMobject): if self.file_name is None: raise Exception("Must specify file for SVGMobject") possible_paths = [ - os.path.join(SVG_IMAGE_DIR, self.file_name), - os.path.join(SVG_IMAGE_DIR, self.file_name + ".svg"), - os.path.join(SVG_IMAGE_DIR, self.file_name + ".xdv"), + os.path.join(os.path.join("assets", "svg_images"), self.file_name), + os.path.join(os.path.join("assets", "svg_images"), self.file_name + ".svg"), + os.path.join(os.path.join("assets", "svg_images"), self.file_name + ".xdv"), self.file_name, ] for path in possible_paths: diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.py index 7280961b..fb39c90e 100644 --- a/manimlib/scene/scene_file_writer.py +++ b/manimlib/scene/scene_file_writer.py @@ -13,7 +13,7 @@ from manimlib.constants import STREAMING_PORT from manimlib.constants import STREAMING_PROTOCOL from manimlib.constants import VIDEO_DIR from manimlib.utils.config_ops import digest_config -from manimlib.utils.file_ops import guarantee_existance +from manimlib.utils.file_ops import guarantee_existence from manimlib.utils.file_ops import add_extension_if_not_present from manimlib.utils.file_ops import get_sorted_integer_files from manimlib.utils.sounds import get_full_sound_file_path @@ -35,7 +35,6 @@ class SceneFileWriter(object): # TODO, address this in extract_scene et. al. "file_name": None, "output_directory": None, - "file_name": None, } def __init__(self, scene, **kwargs): @@ -47,66 +46,62 @@ class SceneFileWriter(object): # Output directories and files def init_output_directories(self): - output_directory = self.output_directory or self.get_default_output_directory() - file_name = self.file_name or self.get_default_file_name() + module_directory = self.output_directory or self.get_default_module_directory() + scene_name = self.file_name or self.get_default_scene_name() if self.save_last_frame: - image_dir = guarantee_existance(os.path.join( + image_dir = guarantee_existence(os.path.join( VIDEO_DIR, - output_directory, - self.get_image_directory(), + module_directory, + scene_name, + "images", )) self.image_file_path = os.path.join( image_dir, - add_extension_if_not_present(file_name, ".png") + add_extension_if_not_present(scene_name, ".png") ) if self.write_to_movie: - movie_dir = guarantee_existance(os.path.join( + movie_dir = guarantee_existence(os.path.join( VIDEO_DIR, - output_directory, - self.get_movie_directory(), + module_directory, + scene_name, + self.get_resolution_directory(), )) self.movie_file_path = os.path.join( movie_dir, add_extension_if_not_present( - file_name, self.movie_file_extension + scene_name, self.movie_file_extension ) ) self.gif_file_path = os.path.join( movie_dir, add_extension_if_not_present( - file_name, self.gif_file_extension + scene_name, self.gif_file_extension ) ) - self.partial_movie_directory = guarantee_existance(os.path.join( + self.partial_movie_directory = guarantee_existence(os.path.join( movie_dir, - self.get_partial_movie_directory(), - file_name, + "partial_movie_files", + scene_name, )) - def get_default_output_directory(self): + def get_default_module_directory(self): filename = os.path.basename(self.input_file_path) - root, ext = os.path.splitext(filename) - return root if root else ext[1:] + root, _ = os.path.splitext(filename) + return root - def get_default_file_name(self): + def get_default_scene_name(self): if self.file_name is None: return self.scene.__class__.__name__ else: return self.file_name - def get_movie_directory(self): + def get_resolution_directory(self): pixel_height = self.scene.camera.pixel_height frame_rate = self.scene.camera.frame_rate return "{}p{}".format( pixel_height, frame_rate ) - def get_image_directory(self): - return "images" - - def get_partial_movie_directory(self): - return "partial_movie_files" - # Directory getters def get_image_file_path(self): return self.image_file_path diff --git a/manimlib/utils/file_ops.py b/manimlib/utils/file_ops.py index 36a21e4e..9c9752a4 100644 --- a/manimlib/utils/file_ops.py +++ b/manimlib/utils/file_ops.py @@ -10,7 +10,7 @@ def add_extension_if_not_present(file_name, extension): return file_name -def guarantee_existance(path): +def guarantee_existence(path): if not os.path.exists(path): os.makedirs(path) return os.path.abspath(path) diff --git a/manimlib/utils/images.py b/manimlib/utils/images.py index 63dcc58b..edd75530 100644 --- a/manimlib/utils/images.py +++ b/manimlib/utils/images.py @@ -3,14 +3,13 @@ import os from PIL import Image -from manimlib.constants import RASTER_IMAGE_DIR from manimlib.utils.file_ops import seek_full_path_from_defaults def get_full_raster_image_path(image_file_name): return seek_full_path_from_defaults( image_file_name, - default_dir=RASTER_IMAGE_DIR, + default_dir=os.path.join("assets", "raster_images"), extensions=[".jpg", ".png", ".gif"] ) diff --git a/manimlib/utils/sounds.py b/manimlib/utils/sounds.py index 17a185ce..26cfff07 100644 --- a/manimlib/utils/sounds.py +++ b/manimlib/utils/sounds.py @@ -1,5 +1,4 @@ import os -from manimlib.constants import SOUND_DIR from manimlib.utils.file_ops import seek_full_path_from_defaults @@ -35,6 +34,6 @@ def play_finish_sound(): def get_full_sound_file_path(sound_file_name): return seek_full_path_from_defaults( sound_file_name, - default_dir=SOUND_DIR, + default_dir=os.path.join("assets", "sounds"), extensions=[".wav", ".mp3"] )