コード例 #1
0
 def reset_location(self, dummy=None):
     if not self.settings["tracking"]:
         self.emitter.emit(
             Message("configuration.patch", {"config": self.home_location}))
         conf = LocalConf(USER_CONFIG)
         conf['location'] = self.home_location
         conf.store()
コード例 #2
0
    def handle_change_lang_intent(self, message):
        lang = message.data.get("lang", self.lang)
        if self.validate_language(lang):
            if lang[:2] in self.lang_map and lang not in self.lang_map:
                lang = lang[:2]
            elif lang not in self.lang_map:
                for l in self.lang_map:
                    if self.lang_map[l].lower() == lang.lower():
                        lang = l
                        break
            lang_name = lang
            if lang_name in self.lang_map:
                lang_name = self.lang_map[lang_name]
            self.speak_dialog("new_lang", {"language": lang_name})
            conf = LocalConf(USER_CONFIG)
            conf['lang'] = lang

            stt = self.config_core["stt"]
            stt["module"] = "google"
            if "google" not in stt:
                stt["google"] = {}
            if "credential" not in stt["google"]:
                stt["google"] = {"credential": {}}
            if "token" not in stt["google"]["credential"]:
                stt["google"][
                    "credential"] = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw"
            conf["stt"] = "google"

            tts = self.config_core["tts"]
            tts["module"] = "google"
            conf["tts"] = tts
            conf.store()
            self.emitter.emit(message.reply("mycroft.reboot", {}))
        else:
            self.speak_dialog("invalid_language", {"language": self.lang})
コード例 #3
0
 def from_ip_db(self, ip=None, update=True):
     self.log.info("Retrieving location data from ip database")
     ip = ip or self.get_ip()
     g = pygeoip.GeoIP(self.settings["geo_ip_db"])
     data = g.record_by_addr(ip) or {}
     city = data.get("city", "")
     region_code = data.get("region_code", "")
     country_code = data.get("country_code", "")
     country_name = data.get("country_name", "")
     region = city
     longitude = data.get("longitude", "")
     latitude = data.get("latitude", "")
     timezone = data.get("time_zone", "")
     city_code = data.get("postal_code", "")
     data = self.build_location_dict(city, region_code, country_code,
                                     country_name, region, longitude,
                                     latitude, timezone, city_code)
     config = {"location": data, "address": city + ", " + country_name}
     if update:
         self.emitter.emit(
             Message("configuration.patch", {"config": config}))
         self.config_core["location"] = data
         conf = LocalConf(USER_CONFIG)
         conf['location'] = data
         conf.store()
     return config
コード例 #4
0
ファイル: __init__.py プロジェクト: HelloChatterbox/HolmesV
def is_backend_disabled():
    configs = [
        LocalConf(DEFAULT_CONFIG),
        LocalConf(SYSTEM_CONFIG),
        LocalConf(USER_CONFIG)
    ]
    config = Configuration.load_config_stack(configs)
    return config["server"].get("disabled") or False
コード例 #5
0
 def __init__(self, path):
     self.path = path
     config = Configuration.get([
         LocalConf(DEFAULT_CONFIG),
         LocalConf(SYSTEM_CONFIG),
         LocalConf(USER_CONFIG)
     ],
                                cache=False)
     config_server = config.get("server")
     self.url = config_server.get("url")
     self.version = config_server.get("version")
     self.identity = IdentityManager.get()
コード例 #6
0
 def bind_engine(self, engine, priority=4):
     conf = LocalConf(USER_CONFIG)
     priority_skills = Configuration.get().get("skills", {}).get(
         "priority_skills", [])
     priority_skills.append(self._dir.split("/")[-1])
     conf.store()
     self.priority = priority
     self.engine = engine
     self.config = engine.config
     self.register_messages(engine.name)
     self.register_fallback(self.handle_fallback, self.priority)
     self.finished_training_event = Event()
     self.finished_initial_train = False
     self.train_delay = self.config.get('train_delay', 4)
     self.train_time = get_time() + self.train_delay
コード例 #7
0
    def handle_rate_speech(self, message):
        from mycroft.configuration.config import (LocalConf, Configuration,
                                                  USER_CONFIG)
        user_config = LocalConf(USER_CONFIG)
        LOG.info(str(user_config))

        user_level = message.data.get('ratelevel')
        LOG.info(user_level)
        rate_var = self.get_rate_var(user_level)

        if (rate_var == "error"):
            self.speak_dialog("invalidInput", {'userLevel': user_level})
        else:
            new_config = {
                "tts": {
                    "mimic": {
                        "duration_stretch": str(rate_var)
                    }
                }
            }
            user_config.merge(new_config)
            user_config.store()

            LOG.info(str(LocalConf(USER_CONFIG)))
            self.bus.emit(Message('configuration.updated'))
            self.speak_dialog("rate.speech", {'rateLevel': user_level})
コード例 #8
0
    def from_wifi(self, update=True):
        if not self.settings["google_geolocate_key"]:
            self.speak("you need a google geolocation services api key "
                       "in order to use wifi geolocation")
            self.log.error("you need a google geolocation services api key "
                           "in order to use wifi geolocation")
            return {}
        lat, lon, accuracy = wifi_geolocate(
            api=self.settings["google_geolocate_key"],
            sudo=self.settings["wifi_sudo"])
        LOG.info("\nlatitude: " + str(lat) + "\nlongitude: " + str(lon) +
                 "\naccuracy (meters) : " + str(accuracy))
        data = reverse_geolocate(lat, lon)
        data["accuracy"] = accuracy
        LOG.info("reverse geocoding data: " + str(data))
        location = self.location.copy()
        location["address"] = data["address"]
        if data.get("zip"):
            location["city"]["code"] = data["zip"]
        else:
            location["city"]["code"] = data["city"]
        location["city"]["name"] = data["city"]
        location["city"]["state"]["name"] = data["state"]
        # TODO state code
        location["city"]["state"]["code"] = data["state"]
        location["city"]["state"]["country"]["name"] = data["country"]
        # TODO country code
        location["city"]["state"]["country"]["code"] = data["country"]
        location["coordinate"]["latitude"] = data["latitude"]
        location["coordinate"]["longitude"] = data["longitude"]

        timezone = get_timezone(data["latitude"], data["longitude"])
        # TODO timezone name
        location["timezone"]["name"] = timezone
        location["timezone"]["code"] = timezone

        config = {"location": location}
        if update:
            self.emitter.emit(
                Message("configuration.patch", {"config": config}))
            self.config_core["location"] = location
            conf = LocalConf(USER_CONFIG)
            conf['location'] = location
            conf.store()
        return config
コード例 #9
0
    def handle_disable_precise_dev(self, message):
        from mycroft.configuration.config import (LocalConf, USER_CONFIG)

        for item in glob(expanduser('~/.mycroft/precise/precise-engine*')):
            self.log.info('Removing: {}...'.format(item))
            if isdir(item):
                rmtree(item)
            else:
                os.remove(item)
        local_conf = LocalConf(USER_CONFIG)
        pconfig = local_conf.get('precise', {})
        if pconfig.get('dist_url') == self.PRECISE_DEV_DIST_URL:
            del pconfig['dist_url']
        if pconfig.get('model_url') == self.PRECISE_DEV_MODEL_URL:
            del pconfig['model_url']
        local_conf.store()

        self.bus.emit(Message('configuration.updated'))
        self.speak_dialog('precise.devmode.disabled')
コード例 #10
0
    def handle_set_listener(self, message):
        from mycroft.configuration.config import (LocalConf, USER_CONFIG,
                                                  Configuration)
        module = message.data['ListenerType'].replace(' ', '')
        module = module.replace('default', 'pocketsphinx')
        name = module.replace('pocketsphinx', 'pocket sphinx')

        if self.get_listener() == module:
            self.speak_dialog('listener.same', data={'listener': name})
            return

        wake_word = Configuration.get()['listener']['wake_word']

        new_config = {'hotwords': {wake_word: {'module': module}}}
        user_config = LocalConf(USER_CONFIG)
        user_config.merge(new_config)
        user_config.store()

        self.bus.emit(Message('configuration.updated'))

        if module == 'precise':
            engine_folder = expanduser('~/.mycroft/precise/precise-engine')
            if not isdir(engine_folder):
                self.speak_dialog('download.started')
                return

        self.speak_dialog('set.listener', data={'listener': name})
コード例 #11
0
 def set_single_thread(self, update):
     new_config = {'padatious': {'single_thread': update}}
     user_config = LocalConf(USER_CONFIG)
     user_config.merge(new_config)
     user_config.store()
     self.log.info('Setting padatious single_thread = ' + str(update))
     self.bus.emit(Message('configuration.updated'))
