Skip to content

Commit

Permalink
Merge pull request #78 from OpenVoiceOS/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Oct 25, 2023
2 parents e985034 + 0cc0efa commit 22627c5
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 92 deletions.
109 changes: 99 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,121 @@
# Changelog

## [V0.0.10a3](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.10a3) (2023-05-31)
## [V0.0.11a15](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a15) (2023-10-24)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.10a2...V0.0.10a3)
[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a14...V0.0.11a15)

**Merged pull requests:**

- Minor dependency and logging updates [\#77](https://github.com/OpenVoiceOS/ovos-config/pull/77) ([NeonDaniel](https://github.com/NeonDaniel))

## [V0.0.11a14](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a14) (2023-10-18)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a13...V0.0.11a14)

**Merged pull requests:**

- add max\_msg\_size [\#76](https://github.com/OpenVoiceOS/ovos-config/pull/76) ([JarbasAl](https://github.com/JarbasAl))

## [V0.0.11a13](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a13) (2023-09-18)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a12...V0.0.11a13)

**Fixed bugs:**

- fix remote config reload [\#74](https://github.com/OpenVoiceOS/ovos-config/pull/74) ([emphasize](https://github.com/emphasize))

## [V0.0.11a12](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a12) (2023-09-17)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a10...V0.0.11a12)

**Merged pull requests:**

- Fix typo'd "loosly" [\#72](https://github.com/OpenVoiceOS/ovos-config/pull/72) ([strugee](https://github.com/strugee))
- \[cache\] Add persistent cache options [\#68](https://github.com/OpenVoiceOS/ovos-config/pull/68) ([goldyfruit](https://github.com/goldyfruit))

## [V0.0.11a10](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a10) (2023-08-22)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a9...V0.0.11a10)

**Implemented enhancements:**

- Update default translation plugin [\#66](https://github.com/OpenVoiceOS/ovos-config/pull/66) ([JarbasAl](https://github.com/JarbasAl))

## [V0.0.11a9](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a9) (2023-08-08)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a8...V0.0.11a9)

**Fixed bugs:**

- Update config hash to sort keys to ensure hashes compare [\#52](https://github.com/OpenVoiceOS/ovos-config/pull/52) ([NeonDaniel](https://github.com/NeonDaniel))
- fix subclassing for deprecation [\#65](https://github.com/OpenVoiceOS/ovos-config/pull/65) ([JarbasAl](https://github.com/JarbasAl))

## [V0.0.11a8](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a8) (2023-08-08)

## [V0.0.10a2](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.10a2) (2023-05-31)
[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a7...V0.0.11a8)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.10a1...V0.0.10a2)
**Merged pull requests:**

- Log deprecation of FileWatcher classes in `.utils` [\#64](https://github.com/OpenVoiceOS/ovos-config/pull/64) ([NeonDaniel](https://github.com/NeonDaniel))

## [V0.0.11a7](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a7) (2023-08-07)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a6...V0.0.11a7)

**Implemented enhancements:**

- update config [\#63](https://github.com/OpenVoiceOS/ovos-config/pull/63) ([JarbasAl](https://github.com/JarbasAl))

## [V0.0.11a6](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a6) (2023-07-26)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a5...V0.0.11a6)

**Merged pull requests:**

- Add config path checks before mtime checks [\#62](https://github.com/OpenVoiceOS/ovos-config/pull/62) ([NeonDaniel](https://github.com/NeonDaniel))

## [V0.0.11a5](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a5) (2023-07-21)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a4...V0.0.11a5)

**Merged pull requests:**

- Fix infinitely recursive callback [\#61](https://github.com/OpenVoiceOS/ovos-config/pull/61) ([NeonDaniel](https://github.com/NeonDaniel))

## [V0.0.11a4](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a4) (2023-07-13)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a3...V0.0.11a4)

**Closed issues:**

- Clean install failed on missing ovos-tts-plugin-mimic [\#49](https://github.com/OpenVoiceOS/ovos-config/issues/49)
- Some fields not updating as expected using single command line [\#58](https://github.com/OpenVoiceOS/ovos-config/issues/58)

**Merged pull requests:**

- Skip config file reload when a non-config file is modified [\#51](https://github.com/OpenVoiceOS/ovos-config/pull/51) ([NeonDaniel](https://github.com/NeonDaniel))
- change connectivity check urls [\#60](https://github.com/OpenVoiceOS/ovos-config/pull/60) ([JarbasAl](https://github.com/JarbasAl))

## [V0.0.11a3](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a3) (2023-07-04)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a2...V0.0.11a3)

**Implemented enhancements:**

- default g2p to ovos-g2p-plugin-heuristic-arpa [\#56](https://github.com/OpenVoiceOS/ovos-config/pull/56) ([JarbasAl](https://github.com/JarbasAl))

## [V0.0.11a2](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a2) (2023-07-04)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.11a1...V0.0.11a2)

**Implemented enhancements:**

- document dinkum listener [\#57](https://github.com/OpenVoiceOS/ovos-config/pull/57) ([JarbasAl](https://github.com/JarbasAl))

## [V0.0.10a1](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.10a1) (2023-05-29)
## [V0.0.11a1](https://github.com/OpenVoiceOS/ovos-config/tree/V0.0.11a1) (2023-07-02)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.9...V0.0.10a1)
[Full Changelog](https://github.com/OpenVoiceOS/ovos-config/compare/V0.0.10...V0.0.11a1)

**Merged pull requests:**

- refactor/better\_defaults [\#50](https://github.com/OpenVoiceOS/ovos-config/pull/50) ([JarbasAl](https://github.com/JarbasAl))
- Update mycroft.conf [\#55](https://github.com/OpenVoiceOS/ovos-config/pull/55) ([JarbasAl](https://github.com/JarbasAl))



Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Given an entry of

* `ovos-config set`

* Searches loosly for keys containing the query string and presents a choice to the user to define a value
* Searches loosely for keys containing the query string and presents a choice to the user to define a value

`ovos-config set -k phal`

Expand Down
2 changes: 1 addition & 1 deletion ovos_config/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def set(key, value):
"""\b
Sets a config key in the user configuration
\b
Loosly searches a config key and if multiple are found asks which key and value should be written.
Loosely searches a config key and if multiple are found asks which key and value should be written.
The user may pass a value to bypass prompting.
\b
Examples:
Expand Down
22 changes: 7 additions & 15 deletions ovos_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import json
from os.path import isfile
from typing import Optional
from time import sleep

from ovos_config.models import LocalConf, MycroftDefaultConfig, \
MycroftSystemConfig, MycroftUserConfig, RemoteConf
from ovos_config.locations import OLD_USER_CONFIG, get_xdg_config_save_path, \
get_xdg_config_locations
from ovos_config.utils import FileWatcher
from ovos_utils.file_utils import FileWatcher

from ovos_utils.json_helper import flattened_delete, merge_dict
from ovos_utils.log import LOG
Expand Down Expand Up @@ -299,25 +298,18 @@ def _on_file_change(path: str):
old_cfg = hash(cfg)
try:
cfg.reload()
reloaded = True
except:
# got the file changed signal before write finished
sleep(0.5)
reloaded = False
try:
if not reloaded:
LOG.warning(f"Reload failed, retrying")
cfg.reload()
except:
LOG.exception("Failed to load configuration, "
"syntax seems invalid!")
except Exception as e:
# Filewatcher only calls this on file close, so this
# is really an error
LOG.exception(f"Failed to load: {path}: {e}")

new_cfg = hash(cfg)
if old_cfg == new_cfg:
LOG.info(f"{path} unchanged")
return
break
else:
LOG.info(f"Ignoring non-config file change: {path}")
LOG.debug(f"Ignoring non-config file change: {path}")
return

LOG.info(f'{path} changed on disk')
Expand Down
31 changes: 23 additions & 8 deletions ovos_config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
# limitations under the License.
#
import json
from os.path import exists, isfile
from combo_lock import NamedLock
import yaml

from time import time
from os.path import exists, isfile, getmtime
from combo_lock import NamedLock
from ovos_utils.json_helper import load_commented_json, merge_dict
from ovos_utils.log import LOG

Expand Down Expand Up @@ -54,13 +56,14 @@ class LocalConf(dict):
allow_overwrite = True
# lock is shared among all subclasses,
# regardless of what file is being edited only one file should change at a time
# this ensure orderly behaviour in anything monitoring changes,
# this ensures orderly behaviour in anything monitoring changes,
# eg FileWatcher util, configuration.patch bus handlers
__lock = NamedLock("ovos_config")

def __init__(self, path):
super().__init__(self)
self.path = path
self._last_loaded = None
if path:
self.load_local(path)

Expand All @@ -85,7 +88,8 @@ def _get_file_format(self, path=None):
return "json"

def load_local(self, path=None):
"""Load local json file into self.
"""
Load local json file into self.
Args:
path (str): file to load
Expand All @@ -110,10 +114,16 @@ def load_local(self, path=None):
LOG.debug(f"Empty config found at: {path}")
except Exception as e:
LOG.exception(f"Error loading configuration '{path}'")
if path == self.path and isfile(self.path):
self._last_loaded = getmtime(self.path)
else:
LOG.debug(f"Configuration '{path}' not defined, skipping")

def reload(self):
if isfile(self.path) and self._last_loaded == getmtime(self.path):
LOG.debug(f"{self.path} not changed since last load "
f"(changed {time() - self._last_loaded} seconds ago)")
return
self.load_local(self.path)

def store(self, path=None):
Expand Down Expand Up @@ -179,7 +189,7 @@ def __init__(self, allow_overwrite=False):


class RemoteConf(LocalConf):
"""Config dictionary fetched from mycroft.ai."""
"""Config dictionary fetched from the backend"""

def __init__(self, cache=WEB_CONFIG_CACHE):
super(RemoteConf, self).__init__(cache)
Expand All @@ -194,12 +204,17 @@ def reload(self):
return

remote = RemoteConfigManager()

remote.download()

changed = []
for key in remote.config:
self.__setitem__(key, remote.config[key])
if self.get(key) != remote.config[key]:
changed.append(key)
self.__setitem__(key, remote.config[key])

self.store(self.path)
if changed:
LOG.debug(f"config key(s) {changed} changed, writing remote config to {self.path}")
self.store(self.path)

except Exception as e:
LOG.error(f"Exception fetching remote configuration: {e}")
Expand Down
Loading

0 comments on commit 22627c5

Please sign in to comment.