Skip to content
This repository has been archived by the owner on Oct 24, 2021. It is now read-only.

Commit

Permalink
monkey
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Dec 29, 2020
1 parent 143e7ef commit e37f4b6
Show file tree
Hide file tree
Showing 53 changed files with 3,625 additions and 371 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include ovos_utils/res *
2 changes: 1 addition & 1 deletion examples/mark1_game_of_life.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ovos_utils.enclosure.mark1.faceplate.cellular_automaton import GoL
from ovos_utils.mark1.faceplate.animations import GoL
from ovos_utils.messagebus import get_mycroft_bus

bus = get_mycroft_bus("192.168.1.70")
Expand Down
4 changes: 2 additions & 2 deletions examples/mark1_image_rotate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ovos_utils.enclosure.mark1.faceplate.icons import Boat, MusicIcon, StormIcon, \
from ovos_utils.mark1.faceplate.icons import Boat, MusicIcon, StormIcon, \
SnowIcon, SunnyIcon, PartlyCloudyIcon, PlusIcon, SkullIcon, CrossIcon, \
HollowHeartIcon, HeartIcon, DeadFishIcon, InfoIcon, \
ArrowLeftIcon, JarbasAI, WarningIcon
Expand All @@ -24,7 +24,7 @@
InfoIcon(bus=bus),
DeadFishIcon(bus=bus)]

from ovos_utils.enclosure.mark1.faceplate.icons import SpaceInvader1, \
from ovos_utils.mark1.faceplate.icons import SpaceInvader1, \
SpaceInvader2, SpaceInvader3, SpaceInvader4
images = [SpaceInvader1(bus=bus),
SpaceInvader2(bus=bus),
Expand Down
2 changes: 1 addition & 1 deletion examples/mark1_pixel_wise.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ovos_utils.enclosure.mark1.faceplate.icons import FaceplateGrid
from ovos_utils.mark1.icons import FaceplateGrid
from ovos_utils.messagebus import get_mycroft_bus
from time import sleep

Expand Down
3 changes: 1 addition & 2 deletions examples/mark1_space_invader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ovos_utils.enclosure.mark1.faceplate.cellular_automaton import \
SpaceInvader
from ovos_utils.mark1.animations import SpaceInvader
from ovos_utils.messagebus import get_mycroft_bus
from time import sleep

Expand Down
24 changes: 22 additions & 2 deletions ovos_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
from time import sleep
import requests
import os
from os.path import isdir, join
from os.path import isdir, join, dirname
import re
import socket
from inflection import camelize, titleize, transliterate, parameterize, ordinalize


def get_ip():
Expand All @@ -43,6 +42,22 @@ def get_external_ip():
return requests.get('https://api.ipify.org').text


def resolve_ovos_resource_file(res_name):
"""Convert a resource into an absolute filename.
used internally for ovos resources
"""
# First look for fully qualified file (e.g. a user setting)
if os.path.isfile(res_name):
return res_name

# now look in bundled ovos resources
filename = join(dirname(__file__), "res", res_name)
if os.path.isfile(filename):
return filename

return None # Resource cannot be resolved


def get_mycroft_root():
paths = [
"/opt/venvs/mycroft-core/lib/python3.7/site-packages/", # mark1/2
Expand Down Expand Up @@ -98,6 +113,11 @@ def resolve_resource_file(res_name, root_path=None):
if os.path.isfile(filename):
return filename

# look in ovos_utils package itself
found = resolve_ovos_resource_file(res_name)
if found:
return found

# Finally look for it in the source package
paths = [
"/opt/venvs/mycroft-core/lib/python3.7/site-packages/", # mark1/2
Expand Down
116 changes: 71 additions & 45 deletions ovos_utils/configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from ovos_utils.log import LOG
from ovos_utils.enclosure import enclosure2rootdir, detect_enclosure
from ovos_utils.enclosure import MycroftEnclosures
from ovos_utils.json_helper import merge_dict, load_commented_json
from os.path import isfile, exists, expanduser, join, dirname, isdir
from os import makedirs
Expand All @@ -9,43 +7,9 @@
MYCROFT_SYSTEM_CONFIG = "/etc/mycroft/mycroft.conf"
MYCROFT_USER_CONFIG = join(expanduser("~"), ".mycroft", "mycroft.conf")

# TODO use json_database

def get_config_fingerprint():
conf = read_mycroft_config()
listener_conf = conf.get("listener", {})
skills_conf = conf.get("skills", {})
return {
"enclosure": conf.get("enclosure", {}).get("platform"),
"data_dir": conf.get("data_dir"),
"msm_skills_dir": skills_conf.get("msm", {}).get("directory"),
"ipc_path": conf.get("ipc_path"),
"input_device_name": listener_conf.get("device_name"),
"input_device_index": listener_conf.get("device_index"),
"default_audio_backend": conf.get("Audio", {}).get("default-backend"),
"priority_skills": skills_conf.get("priority_skills"),
"backend_url": conf.get("server", {}).get("url")
}


def read_mycroft_config():
conf = LocalConf(None)
conf.merge(MycroftDefaultConfig())
conf.merge(MycroftSystemConfig())
conf.merge(MycroftUserConfig())
return conf


def update_mycroft_config(config, path=None):
if path is None:
conf = MycroftUserConfig()
else:
conf = LocalConf(path)
conf.merge(config)
conf.store()
return conf


# TODO use json_database.JsonStorage
class LocalConf(dict):
"""
Config dict from file.
Expand Down Expand Up @@ -138,24 +102,41 @@ def store(self, path=None):
class MycroftUserConfig(LocalConf):
def __init__(self):
path = MYCROFT_USER_CONFIG
enclosure = detect_enclosure()
if enclosure == MycroftEnclosures.MARK1 or \
enclosure == MycroftEnclosures.OLD_MARK1:
if self._is_mycroft_device():
path = "/home/mycroft/.mycroft/mycroft.conf"
super().__init__(path)

@staticmethod
def _is_mycroft_device():
paths = [
"/opt/venvs/mycroft-core/lib/python3.7/site-packages/", # mark1/2
"/opt/venvs/mycroft-core/lib/python3.4/site-packages/ " # old mark1 installs
]
for p in paths:
if isdir(p):
return True
return False


class MycroftDefaultConfig(ReadOnlyConfig):
def __init__(self):
path = join(enclosure2rootdir(), "mycroft",
"configuration", "mycroft.conf")
path = None
# TODO check system config platform and go directly to correct path if it exists
paths = [
"/opt/venvs/mycroft-core/lib/python3.7/site-packages/", # mark1/2
"/opt/venvs/mycroft-core/lib/python3.4/site-packages/ ", # old mark1 installs
"/home/pi/mycroft-core" # picroft
]
for p in paths:
p = join(p, "mycroft", "configuration", "mycroft.conf")
if isfile(p):
path = p
super().__init__(path)
if not self.path or not isfile(self.path):
LOG.warning("mycroft root path not found")

def set_root_config_path(self, root_config):
# in case we got it wrong / non standard
self.path = root_config
def set_mycroft_root(self, mycroft_root_path):
self.path = join(mycroft_root_path, "mycroft", "configuration", "mycroft.conf")
self.reload()


Expand All @@ -164,4 +145,49 @@ def __init__(self, allow_overwrite=False):
super().__init__(MYCROFT_SYSTEM_CONFIG, allow_overwrite)


def read_mycroft_config():
conf = LocalConf(None)
conf.merge(MycroftDefaultConfig())
conf.merge(MycroftSystemConfig())
conf.merge(MycroftUserConfig())
return conf


def update_mycroft_config(config, path=None):
if path is None:
conf = MycroftUserConfig()
else:
conf = LocalConf(path)
conf.merge(config)
conf.store()
return conf


def blacklist_skill(skill):
skills_config = read_mycroft_config().get("skills", {})
blacklisted_skills = skills_config.get("blacklisted_skills", [])
if skill not in blacklisted_skills:
blacklisted_skills.append(skill)
conf = {
"skills": {
"blacklisted_skills": blacklisted_skills
}
}
update_mycroft_config(conf)
return True
return False


def whitelist_skill(skill):
skills_config = read_mycroft_config().get("skills", {})
blacklisted_skills = skills_config.get("blacklisted_skills", [])
if skill in blacklisted_skills:
blacklisted_skills.pop(skill)
conf = {
"skills": {
"blacklisted_skills": blacklisted_skills
}
}
update_mycroft_config(conf)
return True
return False
Loading

0 comments on commit e37f4b6

Please sign in to comment.