def handle_clear_history(self, message): video_data = message.data["modelData"] if video_data["skill_id"] == self.skill_id: historyDB = JsonStorageXDG( "{msg_base}.history".format(msg_base=self.message_namespace)) historyDB["model"] = [] historyDB.store()
def add_to_history(self, video_data): # History historyDB = JsonStorageXDG("{msg_base}.history".format(msg_base=self.message_namespace)) if "model" not in historyDB: historyDB["model"] = [] historyDB["model"].append(video_data) historyDB.store() self.gui["historyModel"] = historyDB["model"]
def __init__(self): self.config = JsonStorageXDG("OVOS-SkillsManager") default_config = { "local": { "active": True, "url": get_skills_folder(), "parse_github": False, "priority": 1 }, "ovos": { "active": True, "url": "https://github.com/OpenVoiceOS/OVOS-appstore", "parse_github": False, "priority": 2 }, "mycroft_marketplace": { "active": False, "url": "https://market.mycroft.ai/", "parse_github": False, "priority": 5 }, "pling": { "active": False, "url": "https://apps.plasma-bigscreen.org/", "parse_github": False, "priority": 10 }, "neon": { "active": False, "url": "https://github.com/NeonGeckoCom/neon-skills-submodules/", "parse_github": False, "auth_token": None, "priority": 50 }, "andlo_skill_list": { "active": False, "url": "https://andlo.gitbook.io/mycroft-skills-list/", "parse_github": False, "priority": 100 } } if "appstores" not in self.config: # NOTE, below should match Appstore.appstore_id self.config["appstores"] = default_config self.save_config() self.config["appstores"] = merge_dict(self.config["appstores"], default_config, new_only=True, no_dupes=True) self._boostrap_tracker = {} self.save_config() self._threads = []
def _upgrade_0_0_10a3(config: JsonStorageXDG = None): """Upgrade early alphas to v0.0.10a3 Migrates config file from JsonStorageXDG to JsonConfigXDG, and changes the subdirectory to OpenVoiceOS, resulting in the path `~/.config/OpenVoiceOS/OVOS-SkillsManager.json` """ if isinstance(config, JsonConfigXDG): # This upgrade's only purpose is to migrate config from JsonStorageXDG to # JsonConfigXDG. We have arrived here in error. Goodbye. return config # Migrate config file old_config = config or JsonStorageXDG("OVOS-SkillsManager") if path.exists(old_config.path): new_config = \ JsonConfigXDG("OVOS-SkillsManager", subfolder="OpenVoiceOS").merge(old_config, skip_empty=False) new_config.store() remove(old_config.path) return new_config raise FileNotFoundError( "Unable to execute OSM upgrade 0.0.9 --> 0.0.10a3: " "could not find old config")
def authenticate(self, auth_token=None, bootstrap=True): if auth_token is None: auth_token = JsonStorageXDG("OVOS-SkillsManager")["appstores"]\ .get(self.appstore_id, {}).get("auth_token") if auth_token: set_github_token(auth_token) if bootstrap: self.bootstrap()
def _find_and_perform_osm_upgrades(config: JsonStorageXDG) -> JsonStorageXDG: """ Accepts and returns config. Iterates over possible upgrades, applying the earliest unapplied upgrade and bumping config's version. Loops until there are no more upgrades to apply. The outermost function will bump config to the current OSM version, regardless of whether any upgrades were applied. """ last_upgrade = version.parse(config.get('last_upgrade')) for upgrade_version, upgrade_path in UPGRADE_PATHS.items(): if upgrade_version > last_upgrade: upgrade_string = str(upgrade_version) echo(f"Running OSM upgrade: v{upgrade_string} ", nl=False) config = upgrade_path( config ) # upgrade routines should accept and then return config, # in case it moves config["last_upgrade"] = upgrade_string config["version"] = upgrade_string config.store() echo("... done") echo("All OSM upgrades applied. ", nl=False) return config
def _existing_osm_config() -> Union[JsonStorageXDG, JsonConfigXDG]: """NOTE: Use get_config_object() unless you're migrating config! Tries to locate the OSM config file, first trying the current path, and then checking the old location (used by the migration upgrade) Returns: [JsonConfigXDG|JsonStorageXDG|None]: the existing OSM config, or None """ config = JsonConfigXDG("OVOS-SkillsManager", subfolder="OpenVoiceOS") if not path.exists(config.path): # Check for legacy config config = JsonStorageXDG("OVOS-SkillsManager") if not path.exists(config.path): return None return config
from json_database import JsonStorageXDG from json_database.search import Query from pprint import pprint db = JsonStorageXDG("dust") q = Query(db).bellow_or_equal("duration", 130).build() #pprint(q) q = Query(db).above_or_equal("rating", 3).build() #pprint(q) q = Query(db).value_contains_token("title", "noir", ignore_case=True).build() pprint(q)
class OVOSSkillsManager: def __init__(self): self.config = JsonStorageXDG("OVOS-SkillsManager") default_config = { "local": { "active": True, "url": get_skills_folder(), "parse_github": False, "priority": 1 }, "ovos": { "active": True, "url": "https://github.com/OpenVoiceOS/OVOS-appstore", "parse_github": False, "priority": 2 }, "mycroft_marketplace": { "active": False, "url": "https://market.mycroft.ai/", "parse_github": False, "priority": 5 }, "pling": { "active": False, "url": "https://apps.plasma-bigscreen.org/", "parse_github": False, "priority": 10 }, "neon": { "active": False, "url": "https://github.com/NeonGeckoCom/neon-skills-submodules/", "parse_github": False, "auth_token": None, "priority": 50 }, "andlo_skill_list": { "active": False, "url": "https://andlo.gitbook.io/mycroft-skills-list/", "parse_github": False, "priority": 100 } } if "appstores" not in self.config: # NOTE, below should match Appstore.appstore_id self.config["appstores"] = default_config self.save_config() self.config["appstores"] = merge_dict(self.config["appstores"], default_config, new_only=True, no_dupes=True) self._boostrap_tracker = {} self.save_config() self._threads = [] def get_active_appstores(self, bootstrap=False): stores = {} for appstore_id in self.config["appstores"]: if self.config["appstores"][appstore_id]["active"]: if bootstrap and appstore_id not in self._boostrap_tracker: self._boostrap_tracker[appstore_id] = True elif bootstrap and appstore_id in self._boostrap_tracker: bootstrap = False stores[appstore_id] = self.get_appstore(appstore_id, bootstrap=bootstrap) return stores def get_appstore(self, appstore_id, bootstrap=True): if self.config["appstores"][appstore_id]["active"]: parse_github = self.config["appstores"][appstore_id][ "parse_github"] store = self.name_to_appstore(appstore_id) if bootstrap and appstore_id not in self._boostrap_tracker: self._boostrap_tracker[appstore_id] = True elif bootstrap and appstore_id in self._boostrap_tracker: bootstrap = False return store(parse_github=parse_github, bootstrap=bootstrap) return None @staticmethod def name_to_appstore(name): if name in ["pling", "bigscreen"]: return Pling elif name in ["mycroft", "mycroft_marketplace"]: return MycroftMarketplace elif name in ["andlo", "andlo_skill_list"]: return AndloSkillList elif name in ["ovos", "ovos_appstore", "ovos_marketplace"]: return OVOSstore elif name in ["neon", "neon_gecko", "neon_skills"]: return NeonSkills elif name in [ "local", "local_skills", "installed", "installed_skills" ]: return InstalledSkills else: raise UnknownAppstore def save_config(self): self.config.store() def clear_cache(self, appstore_id=None): if appstore_id: self.get_appstore(appstore_id).clear_cache() else: for appstore in self.appstores: appstore.clear_cache() def validate_appstore_name(self, appstore): if appstore in ["pling", "bigscreen"]: appstore = "pling" elif appstore in ["mycroft", "mycroft_marketplace"]: appstore = "mycroft_marketplace" elif appstore in ["andlo", "andlo_skill_list"]: appstore = "andlo_skill_list" elif appstore in ["ovos", "ovos_appstore", "ovos_marketplace"]: appstore = "ovos" elif appstore in ["neon", "neon_gecko", "neon_skills"]: appstore = "neon" elif appstore in [ "local", "local_skills", "installed", "installed_skills" ]: appstore = "local" elif appstore not in self.config["appstores"]: raise UnknownAppstore return appstore def enable_appstore(self, appstore_id): appstore_id = self.validate_appstore_name(appstore_id) self.config["appstores"][appstore_id]["active"] = True def set_appstore_priority(self, appstore_id, priority): appstore_id = self.validate_appstore_name(appstore_id) self.config["appstores"][appstore_id]["priority"] = priority def set_appstore_auth_token(self, appstore_id, token): appstore_id = self.validate_appstore_name(appstore_id) self.config["appstores"][appstore_id]["auth_token"] = token def disable_appstore(self, appstore_id): appstore_id = self.validate_appstore_name(appstore_id) self.config["appstores"][appstore_id]["active"] = False def sync_appstores(self, merge=False, new_only=True, threaded=False): stores = self.get_active_appstores() for appstore_id in stores: LOG.info("Syncing skills from " + appstore_id) store = stores[appstore_id] store.authenticate() if threaded: # TODO this will cause auth issues t = store.sync_skills_list_threaded(merge, new_only) self._threads.append(t) else: store.sync_skills_list(merge, new_only) store.clear_authentication() @property def total_skills(self): return sum([s.total_skills() for s in self.appstores]) @property def appstores(self): stores = [] for appstore_id in self.config["appstores"]: store = self.get_appstore(appstore_id) if not store: continue priority = self.config["appstores"][appstore_id]["priority"] stores.append((store, priority)) return [s[0] for s in sorted(stores, key=lambda k: k[1])] def search_skills(self, name, as_json=False, fuzzy=True, thresh=0.85, ignore_case=True): for store in self.appstores: store.authenticate() for skill in store.search_skills(name, as_json, fuzzy, thresh, ignore_case): yield skill store.clear_authentication() def search_skills_by_id(self, skill_id, as_json=False, fuzzy=False, thresh=0.85, ignore_case=True): """ skill_id is repo.author , case insensitive, searchs by name and filters results by author """ for store in self.appstores: store.authenticate() for skill in store.search_skills_by_id(skill_id, as_json, fuzzy=fuzzy, ignore_case=ignore_case, thresh=thresh): yield skill store.clear_authentication() def search_skills_by_name(self, name, as_json=False, fuzzy=True, thresh=0.85, ignore_case=True): for store in self.appstores: store.authenticate() for skill in store.search_skills_by_name(name, as_json, fuzzy, thresh, ignore_case): yield skill store.clear_authentication() def search_skills_by_url(self, url, as_json=False): for store in self.appstores: store.authenticate() for skill in store.search_skills_by_url(url, as_json): store.clear_authentication() return skill def search_skills_by_category(self, category, as_json=False, fuzzy=True, thresh=0.85, ignore_case=True): for store in self.appstores: store.authenticate() for skill in store.search_skills_by_category( category, as_json, fuzzy, thresh, ignore_case): yield skill store.clear_authentication() def search_skills_by_author(self, authorname, as_json=False, fuzzy=True, thresh=0.85, ignore_case=True): for store in self.appstores: store.authenticate() for skill in store.search_skills_by_author(authorname, as_json, fuzzy, thresh, ignore_case): yield skill store.clear_authentication() def search_skills_by_tag(self, tag, as_json=False, fuzzy=True, thresh=0.85, ignore_case=True): for store in self.appstores: store.authenticate() for skill in store.search_skills_by_tag(tag, as_json, fuzzy, thresh, ignore_case): yield skill store.clear_authentication() def search_skills_by_description(self, value, as_json=False, fuzzy=True, thresh=0.85, ignore_case=True): for store in self.appstores: store.authenticate() for skill in store.search_skills_by_description( value, as_json, fuzzy, thresh, ignore_case): yield skill store.clear_authentication() def install_skill(self, skill): """ Installs a SkillEntry with any required auth_token """ store = None try: self.validate_appstore_name(skill.appstore) store = self.get_appstore(skill.appstore) store.authenticate(bootstrap=False) except: pass skill.install() if store: store.clear_authentication() def __iter__(self): for store in self.appstores: for skill in store: yield skill
def handle_homescreen(self, message): self.gui.clear() self.gui["videosHomeModel"] = self.filter_videos(self.videos) self.gui["historyModel"] = JsonStorageXDG("{msg_base}.history".format(msg_base=self.message_namespace)) \ .get("model", []) self.gui.show_page("Homescreen.qml", override_idle=True)
'module': 'google' }, 'tts': { 'module': 'responsive_voice' } } def _merge_defaults(base, default=None): """ Recursively merging configuration dictionaries. Args: base: Target for merge default: Dictionary to merge into base if key not present """ default = default or DEFAULT_CONFIGURATION for k, dv in default.items(): bv = base.get(k) if isinstance(dv, dict) and isinstance(bv, dict): _merge_defaults(bv, dv) elif k not in base: base[k] = dv return base CONFIGURATION = JsonStorageXDG("HivemindPtT") CONFIGURATION = _merge_defaults(CONFIGURATION) if not exists(CONFIGURATION.path): CONFIGURATION.store()
"latitude": 38.971669, "longitude": -95.23525 }, "timezone": { "code": "America/Chicago", "name": "Central Standard Time", "dstOffset": 3600000, "offset": -21600000 } }, "geolocate": False, "override_location": False, "api_version": "v1", "data_path": "~", "record_utterances": False, "record_wakewords": False, "wolfram_key": "Y7R353-9HQAAL8KKA", "owm_key": "28fed22898afd4717ce5a1535da1f78c", "email": { "username": None, "password": None } } CONFIGURATION = JsonStorageXDG("ovos_backend", xdg.BaseDirectory.xdg_config_home) if not exists(CONFIGURATION.path): CONFIGURATION.merge(DEFAULT_CONFIG, skip_empty=False) CONFIGURATION.store()
'play_mp3_cmd': "mpg123 %1", 'play_ogg_cmd': "ogg123 -q %1", 'play_fallback_cmd': "play %1" }, 'log_blacklist': [] } def _merge_defaults(base, default=None): """ Recursively merging configuration dictionaries. Args: base: Target for merge default: Dictionary to merge into base if key not present """ default = default or DEFAULT_CONFIGURATION for k, dv in default.items(): bv = base.get(k) if isinstance(dv, dict) and isinstance(bv, dict): _merge_defaults(bv, dv) elif k not in base: base[k] = dv return base CONFIGURATION = JsonStorageXDG("HivemindVoiceSatellite") CONFIGURATION = _merge_defaults(CONFIGURATION) if not exists(CONFIGURATION.path): CONFIGURATION.store()
from json_database import JsonStorageXDG from json_database.exceptions import DatabaseNotCommitted from os.path import exists save_path = "my_dict" my_config = JsonStorageXDG(save_path) print(my_config.path) my_config["lang"] = "pt" my_config["secondary_lang"] = "en" my_config["email"] = "*****@*****.**" # my_config is a python dict assert isinstance(my_config, dict) # save to file my_config.store() print(my_config) my_config["lang"] = "pt-pt" print(my_config) # revert to previous saved file my_config.reload() print(my_config) assert my_config["lang"] == "pt" # clear all fields my_config.clear() assert my_config == {} # delete stored file