Exemple #1
0
 def run(self):
     if os.path.isfile(self.kwargs['package']):
         old_level = logger.getEffectiveLevel()
         logger.setLevel(logging.ERROR)
         try:
             d = dapi.Dap(self.kwargs['package'])
             if not dapi.DapChecker.check(d):
                 raise exceptions.ExecutionException(
                     'This DAP is not valid, info can\'t be displayed.')
         finally:
             logger.setLevel(old_level)
         logger.infolines(
             dapicli.format_local_dap(d,
                                      full=self.kwargs.get('full', False)))
     elif self.kwargs.get('installed'):
         try:
             logger.infolines(
                 dapicli.format_installed_dap(self.kwargs['package'],
                                              full=self.kwargs.get(
                                                  'full', False)))
         except exceptions.DapiError as e:
             logger.error(utils.exc_as_decoded_string(e))
             raise exceptions.ExecutionException(
                 utils.exc_as_decoded_string(e))
     else:
         try:
             logger.infolines(
                 dapicli.format_dap_from_dapi(self.kwargs['package'],
                                              full=self.kwargs.get(
                                                  'full', False)))
         except exceptions.DapiError as e:
             logger.error(utils.exc_as_decoded_string(e))
             raise exceptions.ExecutionException(
                 utils.exc_as_decoded_string(e))
Exemple #2
0
 def run(self):
     pkgs = exs = []
     try:
         pkgs = self.kwargs['package']
     except KeyError:
         pkgs = dapicli.get_installed_daps()
         if pkgs:
             logger.info('Updating all DAP packages ...')
         else:
             logger.info(
                 'No installed DAP packages found, nothing to update.')
     for pkg in pkgs:
         logger.info('Updating DAP {pkg} ...'.format(pkg=pkg))
         try:
             updated = dapicli.install_dap(
                 pkg,
                 update=True,
                 update_allpaths=self.kwargs['allpaths'],
                 force=self.kwargs['force'])
             if updated:
                 logger.info(
                     'DAP {pkg} successfully updated.'.format(pkg=pkg))
             else:
                 logger.info(
                     'DAP {pkg} is already up to date.'.format(pkg=pkg))
         except exceptions.DapiError as e:
             exs.append(utils.exc_as_decoded_string(e))
             logger.error(utils.exc_as_decoded_string(e))
     if exs:
         raise exceptions.ExecutionException('; '.join(exs))
Exemple #3
0
 def run(self):
     """Runs all errors, dependencies and run methods of all *Assistant objects in self.path.
     Raises:
         devassistant.exceptions.ExecutionException with a cause if something goes wrong
     """
     self._logging()
     errors = self._run_path_errors()
     if errors:
         raise exceptions.ExecutionException(errors)
     self._run_path_dependencies()
     self._run_path_run()
Exemple #4
0
    def construct_arg(cls, name, params):
        """Construct an argument from name, and params (dict loaded from assistant/snippet).
        """
        use_snippet = params.pop('use', None)
        if use_snippet:
            # if snippet is used, take this parameter from snippet and update
            # it with current params, if any
            try:
                problem = None
                snippet = yaml_snippet_loader.YamlSnippetLoader.get_snippet_by_name(
                    use_snippet)
                # this works much like snippet.args.pop(arg_name).update(arg_params),
                # but unlike it, this actually returns the updated dict
                params = dict(snippet.args.pop(name), **params)
                # if there is SnippetNotFoundException, just let it be raised
            except KeyError:  # snippet doesn't have the requested argument
                problem = 'Couldn\'t find arg {arg} in snippet {snip}.'.\
                    format(arg=name, snip=snippet.name)
                raise exceptions.ExecutionException(problem)

        if 'flags' not in params:
            msg = 'Couldn\'t find "flags" in arg {arg}'.format(arg=name)
            raise exceptions.ExecutionException(msg)
        return cls(name, *params.pop('flags'), **params)
Exemple #5
0
    def run(self):
        newargs = {}
        newargs['q'] = ' '.join(self.kwargs['query'])
        newargs['noassistants'] = self.kwargs['noassistants']
        newargs['unstable'] = self.kwargs['unstable']
        newargs['notactive'] = self.kwargs['deactivated']
        newargs['minimal_rank'] = self.kwargs['minrank']
        newargs['minimal_rank_count'] = self.kwargs['mincount']
        if not self.kwargs['allplatforms']:
            newargs['platform'] = utils.get_distro_name()

        try:
            logger.infolines(dapicli.format_search(**newargs))
        except exceptions.DapiError as e:
            logger.error(utils.exc_as_decoded_string(e))
            raise exceptions.ExecutionException(utils.exc_as_decoded_string(e))