コード例 #12
0
    def config(self, name, message):
        from mycroft.configuration.config import (
            LocalConf, USER_CONFIG, Configuration
        )
        module = "precise".replace(' ', '')
        module = module.replace('default', 'pocketsphinx')

        precise_file = self.select_precise_file(name, message)
        if precise_file == None:
            self.log.info("precise file "+name+" not found")
            return
        else:
            self.log.info("set precise file: "+precise_file)

            wake_word = name
            self.log.info("set precise WakeWord:"+name)
            new_config = {"listener": {"wake_word": name, "record_wake_words": "true"}, "hotwords": {wake_word:
                        {"module": module, "threshold": "1e-90", "lang": self.lang,"local_model_file": precise_file}}
            }
            user_config = LocalConf(USER_CONFIG)
            user_config.merge(new_config)
            user_config.store()

            self.bus.emit(Message('configuration.updated'))

            if module == 'precise':
                engine_folder = expanduser('~/.mycroft/precise/precise-engine')
                if not os.path.isdir(engine_folder):
                    self.speak_dialog('download.started')
                    return

            self.speak_dialog('end.calculating', data={'name': name})
コード例 #13
0
    def _disable_listen_beep(self):
        user_config = LocalConf(USER_CONFIG)

        if 'user_beep_setting' not in self.settings:
            # Save any current local config setting
            self.settings['user_beep_setting'] = (
                user_config.get("confirm_listening", None))

            # Disable in local config
            user_config.merge({"confirm_listening": False})
            user_config.store()

            # Notify all processes to update their loaded configs
            self.bus.emit(Message('configuration.updated'))
コード例 #14
0
ファイル: __init__.py プロジェクト: MycroftAI/skill-mark-2
 def _sync_wake_beep_setting(self):
     """ Update "use beep" global config from skill settings. """
     config = Configuration.get()
     use_beep = self.settings.get("use_listening_beep", False)
     if not config["confirm_listening"] == use_beep:
         # Update local (user) configuration setting
         new_config = {"confirm_listening": use_beep}
         user_config = LocalConf(USER_CONFIG)
         user_config.merge(new_config)
         user_config.store()
         self.bus.emit(Message("configuration.updated"))
コード例 #15
0
    def save_upgrade_permission(self, ver):
        # Build version as float, e.g. [18,8,999] as 18.8
        float_ver = ver[0] + ver[1] / 10  # assumes minor is <= 9
        new_conf_values = {"max_allowed_core_version": float_ver}

        # Save under the user (e.g. ~/.mycroft/mycroft.conf)
        user_config = LocalConf(USER_CONFIG)
        user_config.merge(new_conf_values)
        user_config.store()

        # Notify all processes to update their loaded configs
        self.bus.emit(Message('configuration.updated'))
コード例 #16
0
 def _sync_wake_beep_setting(self):
     from mycroft.configuration.config import (LocalConf, USER_CONFIG,
                                               Configuration)
     config = Configuration.get()
     use_beep = self.settings.get("use_listening_beep") == "true"
     if not config['confirm_listening'] == use_beep:
         # Update local (user) configuration setting
         new_config = {'confirm_listening': use_beep}
         user_config = LocalConf(USER_CONFIG)
         user_config.merge(new_config)
         user_config.store()
         self.emitter.emit(Message('configuration.updated'))
コード例 #17
0
 def _sync_wake_beep_setting(self):
     """ Update "use beep" global config from skill settings. """
     from mycroft.configuration.config import (LocalConf, USER_CONFIG,
                                               Configuration)
     config = Configuration.get()
     use_beep = self.settings.get('use_listening_beep') is True
     if not config['confirm_listening'] == use_beep:
         # Update local (user) configuration setting
         new_config = {'confirm_listening': use_beep}
         user_config = LocalConf(USER_CONFIG)
         user_config.merge(new_config)
         user_config.store()
         self.bus.emit(Message('configuration.updated'))
