'manage jobs'

def do_jobs(self, arg):

    arg_parser = PupyArgumentParser(prog='jobs', description='list    or    kill    jobs')
    arg_parser.add_argument('-k', '--kill', metavar='<job_id>', help='print    the    job    current    output    before    killing    it')
    arg_parser.add_argument('-l', '--list', action='store_true', help='list    jobs')
    arg_parser.add_argument('-p', '--print-output', metavar='<job_id>', help='print    a    job    output')
    try:
        modargs = arg_parser.parse_args(shlex.split(arg))
    except PupyModuleExit:
        return
    try:
        if modargs.kill:
            j = self.pupsrv.get_job(modargs.kill)
            self.display(j.result_summary())
            j.stop()
            del j
            self.display_success('job    killed')
        elif modargs.print_output:
            j = self.pupsrv.get_job(modargs.print_output)
            self.display(j.result_summary())
        elif modargs.list:
            if (len(self.pupsrv.jobs) > 0):
                dictable = []
                for (k, v) in self.pupsrv.jobs.iteritems():
                    dic = {'id': k, 'job': str(v)}
                    status = 'running'
                    if v.is_finished():
                        status = 'finished'
                    dic['status'] = status
                    dic['clients_nb'] = str(v.get_clients_nb())
                    dictable.append(dic)
                self.display(PupyCmd.table_format(dictable, wl=['id', 'job', 'clients_nb', 'status']))
            else:
                self.display_error('No    jobs    are    currently    running    !')
        else:
            try:
                arg_parser.parse_args(['-h'])
            except PupyModuleExit:
                return
    except PupyModuleError as e:
        self.display_error(e)
    except Exception as e:
        self.display_error(traceback.format_exc())
