def kill(args):
    """
    %prog kill [options] JOBNAMEPAT/JOBIDs

    Kill jobs based on JOBNAME pattern matching (case-sensitive)
    or list of JOBIDs (comma separated)

    Examples:
    %prog kill "pyth*"                 # Use regex
    %prog kill 160253,160245,160252    # Use list of job ids
    %prog kill all                     # Everything
    """
    import shlex
    from jcvi.apps.base import sh, getusername
    from subprocess import check_output, CalledProcessError
    import xml.etree.ElementTree as ET

    valid_methods = ("pattern", "jobid")
    p = OptionParser(kill.__doc__)
    p.add_option("--method", choices=valid_methods,
                 help="Identify jobs based on [default: guess]")
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    username = getusername()
    tag, = args
    tag = tag.strip()

    if tag == "all":
        sh("qdel -u {0}".format(username))
        return

    valid_jobids = set()
    method = opts.method or guess_method(tag)
    if method == "jobid":
        jobids = tag.split(",")
        valid_jobids |= set(jobids)
    elif method == "pattern":
        qsxmlcmd = 'qstat -u "{0}" -j "{1}" -nenv -njd -xml'.\
                                format(username, tag)
        try:
            qsxml = check_output(shlex.split(qsxmlcmd)).strip()
        except CalledProcessError as e:
            qsxml = None
            logging.debug('No jobs matching the pattern "{0}"'.format(tag))

        if qsxml is not None:
            for job in ET.fromstring(qsxml).findall("djob_info"):
                for elem in job.findall("element"):
                    jobid = elem.find("JB_job_number").text
                    valid_jobids.add(jobid)

    if valid_jobids:
        sh("qdel {0}".format(",".join(valid_jobids)))
def kill ( args ) : import shlex from jcvi . apps . base import sh , getusername from subprocess import check_output , CalledProcessError import xml . etree . ElementTree as ET valid_methods = ( "pattern" , "jobid" ) p = OptionParser ( kill . __doc__ ) p . add_option ( "--method" , choices = valid_methods , help = "Identify jobs based on [default: guess]" ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) username = getusername ( ) tag , = args tag = tag . strip ( ) if tag == "all" : sh ( "qdel -u {0}" . format ( username ) ) return valid_jobids = set ( ) method = opts . method or guess_method ( tag ) if method == "jobid" : jobids = tag . split ( "," ) valid_jobids |= set ( jobids ) elif method == "pattern" : qsxmlcmd = 'qstat -u "{0}" -j "{1}" -nenv -njd -xml' . format ( username , tag ) try : qsxml = check_output ( shlex . split ( qsxmlcmd ) ) . strip ( ) except CalledProcessError as e : qsxml = None logging . debug ( 'No jobs matching the pattern "{0}"' . format ( tag ) ) if qsxml is not None : for job in ET . fromstring ( qsxml ) . findall ( "djob_info" ) : for elem in job . findall ( "element" ) : jobid = elem . find ( "JB_job_number" ) . text valid_jobids . add ( jobid ) if valid_jobids : sh ( "qdel {0}" . format ( "," . join ( valid_jobids ) ) )
%prog kill [options] JOBNAMEPAT/JOBIDs

    Kill jobs based on JOBNAME pattern matching (case-sensitive)
    or list of JOBIDs (comma separated)

    Examples:
    %prog kill "pyth*"                 # Use regex
    %prog kill 160253,160245,160252    # Use list of job ids
    %prog kill all                     # Everything