diff --git a/NEWS b/NEWS index afc3f3016..3e84b5bef 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,7 @@ the other way around). * Fix some crashes when deleting files that don't exist. * Fix adding individual tracks in BPD. +* Fix crash when ~/.beetsconfig does not exist. 1.0b7 ----- diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 4fa5c897e..cabbad91f 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -28,6 +28,7 @@ import logging from beets import library from beets import plugins +from beets import util # Constants. CONFIG_PATH_VAR = 'BEETSCONFIG' @@ -406,12 +407,19 @@ def main(args=None, configfh=None): # Read defaults from config file. config = ConfigParser.SafeConfigParser() if configfh: - pass + configpath = None elif CONFIG_PATH_VAR in os.environ: - configfh = open(os.path.expanduser(os.environ[CONFIG_PATH_VAR])) + configpath = os.path.expanduser(os.environ[CONFIG_PATH_VAR]) else: - configfh = open(DEFAULT_CONFIG_FILE) - config.readfp(configfh) + configpath = DEFAULT_CONFIG_FILE + if configpath: + configpath = util.syspath(configpath) + if os.path.exists(util.syspath(configpath)): + configfh = open(configpath) + else: + configfh = None + if configfh: + config.readfp(configfh) # Add plugin paths. plugpaths = config_val(config, 'beets', 'pluginpath', '') diff --git a/test/test_ui.py b/test/test_ui.py index 7dc51bcf5..be6d4c944 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -180,9 +180,12 @@ class InputTest(unittest.TestCase): class ConfigTest(unittest.TestCase): def setUp(self): + self.io = _common.DummyIO() + self.io.install() self.test_cmd = ui.Subcommand('test', help='test') commands.default_commands.append(self.test_cmd) def tearDown(self): + self.io.restore() commands.default_commands.pop() def _run_main(self, args, config, func): self.test_cmd.func = func @@ -219,6 +222,10 @@ class ConfigTest(unittest.TestCase): [paths] x=y"""), func) + def test_nonexistant_config_file(self): + os.environ['BEETSCONFIG'] = '/xxxxx' + ui.main(['version']) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)