WIP Review comments
- Add TODO for 22.02 to remove the compatibility code - Make Warning a single Log statement - mycroft-config script now uses XDG-environment variable - Remove redundant code - Replace hard coded references to ~/.config - Explicitly remove new path before move of "filesystem" (if needed)pull/2794/head
parent
9029dc1f41
commit
3fd96cf71b
|
@ -95,11 +95,11 @@ function validate_config_file() {
|
||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
|
|
||||||
_conf_file="~/.config/mycroft/mycroft.conf"
|
_conf_file="${XDG_CONFIG_HOME:-$HOME/.config}/mycroft/mycroft.conf"
|
||||||
function name_to_path() {
|
function name_to_path() {
|
||||||
case ${1} in
|
case ${1} in
|
||||||
"system") _conf_file="/etc/mycroft/mycroft.conf" ;;
|
"system") _conf_file="/etc/mycroft/mycroft.conf" ;;
|
||||||
"user") _conf_file=$(readlink -f ~/.config/mycroft/mycroft.conf) ;;
|
"user") _conf_file=$(readlink -f ${XDG_CONFIG_HOME:-$HOME/.config}/mycroft/mycroft.conf) ;;
|
||||||
"default") _conf_file="$DIR/../mycroft/configuration/mycroft.conf" ;;
|
"default") _conf_file="$DIR/../mycroft/configuration/mycroft.conf" ;;
|
||||||
"remote") _conf_file="$HOME/.cache/mycroft/web_cache.json" ;;
|
"remote") _conf_file="$HOME/.cache/mycroft/web_cache.json" ;;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ from threading import Thread, Timer
|
||||||
|
|
||||||
import serial
|
import serial
|
||||||
|
|
||||||
|
import xdg.BaseDirectory
|
||||||
|
|
||||||
import mycroft.dialog
|
import mycroft.dialog
|
||||||
from mycroft.client.enclosure.base import Enclosure
|
from mycroft.client.enclosure.base import Enclosure
|
||||||
from mycroft.api import has_been_paired
|
from mycroft.api import has_been_paired
|
||||||
|
@ -164,7 +166,8 @@ class EnclosureReader(Thread):
|
||||||
self.bus.emit(Message("speak", {
|
self.bus.emit(Message("speak", {
|
||||||
'utterance': mycroft.dialog.get("reset to factory defaults")}))
|
'utterance': mycroft.dialog.get("reset to factory defaults")}))
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
'rm ~/.config/mycroft/identity/identity2.json',
|
(f'rm {xdg.BaseDirectory.save_config_path("mycroft")}'
|
||||||
|
'/mycroft/identity/identity2.json'),
|
||||||
shell=True)
|
shell=True)
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
'rm ~/.mycroft/identity/identity2.json',
|
'rm ~/.mycroft/identity/identity2.json',
|
||||||
|
|
|
@ -280,7 +280,7 @@ class PreciseHotword(HotWordEngine):
|
||||||
old_path = join(expanduser('~'), '.mycroft', 'precise')
|
old_path = join(expanduser('~'), '.mycroft', 'precise')
|
||||||
if os.path.isdir(old_path):
|
if os.path.isdir(old_path):
|
||||||
return old_path
|
return old_path
|
||||||
return join(xdg.BaseDirectory.save_data_path('mycroft', 'precise'))
|
return xdg.BaseDirectory.save_data_path('mycroft', 'precise')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def install_destination(self):
|
def install_destination(self):
|
||||||
|
|
|
@ -24,7 +24,7 @@ import xdg.BaseDirectory
|
||||||
from mycroft.util.json_helper import load_commented_json, merge_dict
|
from mycroft.util.json_helper import load_commented_json, merge_dict
|
||||||
from mycroft.util.log import LOG
|
from mycroft.util.log import LOG
|
||||||
|
|
||||||
from .locations import DEFAULT_CONFIG, OLD_USER_CONFIG, USER_CONFIG
|
from .locations import DEFAULT_CONFIG, USER_CONFIG, OLD_USER_CONFIG
|
||||||
from .locations import SYSTEM_CONFIG
|
from .locations import SYSTEM_CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
@ -170,6 +170,17 @@ class RemoteConf(LocalConf):
|
||||||
self.load_local(cache)
|
self.load_local(cache)
|
||||||
|
|
||||||
|
|
||||||
|
def _log_old_location_deprecation():
|
||||||
|
LOG.warning("\n ===============================================\n"
|
||||||
|
" == DEPRECATION WARNING ==\n"
|
||||||
|
" ===============================================\n"
|
||||||
|
f" You still have a config file at {OLD_USER_CONFIG}\n"
|
||||||
|
" Note that this location is deprecated and will"
|
||||||
|
" not be used in the future\n"
|
||||||
|
" Please move it to "
|
||||||
|
f"{xdg.BaseDirectory.save_config_path('mycroft')}")
|
||||||
|
|
||||||
|
|
||||||
class Configuration:
|
class Configuration:
|
||||||
"""Namespace for operations on the configuration singleton."""
|
"""Namespace for operations on the configuration singleton."""
|
||||||
__config = {} # Cached config
|
__config = {} # Cached config
|
||||||
|
@ -185,9 +196,7 @@ class Configuration:
|
||||||
Args:
|
Args:
|
||||||
configs (list): List of configuration dicts
|
configs (list): List of configuration dicts
|
||||||
cache (boolean): True if the result should be cached
|
cache (boolean): True if the result should be cached
|
||||||
remote (boolean): False if the Mycroft Home settings shouldn't
|
remote (boolean): False if the Remote settings shouldn't be loaded
|
||||||
be loaded
|
|
||||||
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(dict) configuration dictionary.
|
(dict) configuration dictionary.
|
||||||
|
@ -210,7 +219,7 @@ class Configuration:
|
||||||
(dict) merged dict of all configuration files
|
(dict) merged dict of all configuration files
|
||||||
"""
|
"""
|
||||||
if not configs:
|
if not configs:
|
||||||
configs = configs or []
|
configs = []
|
||||||
|
|
||||||
# First use the patched config
|
# First use the patched config
|
||||||
configs.append(Configuration.__patch)
|
configs.append(Configuration.__patch)
|
||||||
|
@ -223,21 +232,9 @@ class Configuration:
|
||||||
|
|
||||||
# Then check the old user config
|
# Then check the old user config
|
||||||
if isfile(OLD_USER_CONFIG):
|
if isfile(OLD_USER_CONFIG):
|
||||||
LOG.warning(" ===============================================")
|
_log_old_location_deprecation()
|
||||||
LOG.warning(" == DEPRECATION WARNING ==")
|
|
||||||
LOG.warning(" ===============================================")
|
|
||||||
LOG.warning(" You still have a config file at " +
|
|
||||||
OLD_USER_CONFIG)
|
|
||||||
LOG.warning(" Note that this location is deprecated and will" +
|
|
||||||
" not be used in the future")
|
|
||||||
LOG.warning(" Please move it to " +
|
|
||||||
xdg.BaseDirectory.save_config_path('mycroft'))
|
|
||||||
configs.append(LocalConf(OLD_USER_CONFIG))
|
configs.append(LocalConf(OLD_USER_CONFIG))
|
||||||
|
|
||||||
# Then check the XDG user config
|
|
||||||
if isfile(USER_CONFIG):
|
|
||||||
configs.append(LocalConf(USER_CONFIG))
|
|
||||||
|
|
||||||
# Then use remote config
|
# Then use remote config
|
||||||
if remote:
|
if remote:
|
||||||
configs.append(RemoteConf())
|
configs.append(RemoteConf())
|
||||||
|
|
|
@ -18,11 +18,13 @@ import xdg.BaseDirectory
|
||||||
DEFAULT_CONFIG = join(dirname(__file__), 'mycroft.conf')
|
DEFAULT_CONFIG = join(dirname(__file__), 'mycroft.conf')
|
||||||
SYSTEM_CONFIG = os.environ.get('MYCROFT_SYSTEM_CONFIG',
|
SYSTEM_CONFIG = os.environ.get('MYCROFT_SYSTEM_CONFIG',
|
||||||
'/etc/mycroft/mycroft.conf')
|
'/etc/mycroft/mycroft.conf')
|
||||||
|
# TODO: remove in 22.02
|
||||||
# Make sure we support the old location still
|
# Make sure we support the old location still
|
||||||
# Deprecated and will be removed eventually
|
# Deprecated and will be removed eventually
|
||||||
OLD_USER_CONFIG = join(expanduser('~'), '.mycroft/mycroft.conf')
|
OLD_USER_CONFIG = join(expanduser('~'), '.mycroft/mycroft.conf')
|
||||||
USER_CONFIG = join(xdg.BaseDirectory.save_config_path('mycroft'),
|
USER_CONFIG = join(xdg.BaseDirectory.save_config_path('mycroft'),
|
||||||
'mycroft.conf')
|
'mycroft.conf')
|
||||||
|
|
||||||
REMOTE_CONFIG = "mycroft.ai"
|
REMOTE_CONFIG = "mycroft.ai"
|
||||||
WEB_CONFIG_CACHE = os.environ.get('MYCROFT_WEB_CACHE',
|
WEB_CONFIG_CACHE = os.environ.get('MYCROFT_WEB_CACHE',
|
||||||
'/var/tmp/mycroft_web_cache.json')
|
'/var/tmp/mycroft_web_cache.json')
|
||||||
|
|
|
@ -38,7 +38,10 @@ class FileSystemAccess:
|
||||||
path = join(xdg.BaseDirectory.save_config_path('mycroft'), path)
|
path = join(xdg.BaseDirectory.save_config_path('mycroft'), path)
|
||||||
|
|
||||||
# Migrate from the old location if it still exists
|
# Migrate from the old location if it still exists
|
||||||
|
# TODO: remove in 22.02
|
||||||
if isdir(old_path):
|
if isdir(old_path):
|
||||||
|
if isdir(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
shutil.move(old_path, path)
|
shutil.move(old_path, path)
|
||||||
|
|
||||||
if not isdir(path):
|
if not isdir(path):
|
||||||
|
|
Loading…
Reference in New Issue