mirror of
https://github.com/beetbox/beets.git
synced 2025-12-09 18:12:19 +01:00
fix crash when ~/.beetsconfig does not exist
This commit is contained in:
parent
a0e0104d83
commit
be9dc888cb
3 changed files with 20 additions and 4 deletions
1
NEWS
1
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
|
||||
-----
|
||||
|
|
|
|||
|
|
@ -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', '')
|
||||
|
|
|
|||
|
|
@ -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__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue