From eace62a0f4cd9cc584b6287d7b8f13519699861e Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 29 Mar 2011 21:03:27 -0700 Subject: [PATCH] BEETSCONFIG environment variable (#148) --- NEWS | 2 ++ beets/ui/__init__.py | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index dcd65827c..b94e60d97 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,8 @@ * Resuming is automatically disabled when the importer is in quiet (-q) mode. Progress is still saved, however, and the -q flag (above) can be used to force resuming. +* The BEETSCONFIG environment variable can now be used to specify the + location of the config file that is at ~/.beetsconfig by default. * Fix a bug where some files would be erroneously interpreted as MP4. * Fix permission bits applied to album art files. * Fix malformed MusicBrainz queries caused by null characters. diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index d661802d1..62b71cb8b 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -30,7 +30,8 @@ from beets import library from beets import plugins # Constants. -CONFIG_FILE = os.path.expanduser('~/.beetsconfig') +CONFIG_PATH_VAR = 'BEETSCONFIG' +DEFAULT_CONFIG_FILE = os.path.expanduser('~/.beetsconfig') STATE_FILE = os.path.expanduser('~/.beetsstate') DEFAULT_LIBRARY = '~/.beetsmusic.blb' DEFAULT_DIRECTORY = '~/Music' @@ -405,9 +406,12 @@ def main(args=None, configfh=None): # Read defaults from config file. config = ConfigParser.SafeConfigParser() if configfh: - config.readfp(configfh) + pass + elif CONFIG_PATH_VAR in os.environ: + configfh = open(os.path.expanduser(os.environ[CONFIG_PATH_VAR])) else: - config.read(CONFIG_FILE) + configfh = open(DEFAULT_CONFIG_FILE) + config.readfp(configfh) # Add plugin paths. plugpaths = config_val(config, 'beets', 'pluginpath', '')