def ejobs(args, bjobsargs): """Wrapper script with bjobs functionality.""" # handle arguments if args.pending: bjobsargs = ["-p"] + bjobsargs args.groupby = "pend_reason" for shortcutname, shortcutargs in ejobsshortcuts.items(): if getattr(args, shortcutname): bjobsargs = shortcutargs + bjobsargs for l in list("rsda"): if args.__dict__[l]: bjobsargs = ["-" + l] + bjobsargs if args.u: unames = map(lookupalias, args.u.split()) bjobsargs = ["-u", " ".join(unames)] + bjobsargs if args.jid: args.output = ["id"] args.fast = True args.noheader = True if args.output: args.output = sum([fields.split() for fields in args.output], []) if len(args.output) == 1: args.noheader = True # read jobs = readjobs(bjobsargs, fast=args.fast) if not jobs: return # sort jobs.sort(key=lambda j: j["submit_time"]) jobs.sort(key=lambda j: j["priority"], reverse=True) # can be None jobs.sort(key=lambda j: -j["run_time"]) jobs.sort(key=lambda j: -statorder[j["stat"]]) if args.sort: try: jobs.sort(key=lambda j: j[args.sort]) except: print("Unknown sorting key \"%s\"!" % args.sort, file=sys.stderr) # no grouping if not args.groupby or args.groupby not in jobs[0]: if args.sum: jobs = [sumjobs(jobs)] printjobs(jobs, wide=args.wide, long=args.long, output=args.output, header=not args.noheader) return # grouping jobgroups = groupjobs(jobs, args.groupby) if not args.pending: if args.sum: jobs = [] for title in sorted(jobgroups.keys()): sumjob = sumjobs(jobgroups[title]) if args.groupby not in ("name", "jobname", "user"): sumjob["title"] = title jobs.append(sumjob) printjobs(jobs, wide=args.wide, long=args.long, output=args.output, header=not args.noheader) else: for title in sorted(jobgroups.keys()): printjobs(jobgroups[title], wide=args.wide, long=args.long, output=args.output, header=not args.noheader, title=title) return # pending for title in sorted(jobgroups.keys()): jobs = jobgroups[title] reasons = jobs[0]["pend_reason"] resreq = jobs[0]["resreq"] hostreq = jobs[0]["host_req"] if not reasons or len(reasons) != 1: title = None else: # use singular reason as title reason = reasons[0] title = reason[0] if not isinstance(reason[1], bool): title += ": %d" % reason[1] if args.sum: jobs = [sumjobs(jobs)] printjobs(jobs, wide=args.wide, long=args.long, output=args.output, header=not args.noheader, title=title) if reasons and len(reasons) > 1: # show pending reasons for reason, count in reasons: for pattern in pendingcolors: if re.match(pattern, reason): reason = color(reason, pendingcolors[pattern]) break if count is True: print(" " + reason) else: print(" %4d %s" % (count, reason)) # show potential hosts if resreq and not args.fast: resreq = re.sub(" && \(hostok\)", "", resreq) resreq = re.sub(" && \(mem>\d+\)", "", resreq) hosts = readhosts(["-R", resreq] + hostreq) hostnames = [h["host_name"] for h in hosts] jobs = readjobs(["-u", "all", "-r", "-m", " ".join(hostnames)]) hosts.sort(key=lambda h: h["host_name"]) printhosts(hosts, jobs, wide=args.wide, header=not args.noheader) if len(jobgroups) > 1: print()
def ejobs(args, bjobsargs): if args.pending: bjobsargs = ["-p"] + bjobsargs args.groupby = "pend_reason" if args.sort: args.sortby = "jobid" if args.aices: bjobsargs = ["-P", "aices", "-G", "p_aices"] + bjobsargs if args.aices2: bjobsargs = ["-P", "aices2", "-G", "p_aices"] + bjobsargs if args.aices24: bjobsargs = ["-P", "aices-24", "-G", "p_aices"] + bjobsargs for l in list("rsda"): if args.__dict__[l]: bjobsargs = ["-" + l] + bjobsargs if args.u: unames = [] for alias in args.u.split(): unames += lookupalias(alias) bjobsargs += ["-u", " ".join(unames)] # read jobs = readjobs(bjobsargs, fast=args.fast) if not jobs: return # sort statorder = { "RUN": 4, "PROV": 4, "PSUSP": 3, "USUSP": 3, "SSUSP": 3, "PEND": 2, "WAIT": 2, "UNKWN": 1, "DONE": 0, "ZOMBI": 0, "EXIT": 0, } jobs.sort(key=lambda j: j["submit_time"]) jobs.sort(key=lambda j: j["priority"], reverse=True) jobs.sort(key=lambda j: -j["run_time"]) jobs.sort(key=lambda j: -statorder[j["stat"]]) if args.sortby: jobs.sort(key=lambda j: j[args.sortby]) # no grouping if not args.groupby or args.groupby not in jobs[0]: if args.sum: printjobs([sumjobs(jobs)], wide=args.wide, long=args.long, header=not args.noheader) else: printjobs(jobs, wide=args.wide, long=args.long, header=not args.noheader) return # grouping jobgroups = groupjobs(jobs, args.groupby) if not args.pending: if args.sum: jobs = [] for title in sorted(jobgroups.keys()): jobgroup = jobgroups[title] sumjob = sumjobs(jobgroup) sumjob["title"] = title jobs.append(sumjob) printjobs(jobs, wide=args.wide, long=args.long, header=not args.noheader) else: for title in sorted(jobgroups.keys()): jobs = jobgroups[title] printjobs(jobs, wide=args.wide, long=args.long, header=not args.noheader, title=title) return # pending for title in sorted(jobgroups.keys()): jobs = jobgroups[title] reasons = jobs[0]["pend_reason"] if not reasons or len(reasons) != 1: title = None else: # only use singular reason as title reason = reasons[0] title = reason[0] if not isinstance(reason[1], bool): title += ": %d" % reason[1] if args.sum: printjobs([sumjobs(jobs)], wide=args.wide, long=args.long, header=not args.noheader, title=title) else: printjobs(jobs, wide=args.wide, long=args.long, header=not args.noheader, title=title) if reasons and len(reasons) > 1: # show pending reasons for reason, count in reasons: if reason in pendingcolors: reason = color(reason, pendingcolors[reason]) if count is True: print(" " + reason) else: print(" %4d %s" % (count, reason)) # show potential hosts if jobs[0]["resreq"] and not args.fast: req = jobs[0]["resreq"] req = re.sub(" && \(hostok\)", "", req) req = re.sub(" && \(mem>\d+\)", "", req) hosts = readhosts(["-R", req]) hostnames = [h["host_name"] for h in hosts] jobs = readjobs(["-u", "all", "-r", "-m", " ".join(hostnames)]) hosts.sort(key=lambda h: h["host_name"]) printhosts(hosts, jobs, wide=args.wide, header=not args.noheader) if len(jobgroups) > 1: print()
def ehosts(args, bhostsargs): # construct -R argument select = None if args.aices and args.aices2: select = "aices || aices2" elif args.aices: select = "aices" elif args.aices2: select = "aices2" elif args.aices24: select = "aices24" if args.model: if select: select = "(%s) && model==%s" % (select, args.model) else: select = "model==" + args.model if select: if "-R" not in bhostsargs: bhostsargs += ["-R", "select[%s]" % select] else: i = bhostsargs.index("-R") + 1 req = bhostsargs[i] if "select" in req: bhostsargs[i] = req.replace("select[", "select[(%s) & " % select, 1) else: bhostsargs[i] = "(%s) & (%s)" % (req, select) # read hosts = readhosts(bhostsargs, fast=args.fast) if not hosts: return # read jobs if args.fast: jobs = [] else: hostnames = [h["host_name"] for h in hosts] jobs = readjobs(["-u", "all", "-r", "-m", " ".join(hostnames)]) # sort if not args.nosort: hosts.sort(key=lambda h: h["host_name"]) # no grouping if not args.groupby or args.groupby not in hosts[0]: if args.sum: printhosts([sumhosts(hosts)], wide=args.wide, header=not args.noheader) else: printhosts(hosts, jobs, wide=args.wide, header=not args.noheader) return # grouping hostgroups = grouphosts(hosts, args.groupby) if args.sum: hosts = [] for title in sorted(hostgroups.keys()): hostgroup = hostgroups[title] sumhost = sumhosts(hostgroup) sumhost["title"] = title hosts.append(sumhost) printhosts(hosts, jobs, wide=args.wide, header=not args.noheader) else: for title in sorted(hostgroups.keys()): hosts = hostgroups[title] printhosts(hosts, jobs, wide=args.wide, header=not args.noheader, title=title)