Exemple #1
0
    def log(self, args):
        """
        Get job log of a complete finished job (get *log* element of the job output).
        Use -v to get complete job info.

        :param args: parser arguments, in particualr the job *id*.
        :return: None
            see: :func:`pdm.userservicedesk.TransferClient.TransferClient.output`
        """
        token = UserCommand._get_token(args.token)
        if token:
            job_id = int(args.job)
            client = TransferClientFacade(token)
            status = self._status(job_id, client, block=True)
            try:
                for element in client.output(job_id,
                                             element_id=args.element,
                                             attempt=args.attempt):
                    for attempt in element:
                        log_listing = attempt.get('log')
                        if args.verbosity == logging.DEBUG:
                            pprint(attempt)
                        else:
                            print log_listing
            except RESTException as rexc:
                print str(rexc)
Exemple #2
0
    def list(self, args):  # pylint: disable=no-self-use
        """
        List files at remote site.

        :param args: parser arguments.
        :return: None
        """

        nap = 0.2
        count = 1
        max_iter = max(1, int(args.wait / nap))
        #
        token = UserCommand._get_token(args.token)
        if token and self._session_ok(args.site, token):
            client = TransferClientFacade(token)
            # remove None values, position args, func and token from the kwargs:
            accepted_args = {
                key: value
                for (key, value) in vars(args).iteritems()
                if value is not None and key not in ('func', 'site', 'token',
                                                     'config', 'verbosity',
                                                     'wait')
            }
            resp = client.list(args.site,
                               **accepted_args)  # max_tries, priority, depth)
            # resp and status both carry job id:
            if resp:
                status = client.status(resp['id'])
                while status['status'] not in ('DONE', 'FAILED'):
                    sleep(nap)  # seconds
                    status = client.status(resp['id'])
                    count += 1
                    if count >= max_iter:
                        break

                if status['status'] == 'DONE':
                    listing_output = client.output(
                        resp['id'], 0, -1)[0][0]  # listing is 0, last attempt
                    listing_d_value = listing_output['listing']
                    root, listing = listing_d_value.items()[0]  # top root
                    self._print_formatted_listing(root, listing_d_value)
                elif resp['status'] == 'FAILED':
                    print " Failed to obtain a listing for job %d " % (
                        resp['id'], )
                else:
                    print "Timeout. Last status is %s for job id %d" % \
                          (status['status'], resp['id'])
            elif isinstance(resp, list) and not resp:
                print "No such site: %s " % (args.site, )