From 9e3c0d0c8b97c2e78d7a6412e2c14b91d3bcd11f Mon Sep 17 00:00:00 2001 From: rajdakin Date: Thu, 24 May 2018 20:59:37 +0200 Subject: [PATCH] Added a way to easily customize the media directory --- .gitignore | 1 + constants.py | 46 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 87cbc012..73bd3812 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ manim.sublime-project manim.sublime-workspace primes.py +/media_dir.txt diff --git a/constants.py b/constants.py index 888b0c31..59a808bd 100644 --- a/constants.py +++ b/constants.py @@ -1,12 +1,40 @@ import os import numpy as np -# Things anyone wishing to use this repository for their -# own use will want to change -MEDIA_DIR = os.path.join( - os.path.expanduser('~'), - "Dropbox (3Blue1Brown)/3Blue1Brown Team Folder" -) +env_MEDIA_DIR = None +MEDIA_DIR = "#ERROR#" + +try: + env_MEDIA_DIR = os.getenv("MEDIA_DIR") +except NameError: + try: + env_MEDIA_DIR = os.environ['MEDIA_DIR'] + except KeyError: + pass + +if not (env_MEDIA_DIR is None): + MEDIA_DIR = env_MEDIA_DIR +elif os.path.exists("media_dir.txt"): + with open("media_dir.txt", 'rU') as media_file: + MEDIA_DIR = media_file.readline() + if MEDIA_DIR[-1] in ['\n', '\r']: + raise Exception("media_dir.txt must be a single-line text file pointing at the media_dir place") +else: + MEDIA_DIR = os.path.join( + os.path.expanduser('~'), + "Dropbox (3Blue1Brown)/3Blue1Brown Team Folder" + ) + +if not os.path.exists(MEDIA_DIR): + raise Exception(""" + Redefine MEDIA_DIR by changing the MEDIA_DIR + environment constant or by changing + media_dir.txt to point to a valid directory + where movies and images will be written + """) + +with open("media_dir.txt", 'w') as media_file: + media_file.write(MEDIA_DIR) # @@ -97,12 +125,6 @@ TEX_IMAGE_DIR = TEX_DIR # TODO, What is this doing? MOBJECT_DIR = os.path.join(FILE_DIR, "mobjects") IMAGE_MOBJECT_DIR = os.path.join(MOBJECT_DIR, "image") -if not os.path.exists(MEDIA_DIR): - raise Exception(""" - Redefine MEDIA_DIR in constants.py to point to - a valid directory where movies and images will - be written - """) for folder in [FILE_DIR, RASTER_IMAGE_DIR, SVG_IMAGE_DIR, ANIMATIONS_DIR, TEX_DIR, TEX_IMAGE_DIR, MOBJECT_DIR, IMAGE_MOBJECT_DIR, STAGED_SCENES_DIR]: