From 4904780b67f40aeae5d61417459b654cb956928d Mon Sep 17 00:00:00 2001 From: Devin Neal Date: Mon, 10 Dec 2018 19:30:07 -0800 Subject: [PATCH 1/2] automatically create MEDIA_DIR --- constants.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/constants.py b/constants.py index 4f90b1bc..4db0a328 100644 --- a/constants.py +++ b/constants.py @@ -1,18 +1,8 @@ import os import numpy as np -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): +env_MEDIA_DIR = os.getenv("MEDIA_DIR") +if env_MEDIA_DIR: MEDIA_DIR = env_MEDIA_DIR elif os.path.exists("media_dir.txt"): with open("media_dir.txt", 'rU') as media_file: @@ -24,16 +14,14 @@ else: ) 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 - """) + MEDIA_DIR = "media" + print( + f"Media will be stored in {MEDIA_DIR + os.sep}. You can change " + \ + "this behavior by writing a different directory to media_dir.txt." + ) with open("media_dir.txt", 'w') as media_file: media_file.write(MEDIA_DIR) -# LOW_QUALITY_FRAME_DURATION = 1. / 15 MEDIUM_QUALITY_FRAME_DURATION = 1. / 30 From b2f8c75a44665c37d29dfcedd9b00c8c2a5e145f Mon Sep 17 00:00:00 2001 From: Devin Neal Date: Mon, 10 Dec 2018 19:43:51 -0800 Subject: [PATCH 2/2] replace exists() with isfile() and isdir() --- constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/constants.py b/constants.py index 4db0a328..7e004185 100644 --- a/constants.py +++ b/constants.py @@ -4,7 +4,7 @@ import numpy as np env_MEDIA_DIR = os.getenv("MEDIA_DIR") if env_MEDIA_DIR: MEDIA_DIR = env_MEDIA_DIR -elif os.path.exists("media_dir.txt"): +elif os.path.isfile("media_dir.txt"): with open("media_dir.txt", 'rU') as media_file: MEDIA_DIR = media_file.readline().strip() else: @@ -13,7 +13,7 @@ else: "Dropbox (3Blue1Brown)/3Blue1Brown Team Folder" ) -if not os.path.exists(MEDIA_DIR): +if not os.path.isdir(MEDIA_DIR): MEDIA_DIR = "media" print( f"Media will be stored in {MEDIA_DIR + os.sep}. You can change " + \