コード例 #18
0
    def _restore_listen_beep(self):
        if 'user_beep_setting' in self.settings:
            # Wipe from local config
            new_conf_values = {"confirm_listening": False}
            user_config = LocalConf(USER_CONFIG)

            if (self.settings["user_beep_setting"] is None and
                    "confirm_listening" in user_config):
                del user_config["confirm_listening"]
            else:
                user_config.merge({"confirm_listening":
                                   self.settings["user_beep_setting"]})
            user_config.store()

            # Notify all processes to update their loaded configs
            self.bus.emit(Message('configuration.updated'))
            del self.settings["user_beep_setting"]
コード例 #19
0
    def handle_set_listener(self, message):
        try:
            from mycroft.configuration.config import (LocalConf, USER_CONFIG,
                                                      Configuration)
            module = message.data['ListenerType'].replace(' ', '')
            module = module.replace('default', 'pocketsphinx')
            name = module.replace('pocketsphinx', 'pocket sphinx')
            config = Configuration.get()

            if config['hotwords']['hey mycroft']['module'] == module:
                self.speak_dialog('listener.same', data={'listener': name})
                return

            new_config = {
                'precise': {
                    'dist_url':
                    'http://bootstrap.mycroft.ai/'
                    'artifacts/static/daily/'
                },
                'hotwords': {
                    'hey mycroft': {
                        'module': module
                    }
                }
            }
            user_config = LocalConf(USER_CONFIG)
            user_config.merge(new_config)
            user_config.store()

            self.emitter.emit(Message('configuration.updated'))

            if module == 'precise':
                exe_path = expanduser('~/.mycroft/precise/precise-stream')
                if isfile(exe_path):
                    self.enclosure.mouth_text('Checking version...')
                    version = check_output([exe_path, '-v'], stderr=STDOUT)
                    if version.strip() == '0.1.0':
                        os.remove(exe_path)
                    self.enclosure.mouth_reset()
                else:
                    self.speak_dialog('download.started')
                    return

            self.speak_dialog('set.listener', data={'listener': name})
        except (NameError, SyntaxError, ImportError):
            self.speak_dialog('must.update')
コード例 #20
0
    def handle_level_decrease(self, message):
        from mycroft.configuration.config import (LocalConf, USER_CONFIG)
        new_rate = self.curr_level + 0.10
        if new_rate <= 2.0 and new_rate > 0.1:
            new_config = {
                "tts": {
                    "mimic": {
                        "duration_stretch": str(new_rate)
                    }
                }
            }
            user_config = LocalConf(USER_CONFIG)
            user_config.merge(new_config)
            user_config.store()

            self.curr_level = new_rate
            self.bus.emit(Message('configuration.updated'))
            self.speak_dialog('updatedLevel', {'directionChange': 'decreased'})
        else:
            self.speak_dialog("invalidLevel")
コード例 #21
0
    def handle_use_precise_dev(self, message):
        from mycroft.configuration.config import (LocalConf, USER_CONFIG,
                                                  Configuration)

        wake_word = Configuration.get()['listener']['wake_word']

        new_config = {
            'precise': {
                "dist_url": self.PRECISE_DEV_DIST_URL,
                "model_url": self.PRECISE_DEV_MODEL_URL
            },
            'hotwords': {
                wake_word: {
                    'module': 'precise',
                    'sensitivity': 0.5
                }
            }
        }
        user_config = LocalConf(USER_CONFIG)
        user_config.merge(new_config)
        user_config.store()

        self.bus.emit(Message('configuration.updated'))
        self.speak_dialog('precise.devmode.enabled')
コード例 #22
0
 def _update_config(self, config):
     from mycroft.configuration.config import (LocalConf, USER_CONFIG)
     user_config = LocalConf(USER_CONFIG)
     user_config.merge(config)
     user_config.store()
     self.bus.emit(Message('configuration.updated'))
コード例 #23
0
ファイル: util.py プロジェクト: badcons2002/mycroft
from mycroft.configuration.config import LocalConf, DEFAULT_CONFIG
from copy import deepcopy

__config = LocalConf(DEFAULT_CONFIG)


# Base config to use when mocking
def base_config():
    return deepcopy(__config)


class Anything:
    """Class matching any object.

    Useful for assert_called_with arguments.
    """
    def __eq__(self, other):
        return True
コード例 #24
0
ファイル: core.py プロジェクト: yoyoo2/mycroft-core
import mock
from adapt.intent import IntentBuilder
from os.path import join, dirname, abspath
from re import error
from datetime import datetime

