def setup(self):
     root = dirname(abspath(__file__))
     chdir(root)
     self.repo = SkillRepo(
         join(root, 'repo-instance'),
         'https://github.com/mycroftai/mycroft-skills-manager', 'test-repo')
     self.repo.update()
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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'])
Пример #6
0
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)
Пример #7
0
 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'])
Пример #8
0
 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'])
     repo_cache = join(data_dir, repo_config['cache'])
     platform = config['enclosure'].get('platform', 'default')
     return OwOSkillsManager(platform=platform,
                             skills_dir=skills_dir,
                             repo=SkillRepo(repo_cache, repo_config['url'],
                                            repo_config['branch']),
                             versioned=msm_config['versioned'])
Пример #9
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)
Пример #10
0
    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'])
Пример #11
0
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
class TestSkillRepo(object):
    def setup(self):
        root = dirname(abspath(__file__))
        chdir(root)
        self.repo = SkillRepo(
            join(root, 'repo-instance'),
            'https://github.com/mycroftai/mycroft-skills-manager', 'test-repo')
        self.repo.update()

    def test_read_file(self):
        assert self.repo.read_file('test_file.txt') == 'test'

    def test_get_skill_data(self):
        """ generates tuples of name, path, url """
        assert set(self.repo.get_skill_data()) == {
            ('skill-a', 'skill-a',
             'https://github.com/MycroftAI/skill-hello-world',
             'a45e9b476884cfa463a50158d1131e02da072634'),
            ('skill-b', 'skill-b', 'https://github.com/MycroftAI/skill-ip.git',
             '880c2f90310844f62728e762f0a2fad328c0a008'),
            ('skill-ce', 'skill-ce',
             'https://github.com/MycroftAI/skill-alarm.git',
             '16e717dfacef8c10390c6f4184d4c07877950894'),
            ('skill-cd', 'skill-cd',
             'https://github.com/MycroftAI/skill-joke.git',
             '4ac8c0da55c2f38f9bcf04c2b369602851ccd38f')
        }

    def test_get_shas(self):
        assert set(self.repo.get_shas()) == {
            ('skill-a', 'a45e9b476884cfa463a50158d1131e02da072634'),
            ('skill-b', '880c2f90310844f62728e762f0a2fad328c0a008'),
            ('skill-ce', '16e717dfacef8c10390c6f4184d4c07877950894'),
            ('skill-cd', '4ac8c0da55c2f38f9bcf04c2b369602851ccd38f')
        }

    def test_get_default_skill_names(self):
        assert dict(self.repo.get_default_skill_names()) == {
            'default': ['skill-a'],
            'platform-1': ['skill-b']
        }

    def teardown(self):
        rmtree('repo-instance')