Catch key exception + correct typo + file i/o method
This commit is contained in:
parent
7f6e6ee5fa
commit
0dc255594f
@ -2,7 +2,6 @@ import musicbrainzngs
|
|||||||
import logging
|
import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
import io
|
|
||||||
import configparser
|
import configparser
|
||||||
from sys import platform as current_os
|
from sys import platform as current_os
|
||||||
|
|
||||||
@ -44,19 +43,19 @@ NOT_A_GENRE = ".", "..", "misc_scripts", "Music", "script", ".git", ".idea"
|
|||||||
MUSIC_DIR = os.path.join("~", ".config", "user-dirs.dirs")
|
MUSIC_DIR = os.path.join("~", ".config", "user-dirs.dirs")
|
||||||
|
|
||||||
if current_os == "linux":
|
if current_os == "linux":
|
||||||
USER_XDG_DIR_FILE = os.path.expanduser("~/.config/user-dirs.dirss")
|
USER_XDG_DIR_FILE = os.path.expanduser("~/.config/user-dirs.dirs")
|
||||||
logger = logging.getLogger("init_path")
|
logger = logging.getLogger("init_path")
|
||||||
logger.setLevel(logging.WARNING)
|
logger.setLevel(logging.WARNING)
|
||||||
try:
|
try:
|
||||||
with open(USER_XDG_DIR_FILE, 'r') as f:
|
with open(USER_XDG_DIR_FILE, 'r') as f:
|
||||||
data = io.StringIO("[XDG_USER_DIRS]\n" + f.read())
|
data = "[XDG_USER_DIRS]\n" + f.read()
|
||||||
config = configparser.ConfigParser(allow_no_value=True)
|
config = configparser.ConfigParser(allow_no_value=True)
|
||||||
config.read_file(data)
|
config.read_string(data)
|
||||||
xdg_config = config['XDG_USER_DIRS']
|
xdg_config = config['XDG_USER_DIRS']
|
||||||
MUSIC_DIR = os.path.expandvars(xdg_config['xdg_music_dir'].strip('"'))
|
MUSIC_DIR = os.path.expandvars(xdg_config['xdg_music_dir'].strip('"'))
|
||||||
except FileNotFoundError as N:
|
except (FileNotFoundError, KeyError) as E:
|
||||||
logger.warning(f'''
|
logger.warning(f'''
|
||||||
Missing XDG_USER_DIRS file at: '{USER_XDG_DIR_FILE}'.
|
Missing file or key at: '{USER_XDG_DIR_FILE}'.
|
||||||
Will fallback on default '$HOME/Music'.
|
Will fallback on default '$HOME/Music'.
|
||||||
----
|
----
|
||||||
''')
|
''')
|
||||||
|
Loading…
Reference in New Issue
Block a user