Exemple #1
0
    def list(self):
        """
        Load a list of SkillEntry objects from both local and
        remote skills

        It is necessary to load both local and remote skills at
        the same time to correctly associate local skills with the name
        in the repo and remote skills with any custom path that they
        have been downloaded to
        """
        try:
            self.repo.update()
        except GitException as e:
            if not isdir(self.repo.path):
                raise
            LOG.warning('Failed to update repo: {}'.format(repr(e)))
        remote_skill_list = (
            SkillEntry(
                name, SkillEntry.create_path(self.skills_dir, url, name),
                url, sha if self.versioned else '', msm=self
            )
            for name, path, url, sha in self.repo.get_skill_data()
        )
        remote_skills = {
            skill.id: skill for skill in remote_skill_list
        }
        all_skills = []
        for skill_file in glob(join(self.skills_dir, '*', '__init__.py')):
            skill = SkillEntry.from_folder(dirname(skill_file), msm=self)
            if skill.id in remote_skills:
                skill.attach(remote_skills.pop(skill.id))
            all_skills.append(skill)
        all_skills += list(remote_skills.values())
        return all_skills
    def _merge_remote_with_local(self, remote_skills):
        """Merge the skills found in the repo with those installed locally."""
        all_skills = []
        for skill_file in glob(path.join(self.skills_dir, '*', '__init__.py')):
            skill = SkillEntry.from_folder(path.dirname(skill_file), msm=self,
                                           use_cache=False)
            if skill.id in remote_skills:
                skill.attach(remote_skills.pop(skill.id))
            all_skills.append(skill)
        all_skills.extend(remote_skills.values())

        return all_skills
    def _merge_remote_with_local(self, remote_skills):
        """Merge the skills found in the repo with those installed locally."""
        all_skills = []
        skill_dirs = []
        for directory in BaseDirectory.load_data_paths('mycroft/skills'):
            # Make sure we don't add the XDG save data path twice
            if directory != self.skills_dir:
                skill_dirs.append(directory)
        skill_dirs.append(self.skills_dir)

        for skills_dir in skill_dirs:
            for skill_file in glob(path.join(skills_dir, '*', '__init__.py')):
                skill = SkillEntry.from_folder(path.dirname(skill_file),
                                               msm=self,
                                               use_cache=False)
                if skill.id in remote_skills:
                    skill.attach(remote_skills.pop(skill.id))
                all_skills.append(skill)
        all_skills.extend(remote_skills.values())

        return all_skills
    def _merge_remote_with_local(self, remote_skills):
        """Merge the skills found in the repo with those installed locally."""
        all_skills = []

        # First move locally installed skills from old to new location
        # TODO: get rid of this at some point
        if self.old_skills_dir:
            for old_skill_dir in glob(path.join(self.old_skills_dir, '*/')):
                skill_name = old_skill_dir.rstrip('/').rsplit('/', 1)[1]
                new_skill_path = self.skills_dir + "/" + skill_name
                if not path.isdir(new_skill_path):
                    shutil.move(old_skill_dir,
                                self.skills_dir + "/" + skill_name)

        for skill_file in glob(path.join(self.skills_dir, '*', '__init__.py')):
            skill = SkillEntry.from_folder(path.dirname(skill_file),
                                           msm=self,
                                           use_cache=False)
            if skill.id in remote_skills:
                skill.attach(remote_skills.pop(skill.id))
            all_skills.append(skill)
        all_skills.extend(remote_skills.values())

        return all_skills