Exemple #6
0
 def run(self):
     error = False
     old_level = logger.getEffectiveLevel()
     for pkg in self.kwargs['package']:
         try:
             if self.kwargs['nowarnings']:
                 logger.setLevel(logging.ERROR)
             d = dapi.Dap(pkg)
             if not dapi.DapChecker.check(
                     d,
                     network=self.kwargs['network'],
                     yamls=not self.kwargs['noyamlcheck']):
                 error = True
         except (exceptions.DapFileError, exceptions.DapMetaError) as e:
             logger.error(utils.exc_as_decoded_string(e))
             error = True
     logger.setLevel(old_level)
     if error:
         raise exceptions.ExecutionException(
             'One or more packages are not sane')
Exemple #7
0
 def run(self):
     exs = []
     for pkg in self.kwargs['package']:
         logger.info('Installing DAP {pkg} ...'.format(pkg=pkg))
         if os.path.isfile(pkg):
             method = dapicli.install_dap_from_path
         else:
             method = dapicli.install_dap
         try:
             pkgs = method(pkg,
                           force=self.kwargs['force'],
                           nodeps=self.kwargs['nodeps'],
                           reinstall=self.kwargs['reinstall'],
                           __ui__=self.kwargs['__ui__'])
             logger.info('Successfully installed DAPs {pkgs}'.format(
                 pkgs=' '.join(pkgs)))
         except exceptions.DapiError as e:
             exs.append(utils.exc_as_decoded_string(e))
             logger.error(utils.exc_as_decoded_string(e))
     if exs:
         raise exceptions.ExecutionException('; '.join(exs))
Exemple #8
0
    def add_argument_to(self, parser):
        """Used by cli to add this as an argument to argparse parser.

        Args:
            parser: parser to add this argument to
        """
        from devassistant.cli.devassistant_argparse import DefaultIffUsedActionFactory
        if isinstance(self.kwargs.get('action', ''), list):
            # see documentation of DefaultIffUsedActionFactory to see why this is necessary
            if self.kwargs['action'][0] == 'default_iff_used':
                self.kwargs[
                    'action'] = DefaultIffUsedActionFactory.generate_action(
                        self.kwargs['action'][1])
        # In cli 'preserved' is not supported.
        # It needs to be removed because it is unknown for argparse.
        self.kwargs.pop('preserved', None)
        try:
            parser.add_argument(*self.flags, **self.kwargs)
        except Exception as ex:
            problem = "Error while adding argument '{name}': {error}".\
                format(name=self.name, error=repr(ex))
            raise exceptions.ExecutionException(problem)
Exemple #9
0
 def run(self):
     exs = []
     uninstalled = []
     for pkg in self.kwargs['package']:
         if pkg in uninstalled:
             logger.info('DAP {pkg} already uninstalled'.format(pkg=pkg))
             continue
         logger.info('Uninstalling DAP {pkg} ...'.format(pkg=pkg))
         try:
             done = dapicli.uninstall_dap(pkg,
                                          confirm=self.kwargs['force'],
                                          allpaths=self.kwargs['allpaths'],
                                          __ui__=self.kwargs['__ui__'])
             if done:
                 logger.info('DAPs {pkgs} successfully uninstalled'.format(
                     pkgs=' '.join(done)))
                 uninstalled += done
         except exceptions.DapiError as e:
             exs.append(utils.exc_as_decoded_string(e))
             logger.error(utils.exc_as_decoded_string(e))
     if exs:
         raise exceptions.ExecutionException('; '.join(exs))
Exemple #10
0
 def run(self):
     dap = self.kwargs['dap']
     doc = self.kwargs.get('doc', None)
     docdir = utils.find_file_in_load_dirs(os.path.join('doc', dap))
     all_docs = []
     if docdir is not None:
         all_docs = self._get_doc_files(docdir)
     if not all_docs:
         logger.info('DAP {0} has no documentation.'.format(dap))
     elif doc is not None:
         doc_fullpath = os.path.join(docdir, doc)
         if doc_fullpath in all_docs:
             self._show_doc(doc_fullpath)
         else:
             msg = 'DAP {0} has no document "{1}".'.format(dap, doc)
             logger.error(msg)
             raise exceptions.ExecutionException(msg)
     else:
         logger.info('DAP {0} has these docs:'.format(dap))
         for d in all_docs:
             logger.info(d[len(docdir):].strip(os.path.sep))
         logger.info(
             'Use "da doc {0} <DOC>" to see a specific document'.format(
                 dap))