from mycroft.configuration import Configuration
from mycroft.messagebus.message import Message
from mycroft.skills.skill_data import load_regex_from_file, load_regex, \
    load_vocab_from_file, load_vocabulary
from mycroft.skills.core import MycroftSkill, load_skill, \
    create_skill_descriptor, open_intent_envelope

from mycroft.configuration.config import LocalConf, DEFAULT_CONFIG

BASE_CONF = LocalConf(DEFAULT_CONFIG)


class MockEmitter(object):
    def __init__(self):
        self.reset()

    def emit(self, message):
        self.types.append(message.type)
        self.results.append(message.data)

    def get_types(self):
        return self.types

    def get_results(self):
        return self.results
コード例 #25
0
ファイル: __init__.py プロジェクト: TREE-Ind/wake-word-skill
 def save_wakewords(self):
     from mycroft.configuration.config import (LocalConf, USER_CONFIG,
                                               Configuration)
     record = Configuration.get()['listener']['record_wake_words']
     if self.settings["savewakewords"] is True:
         free_mb = psutil.disk_usage('/')[2] / 1024 / 1024
         if free_mb <= self.settings["min_free_disk"]:
             self.log.info("no space: deactivate recording")
             new_config = {"listener": {"record_wake_words": "true"}}
             user_config = LocalConf(USER_CONFIG)
             user_config.merge(new_config)
             user_config.store()
         if record == "false":
             new_config = {"listener": {"record_wake_words": "true"}}
             self.log.info("set wake word recording")
             user_config = LocalConf(USER_CONFIG)
             user_config.merge(new_config)
             user_config.store()
             self.settings.update
     else:
         if record == "true":
             new_config = {"listener": {"record_wake_words": "false"}}
             self.log.info("unset wake word recording")
             user_config = LocalConf(USER_CONFIG)
             user_config.merge(new_config)
             user_config.store()
             self.settings.update
コード例 #26
0
ファイル: __init__.py プロジェクト: indigos33k3r/ZZZ-py_msm
 def update_skills_config(self, config=None):
     conf = LocalConf(USER_CONFIG)
     conf['skills'] = config or self.skills_config
     conf.store()
     self.send_message("skills.config.updated")
コード例 #27
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from copy import deepcopy
from unittest.mock import Mock

from msm import MycroftSkillsManager
from msm.skill_repo import SkillRepo

from mycroft.configuration.config import LocalConf, DEFAULT_CONFIG

__CONFIG = LocalConf(DEFAULT_CONFIG)


def base_config():
    """Base config used when mocking.

    Preload to skip hitting the disk each creation time but make a copy
    so modifications don't mutate it.

    Returns:
        (dict) Mycroft default configuration
    """
    return deepcopy(__CONFIG)


def mock_msm(temp_dir):
コード例 #28
0
    def from_remote_ip(self, update=True):
        self.log.info("Retrieving location data from ip address api")
        if connected():
            response = requests.get("https://ipapi.co/json/").json()
            response = json.loads(response)
            city = response.body.get("city")
            region_code = response.body.get("region_code")
            country = response.body.get("country")
            country_name = response.body.get("country_name")
            region = response.body.get("region")
            lon = response.body.get("longitude")
            lat = response.body.get("latitude")
            timezone = response.body.get("timezone")
            if timezone is None:
                timezone_data = self.location.get(
                    "timezone", self.home_location.get("timezone", {}))
            else:
                timezone_data = {
                    "code": timezone,
                    "name": timezone,
                    "dstOffset": 3600000,
                    "offset": -21600000
                }

            region_data = {
                "code": region_code,
                "name": region,
                "country": {
                    "code": country,
                    "name": country_name
                }
            }
            city_data = {
                "code": city,
                "name": city,
                "state": region_data,
                "region": region_data
            }

            coordinate_data = {"latitude": float(lat), "longitude": float(lon)}
            location_data = {
                "city": city_data,
                "coordinate": coordinate_data,
                "timezone": timezone_data
            }
            config = {
                "location": location_data,
                "address": city + ", " + country_name
            }
            if update:
                self.emitter.emit(
                    Message("configuration.patch", {"config": config}))
                self.config_core["location"] = location_data
                conf = LocalConf(USER_CONFIG)
                conf['location'] = location_data
                conf.store()
            return config
        else:
            self.log.warning("No internet connection, could not update "
                             "location from ip address")
            return {}