Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixed problem with output_directory_getters.py on new files

Grant Sanderson4504fa381986
diff --git a/extract_scene.py b/extract_scene.py
index 5fe81b79d..ae52be31d 100644
--- a/extract_scene.py
+++ b/extract_scene.py
@@ -21,6 +21,7 @@ HELP_MESSAGE = """
-p preview in low quality
-s show and save picture of last frame
-w write result to file [this is default if nothing else is stated]
+ -o <file_name> write to a different file_name
-l use low quality
-m use medium quality
-a run and save every scene in the script, or all args for the given scene
diff --git a/scene/scene.py b/scene/scene.py
index 2c9bd581c..f136982f2 100644
--- a/scene/scene.py
+++ b/scene/scene.py
@@ -545,9 +545,6 @@ class Scene(Container):
def save_image(self, name=None, mode="RGB", dont_update=False):
path = self.get_image_file_path(name, dont_update)
- directory_path = os.path.dirname(path)
- if not os.path.exists(directory_path):
- os.makedirs(directory_path)
if not dont_update:
self.update_frame(dont_update_when_skipping=False)
image = self.get_image()
diff --git a/utils/output_directory_getters.py b/utils/output_directory_getters.py
index 6306d3986..8011392e3 100644
--- a/utils/output_directory_getters.py
+++ b/utils/output_directory_getters.py
@@ -12,6 +12,12 @@ def add_extension_if_not_present(file_name, extension):
return file_name
+def guarantee_existance(path):
+ if not os.path.exists(path):
+ os.makedirs(path)
+ return path
+
+
def get_scene_output_directory(scene_class):
file_path = os.path.abspath(inspect.getfile(scene_class))
@@ -22,7 +28,7 @@ def get_scene_output_directory(scene_class):
file_path = os.path.join(*sub_parts)
file_path = file_path.replace(".pyc", "")
file_path = file_path.replace(".py", "")
- return os.path.join(ANIMATIONS_DIR, file_path)
+ return guarantee_existance(os.path.join(ANIMATIONS_DIR, file_path))
def get_movie_output_directory(scene_class, camera_config, frame_duration):
@@ -31,8 +37,9 @@ def get_movie_output_directory(scene_class, camera_config, frame_duration):
camera_config["pixel_shape"][0],
int(1.0 / frame_duration)
)
- return os.path.join(directory, sub_dir)
+ return guarantee_existance(os.path.join(directory, sub_dir))
def get_image_output_directory(scene_class, sub_dir="images"):
- return os.path.join(get_scene_output_directory(scene_class), sub_dir)
+ directory = get_scene_output_directory(scene_class)
+ return guarantee_existance(os.path.join(directory, sub_dir))