def install(self, param, author=None, constraints=None, origin=''):
     """Install by url or name"""
     if isinstance(param, SkillEntry):
         skill = param
     else:
         skill = self.find_skill(param, author)
     skill_state = initialize_skill_state(skill.name, origin, skill.is_beta,
                                          skill.skill_gid)
     try:
         skill.install(constraints)
     except AlreadyInstalled:
         log_msg = 'Skill {} already installed - ignoring install request'
         LOG.info(log_msg.format(skill.name))
         skill_state = None
         raise
     except MsmException as e:
         skill_state.update(installation='failed',
                            status='error',
                            failure_message=str(e))
         raise
     else:
         skill_state.update(installed=time.time(),
                            installation='installed',
                            status='active',
                            beta=skill.is_beta)
     finally:
         # Store the entry in the list
         if skill_state is not None:
             self.device_skill_state['skills'].append(skill_state)
             self._invalidate_skills_cache()
 def _add_skills_to_state(self):
     """Add local skill to state if it is not already there."""
     skill_names = [s['name'] for s in self._device_skill_state['skills']]
     for skill in self.local_skills.values():
         if skill.name not in skill_names:
             origin = self._determine_skill_origin(skill)
             skill_state = initialize_skill_state(skill.name, origin, False,
                                                  skill.skill_gid)
             self._device_skill_state['skills'].append(skill_state)
 def _upgrade_to_v1(self):
     """Upgrade the device skills state to version one."""
     self._device_skill_state.update(blacklist=[], version=1, skills=[])
     for skill in self.local_skills.values():
         skill_data = self._device_skill_state.get(skill.name, {})
         try:
             origin = skill_data['origin']
         except KeyError:
             origin = self._determine_skill_origin(skill)
         beta = skill_data.get('beta', False)
         skill_state = initialize_skill_state(skill.name, origin, beta,
                                              skill.skill_gid)
         skill_state['installed'] = skill_data.get('installed', 0)
         if isinstance(skill_state['installed'], bool):
             skill_state['installed'] = 0
         skill_state['updated'] = skill_data.get('updated', 0)
         self._device_skill_state['skills'].append(skill_state)
     self._device_skill_state.update(upgraded=True)