def main(): parser = ArgumentParser() parser.add_argument('-l', '--lang', default='en-us') parser.add_argument('-u', '--repo-url', help='Url of GitHub repo to upload skills to') parser.add_argument('-b', '--repo-branch', help='Branch of skills repo to upload to') parser.add_argument('-s', '--skills-dir', help='Directory to look for skills in') parser.add_argument('-c', '--repo-cache', help='Location to store local skills repo clone') parser.add_argument('-t', '--use-token', action='store_true') subparsers = parser.add_subparsers(dest='action') subparsers.required = True for action, cls in console_actions.items(): cls.register(subparsers.add_parser(action)) args = parser.parse_args(sys.argv[1:]) context = GlobalContext() context.lang = args.lang context.msm = MycroftSkillsManager( skills_dir=args.skills_dir, repo=SkillRepo(url=args.repo_url, branch=args.repo_branch) ) context.use_token = args.use_token context.branch = context.msm.repo.branch try: return console_actions[args.action](args).perform() except MskException as e: print('{}: {}'.format(e.__class__.__name__, str(e))) except (KeyboardInterrupt, EOFError): pass
def create_msm(msm_config: MsmConfig) -> MycroftSkillsManager: """Returns an instantiated MSM object. This function is cached because it can take as long as 15 seconds to instantiate MSM. Caching the instance improves performance significantly, especially during the boot sequence when this function is called multiple times. """ if msm_config.repo_url != "https://github.com/MycroftAI/mycroft-skills": LOG.warning("You have enabled a third-party skill store.\n" "Unable to guarantee the safety of skills from " "sources other than the Mycroft Marketplace.\n" "Proceed with caution.") msm_lock = _init_msm_lock() LOG.info('Acquiring lock to instantiate MSM') with msm_lock: if not path.exists(msm_config.skills_dir): makedirs(msm_config.skills_dir) msm_skill_repo = SkillRepo(msm_config.repo_cache, msm_config.repo_url, msm_config.repo_branch) msm_instance = MycroftSkillsManager(platform=msm_config.platform, skills_dir=msm_config.skills_dir, repo=msm_skill_repo, versioned=msm_config.versioned) LOG.info('Releasing MSM instantiation lock.') return msm_instance
def create_msm(msm_config: MsmConfig) -> MycroftSkillsManager: """Returns an instantiated MSM object. This function is cached because it can take as long as 15 seconds to instantiate MSM. Caching the instance improves performance significantly, especially during the boot sequence when this function is called multiple times. """ msm_lock = _init_msm_lock() LOG.info('Acquiring lock to instantiate MSM') with msm_lock: if not path.exists(msm_config.skills_dir): makedirs(msm_config.skills_dir) msm_skill_repo = SkillRepo( msm_config.repo_cache, msm_config.repo_url, msm_config.repo_branch ) msm_instance = MycroftSkillsManager( platform=msm_config.platform, skills_dir=msm_config.skills_dir, repo=msm_skill_repo, versioned=msm_config.versioned ) LOG.info('Releasing MSM instantiation lock.') return msm_instance
def before_all(context): log = create_voight_kampff_logger() bus = InterceptAllBusClient() bus_connected = Event() bus.once('open', bus_connected.set) create_daemon(bus.run_forever) context.msm = MycroftSkillsManager() # Wait for connection log.info('Waiting for messagebus connection...') bus_connected.wait() log.info('Waiting for skills to be loaded...') start = monotonic() while True: response = bus.wait_for_response(Message('mycroft.skills.all_loaded')) if response and response.data['status']: break elif monotonic() - start >= 2 * 60: raise Exception('Timeout waiting for skills to become ready.') else: sleep(1) context.bus = bus context.matched_message = None context.log = log
def create_msm(config): """ Create msm object from config. """ global mycroft_msm_lock if mycroft_msm_lock is None: try: mycroft_msm_lock = ComboLock('/tmp/mycroft-msm.lck') LOG.debug('mycroft-msm combo lock created') except Exception as e: LOG.error('Failed to create msm lock ({})'.format(repr(e))) msm_config = config['skills']['msm'] repo_config = msm_config['repo'] data_dir = expanduser(config['data_dir']) skills_dir = join(data_dir, msm_config['directory']) repo_cache = join(data_dir, repo_config['cache']) platform = config['enclosure'].get('platform', 'default') with mycroft_msm_lock: # Try to create the skills directory if it doesn't exist if not exists(skills_dir): os.makedirs(skills_dir) return MycroftSkillsManager(platform=platform, skills_dir=skills_dir, repo=SkillRepo(repo_cache, repo_config['url'], repo_config['branch']), versioned=msm_config['versioned'])
def main(): args = create_parser(usage).parse_args() github = load_github() summaries = {} repo = SkillRepo(path=join(gettempdir(), 'mycroft-skills-repo'), branch=use_branch) print("Working on repository: ", repo.url) print(" branch: ", repo.branch) for skill_entry in MycroftSkillsManager(repo=repo).list(): if not skill_entry.url: continue print('Generating {}...'.format(skill_entry.name)) try: summary = generate_summary(github, skill_entry) except GithubException as e: print('Failed to generate summary:', repr(e)) continue summaries[skill_entry.name] = summary if args.output_file: with open(args.output_file, 'w') as f: json.dump(summaries, f) else: print(json.dumps(summaries, indent=4)) if args.upload: upload_summaries(github, summaries, use_branch)
def setup(self): self.root = root = dirname(abspath(__file__)) self.msm = MycroftSkillsManager( platform='default', skills_dir=join(root, 'test-skills'), repo=SkillRepo( join(root, 'repo-instance'), branch='test-repo', url='https://github.com/mycroftai/mycroft-skills-manager'), versioned=True)
def create_msm(): config = Configuration.get() msm_config = config['skills']['msm'] repo_config = msm_config['repo'] platform = config['enclosure'].get('platform', 'default') return MycroftSkillsManager(platform=platform, skills_dir=msm_config['directory'], repo=SkillRepo(repo_config['cache'], repo_config['url'], repo_config['branch']), versioned=msm_config['versioned'])
def __init__(self, args): msm = MycroftSkillsManager() skill_matches = [ skill for skill in msm.list() if skill.is_local and samefile(skill.path, args.skill_folder) ] if not skill_matches: raise NotUploaded( 'Skill at folder not uploaded to store: {}'.format( args.skill_folder)) self.skill = SkillData(skill_matches[0])
def create_skills_manager(platform, skills_dir, url, branch): """Create mycroft skills manager for the given url / branch. Args: platform (str): platform to use skills_dir (str): skill directory to use url (str): skills repo url branch (str): skills repo branch Returns: MycroftSkillsManager """ repo = SkillRepo(url=url, branch=branch) return MycroftSkillsManager(platform, skills_dir, repo)
def setUp(self): temp_dir = tempfile.mkdtemp() self.temp_dir = Path(temp_dir) self.skills_json_path = self.temp_dir.joinpath('skills.json') self.skills_dir = self.temp_dir.joinpath('skills') self._build_fake_skills() self._mock_skills_json_path() self._mock_skill_entry() self._mock_skill_repo() copyfile('skills_test.json', str(self.skills_json_path)) self.msm = MycroftSkillsManager(platform='default', skills_dir=str( self.temp_dir.joinpath('skills')), repo=self.skill_repo_mock, versioned=True)
def create_msm(): config = Configuration.get() msm_config = config['skills']['msm'] repo_config = msm_config['repo'] data_dir = expanduser(config['data_dir']) skills_dir = join(data_dir, msm_config['directory']) # Try to create the skills directory if it doesn't exist if not exists(skills_dir): os.makedirs(skills_dir) repo_cache = join(data_dir, repo_config['cache']) platform = config['enclosure'].get('platform', 'default') return MycroftSkillsManager(platform=platform, skills_dir=skills_dir, repo=SkillRepo(repo_cache, repo_config['url'], repo_config['branch']), versioned=msm_config['versioned'])
def main(): parser = ArgumentParser() parser.add_argument('-l', '--lang', default='en-us') parser.add_argument('-u', '--repo-url', help='Url of GitHub repo to upload skills to') parser.add_argument('-b', '--repo-branch', help='Branch of skills repo to upload to') parser.add_argument('-s', '--skills-dir', help='Directory to look for skills in') parser.add_argument('-c', '--repo-cache', help='Location to store local skills repo clone') subparsers = parser.add_subparsers(dest='action') subparsers.required = True action_to_cls = {} for cls, names in action_names.items(): cls.register(subparsers.add_parser(names[0], aliases=names[1:])) action_to_cls.update({name: cls for name in names}) args = parser.parse_args(sys.argv[1:]) ensure_git_user() context = GlobalContext() context.lang = args.lang context.msm = MycroftSkillsManager(skills_dir=args.skills_dir, repo=SkillRepo(url=args.repo_url, branch=args.repo_branch, path=args.repo_cache)) context.branch = context.msm.repo.branch try: return action_to_cls[args.action](args).perform() except MskException as e: print('{}: {}'.format(e.__class__.__name__, str(e))) except (KeyboardInterrupt, EOFError): pass
def before_all(context): log = create_voight_kampff_logger() bus = InterceptAllBusClient() bus_connected = Event() bus.once('open', bus_connected.set) create_daemon(bus.run_forever) context.msm = MycroftSkillsManager() # Wait for connection log.info('Waiting for messagebus connection...') bus_connected.wait() log.info('Waiting for skills to be loaded...') start = monotonic() while True: response = bus.wait_for_response(Message('mycroft.skills.all_loaded')) if response and response.data['status']: break elif monotonic() - start >= 2 * 60: raise Exception('Timeout waiting for skills to become ready.') else: sleep(1) # Temporary bugfix - First test to run sometimes fails # Sleeping to see if something isn't finished setting up when tests start # More info in Jira Ticket MYC-370 # TODO - remove and fix properly dependant on if failures continue sleep(10) context.bus = bus context.matched_message = None context.log = log context.original_config = {} context.config = Configuration.get() Configuration.set_config_update_handlers(bus)
from mycroft.util.audio_utils import play_wav, play_mp3 from os.path import join import time from os.path import dirname, exists, expanduser from os import makedirs, access, W_OK import json try: import cv2 from imutils.video import VideoStream #from shared_camera import Camera import yagmail except ImportError: # re-install yourself from msm import MycroftSkillsManager msm = MycroftSkillsManager() msm.install_by_url("https://github.com/emphasize/skill-camera", True) # trigger reload msm.reload_skill("skill-camera") __author__ = 'jarbas' class WebcamSkill(MycroftSkill): def __init__(self): self.create_settings_meta() super(WebcamSkill, self).__init__() platform = self.config_core.get("enclosure", {}) \ .get("platform", "unknown") self.use_pi = platform.lower() in [ "mycroft_mark_2", "mycroft_mark_1", "picroft", "unknown",
def handle_search_skills_intent(self, message): # A decision was made other than Cancel m = MycroftSkillsManager() installed_skills = [s for s in m.list() if s.is_local] LOGGER.info('Found the following Skills: '+str(installed_skills))