Skip to content

Commit

Permalink
Startup bugfixes, annotations, refactoring (#166)
Browse files Browse the repository at this point in the history
* Fixes typo in run_neon preventing gui, server, and messagebus services from being stopped
Add annotations to methods in neon_core.__init__ and exports Mycroft-compatible config from YML configs (closes #159)

* Refactor 'Holmes' to 'OVOS' default configs

* Address review feedback

* Address review feedback

* Add TODO comment to evaluate log later
  • Loading branch information
NeonDaniel authored Nov 8, 2021
1 parent 2880298 commit cc858c2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
62 changes: 41 additions & 21 deletions neon_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,29 @@
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from os.path import join, dirname, exists

from os.path import join, dirname
import xdg.BaseDirectory
import json
from ovos_utils.json_helper import merge_dict
from ovos_utils.system import set_root_path
from ovos_utils.configuration import set_config_name

from neon_utils import LOG
from neon_utils.configuration_utils import write_mycroft_compatible_config

NEON_ROOT_PATH = dirname(dirname(__file__))

# first thing to do is ensure user holmes.conf exists
# NOTE: must be done before any mycroft (neon) import
def setup_holmes_config():
HOLMES_CONFIG = join(xdg.BaseDirectory.save_config_path("HolmesV"),
"holmes.conf")

_NEON_HOLMES_CONFIG = {
def setup_ovos_core_config():
"""
Runs at module init to ensure base ovos.conf exists to patch ovos-core. Note that this must run before any import
of Configuration class.
"""
OVOS_CONFIG = join(xdg.BaseDirectory.save_config_path("OpenVoiceOS"),
"ovos.conf")

_NEON_OVOS_CONFIG = {
"module_overrides": {
"neon_core": {
"xdg": True,
Expand All @@ -55,25 +62,26 @@ def setup_holmes_config():
"neon_enclosure": "neon_core"
}
}

cfg = {}
if exists(HOLMES_CONFIG):
try:
with open(HOLMES_CONFIG) as f:
cfg = json.load(f)
except:
pass
cfg = merge_dict(cfg, _NEON_HOLMES_CONFIG)
with open(HOLMES_CONFIG, "w") as f:
json.dump(cfg, f, indent=4, ensure_ascii=True)
try:
with open(OVOS_CONFIG) as f:
cfg = json.load(f)
except FileNotFoundError:
pass
except Exception as e:
LOG.error(e)

# make holmesV Configuration.get() load neon.conf
# TODO HolmesV does not yet support yaml configs, once it does
# Configuration.get() will be made to load the existing neon config files,
# for now it simply provides correct default values
setup_holmes_config()
cfg = merge_dict(cfg, _NEON_OVOS_CONFIG)
with open(OVOS_CONFIG, "w") as f:
json.dump(cfg, f, indent=4, ensure_ascii=True)


def setup_ovos_config():
"""
Configure ovos_utils to read from neon.conf files and set this path as the root.
"""
# TODO: This method will be handled in ovos-core directly in the future
# ensure ovos_utils can find neon_core
set_root_path(NEON_ROOT_PATH)
# make ovos_utils load the proper .conf files
Expand All @@ -82,6 +90,18 @@ def setup_ovos_config():

setup_ovos_config()

# make ovos-core Configuration.get() load neon.conf
# TODO ovos-core does not yet support yaml configs, once it does
# Configuration.get() will be made to load the existing neon config files,
# for now it simply provides correct default values
setup_ovos_core_config()

neon_config_path = join(xdg.BaseDirectory.save_config_path("neon"),
"neon.conf")
write_mycroft_compatible_config(neon_config_path)
# TODO: Consider when this log is valid/config is changed or not already synced with neon_config DM
LOG.info(f"{neon_config_path} will be overwritten with Neon YAML config contents.")

# patch version string to allow downstream to know where it is running
import mycroft.version
CORE_VERSION_STR = '.'.join(map(str, mycroft.version.CORE_VERSION_TUPLE)) + \
Expand Down
6 changes: 3 additions & 3 deletions neon_core/run_neon.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def _stop_all_core_processes():
procs = {p.pid: p.cmdline() for p in psutil.process_iter()}
for pid, cmdline in procs.items():
if cmdline and (any(pname in cmdline[-1] for pname in ("mycroft.messagebus.service", "neon_speech_client",
"neon_audio_client",
"neon_core.skills", "neon_core.gui"
"neon_audio_client", "neon_core.messagebus.service",
"neon_core.skills", "neon_core.gui",
"neon_core_server", "neon_enclosure_client",
"neon_core_client", "mycroft-gui-app",
"NGI.utilities.gui", "run_neon.py")
Expand All @@ -138,7 +138,7 @@ def _stop_all_core_processes():
psutil.Process(pid).terminate()
sleep(1)
if psutil.pid_exists(pid) and psutil.Process(pid).is_running():
LOG.error(f"Process {pid} not terminated!!")
LOG.info(f"Process {pid} not terminated!!")
psutil.Process(pid).kill()
except Exception as e:
LOG.error(e)
Expand Down

0 comments on commit cc858c2

Please sign in to comment.