def remote_modules(): try: index = urllib.urlopen(remote_index_url) return module_tuples(index.read()) except: print utility.color(' - failed to retrieve remote index', 'red') return []
def ready_indexed_module(name): if storage.module_compiled(name): print utility.color(' - already compiled', 'green') else: path = storage.module_path(name) build_directory(path) prepare_headers(name) print utility.color(' - compiled module: ' + name, 'green')
def parse_option(a): if a[:2] == '--' and a[2:] in option_table.values(): return a[2:] elif a[:1] == '-' and a[1:] in option_table.keys(): return option_table[a[1:]] else: print utility.color(' - ERROR: invalid option: ' + a, 'red') quit()
def setup(): clear() os.makedirs(modules) os.makedirs(modules + '/' + 'headers') os.makedirs(modules + '/' + 'headers/kit') with open(module_list, 'w+') as f: f.write('') print utility.color(' - setup kit storage', 'green')
def fetch_unindexed_module(repo): name = repo.split('/')[-1].replace('.git', '') clear_module(name) if 0 == os.system('git clone ' + repo + ' ' + modules + '/' + name): print utility.color(' - cloned module successfully', 'green') index(name, repo) else: print utility.color(' - failed to fetch module: ' + name, 'red')
def fetch_module(name): clear_module(name) url = remote_resolve(name) if url and 0 == os.system('git clone ' + url + ' ' + modules + '/' + name): print utility.color(' - cloned module successfully', 'green') index(name, url) else: print utility.color(' - failed to fetch module: ' + name, 'red')
def directory_metafile_contents(path): path += '/kit.meta' if os.path.exists(path): f = open(path, 'r') text = f.read() try: return json.loads(text) except: print utility.color(" - ERROR: couldn't parse kit.meta", 'red') exit(1) f.close() else: return ''
def build_directory(path): deps = scanner.directory_dependencies(path) for dep in deps: print ' - resolving dependency:', dep if not storage.contains_module(dep): if storage.remote_contains_module(dep): storage.fetch_module(dep) else: print utility.color(' - module not found: ' + dep, 'red') print utility.color(' - build failed', 'red') exit(1) ready_indexed_module(dep) generate_cmake(path, deps) make(path)
def build_directory(path,options=None): deps = scanner.recursive_dependencies(path) for dep in deps: # print ' - resolving dependency:', dep if not storage.contains_module(dep): if storage.remote_contains_module(dep): storage.fetch_module(dep) else: print utility.color(' - module not found: ' + dep, 'red') print utility.color(' - build failed', 'red') exit(1) ready_indexed_module(dep) generate_cmake(path, deps,options) make(path,options)
def make(path): print ' - running `make`...' wd = os.getcwd() os.chdir(path) os.system('mkdir -p build') os.chdir('build') c1 = os.system('cmake -Wno-dev .. > /dev/null') c2 = os.system('make > /dev/null') os.system('rm ../CMakeLists.txt') os.chdir(wd) if c1 == 0 and c2 == 0: print utility.color(' - build successfull', 'green') else: print utility.color(' - build failed', 'red') exit(1)
def modules(context): local = storage.local_modules() print 'local: (' + str(len(local)) + ')' for m in local: if storage.module_compiled(m[0]): print ' - ' + m[0], '[' + utility.color('compiled', 'green') + ']' else: print ' - ' + m[0], '[' + utility.color('not compiled', 'red') + ']' if context.local: return remote = storage.remote_modules() print '\nremote: (' + str(len(remote)) + ')' for m in remote: print ' -', m[0], '[' + utility.color(m[1], 'yellow') + ']'
def main(): parser = argparse.ArgumentParser(description="More comprehensive version of bjobs.") parser.add_argument("-l", "--long", help="long job description", action="store_true") parser.add_argument("-w", "--wide", help="don't shorten strings", action="store_true") exg = parser.add_mutually_exclusive_group() exg.add_argument("-p", "--pending", help="show pending jobs with reasons and potential hosts", action="store_true") exg.add_argument("--group", help="group jobs by attribute", metavar="BY") parser.add_argument("-aices", help="short for -G p_aices", action="store_true") parser.add_argument("--nopar", help="faster response, longer runtime", action="store_true") parser.add_argument("-d", "--debug", help="show debug info on errors", action="store_true") parser.add_argument_group("further arguments", description="are passed to bjobs") args, bjobsargs = parser.parse_known_args() if args.debug: ejobs(args, bjobsargs) else: try: ejobs(args, bjobsargs) except KeyboardInterrupt: pass except Exception: print( color("ERROR -- probably a job status changed while " + sys.argv[0] + " processed it", "r"), file=sys.stderr, )
def log_event(self, message): self.event_log.move(1, 1) self.event_log.deleteln() self.event_log.move(self.event_log.getmaxyx()[0] - 2, 1) self.event_log.insertln() self.event_log.border() self.event_log.addstr(self.event_log.getmaxyx()[0] - 2, 1, message, color(foreground=curses.COLOR_YELLOW))
def main(): parser = argparse.ArgumentParser( description="More comprehensive version of bjobs." ) parser.add_argument( "-l", "--long", help="long job description", action="store_true", ) parser.add_argument( "-w", "--wide", help="don't shorten strings", action="store_true", ) exg = parser.add_mutually_exclusive_group() exg.add_argument( "-p", "--pending", help="show pending jobs with reasons and potential hosts", action="store_true", ) exg.add_argument( "--group", help="group jobs by attribute", metavar="BY", ) parser.add_argument( "-aices", help="short for -G p_aices", action="store_true", ) parser.add_argument( "--nopar", help="faster response, longer runtime", action="store_true", ) parser.add_argument( "-d", "--debug", help="show debug info on errors", action="store_true", ) parser.add_argument_group("further arguments", description="are passed to bjobs") args, bjobsargs = parser.parse_known_args() if args.debug: ejobs(args, bjobsargs) else: try: ejobs(args, bjobsargs) except KeyboardInterrupt: pass except Exception: print(color("ERROR -- probably a job status changed while " + sys.argv[0] + " processed it", "r"), file=sys.stderr)
def make(path,options=None): if options is None: options = [] print ' - running `make`...' wd = os.getcwd() os.chdir(path) run_configuration(path) os.system('mkdir -p build') os.chdir('build') c1 = os.system('cmake -Wno-dev .. > /dev/null') if "verbose" in options: c2 = os.system('make VERBOSE=1') else: c2 = os.system('make > /dev/null') if not "save-cmake" in options: os.system('rm ../CMakeLists.txt') os.chdir(wd) if c1 == 0 and c2 == 0: print utility.color(' - build successfull', 'green') else: print utility.color(' - build failed', 'red') exit(1)
def main(): global args parser = argparse.ArgumentParser( description="More comprehensive version of bhosts.") parser.add_argument( "-w", "--wide", help="don't shorten strings", action="store_true", ) parser.add_argument( "-aices", help="short for -R select[aices]", action="store_true", ) parser.add_argument( "-m", "--model", help="short for -R select[model==MODEL]", ) parser.add_argument( "--nopar", help="faster response, longer runtime", action="store_true", ) parser.add_argument( "-d", "--debug", help="show debug info on errors", action="store_true", ) parser.add_argument("-R", help=argparse.SUPPRESS) parser.add_argument_group("further arguments", description="are passed to bhosts") args, bhostsargs = parser.parse_known_args() if args.debug: ehosts(args, bhostsargs) else: try: ehosts(args, bhostsargs) except KeyboardInterrupt: pass except Exception: print(color( "ERROR -- probably a job status changed while " + sys.argv[0] + " processed it", "r"), file=sys.stderr)
def main(): global args parser = argparse.ArgumentParser( description="More comprehensive version of bhosts.") parser.add_argument( "-w", "--wide", help="don't shorten strings", action="store_true", ) parser.add_argument( "-aices", help="short for -R select[aices]", action="store_true", ) parser.add_argument( "-m", "--model", help="short for -R select[model==MODEL]", ) parser.add_argument( "--nopar", help="faster response, longer runtime", action="store_true", ) parser.add_argument( "-d", "--debug", help="show debug info on errors", action="store_true", ) parser.add_argument( "-R", help=argparse.SUPPRESS ) parser.add_argument_group("further arguments", description="are passed to bhosts") args, bhostsargs = parser.parse_known_args() if args.debug: ehosts(args, bhostsargs) else: try: ehosts(args, bhostsargs) except KeyboardInterrupt: pass except Exception: print(color("ERROR -- probably a job status changed while " + sys.argv[0] + " processed it", "r"), file=sys.stderr)
def esub(args, bsubargs, jobscript): data = {"command": ""} if args.aices: data["project"] = "aices" if args.aices2: data["project"] = "aices2" scriptargs = [] for line in jobscript.splitlines(True): if line.startswith("#!"): data["command"] += line elif line.startswith("#BSUB "): scriptargs += shlex.split(line[6:].split("#")[0]) else: data["command"] += line.split("#")[0] bsubargs = scriptargs + bsubargs last = False cmd = False for arg in bsubargs: if cmd: data["command"] += " " + arg continue if arg[0] == "-": if last: data[last] = True last = arg else: if last: data[last] = arg last = False else: cmd = True data["command"] = arg if last: data[last] = True try: jobid = submitjob(data) subprocess.Popen(["ejobs", "--noheader", jobid]) except Exception as e: print(color(e.strerror, "r")) sys.exit(-1)
def esub(args, bsubargs, jobscript): """Wrapper script with bsub functionality.""" data = {"command": ""} scriptargs = [] for line in jobscript.splitlines(True): if line.startswith("#!"): data["command"] += line elif line.startswith("#BSUB "): scriptargs += shlex.split(line[6:].split("#")[0]) else: data["command"] += line.split("#")[0] bsubargs = scriptargs + bsubargs last = False cmd = False for arg in bsubargs: if cmd: data["command"] += " " + arg continue if arg[0] == "-": if last: data[last] = True last = arg else: if last: data[last] = arg last = False else: cmd = True data["command"] = arg if last: data[last] = True try: jobid = submitjob(data) print(jobid) except Exception as e: print(color(e.strerror, "r")) sys.exit(-1)
def index(name, url): with open(module_list, 'a') as f: f.write('\n' + name + ', ' + url) print utility.color(' - indexed module: ' + name, 'green')
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: args.group = "PENDING REASONS" if args.aices: bjobsargs = ["-G", "p_aices"] + bjobsargs if sys.stdout.isatty(): print("Reading job list from LSF ...", end="\r") sys.stdout.flush() joblist = Joblist(bjobsargs) if sys.stdout.isatty(): print(" ", end="\r") if args.pending: joblists = joblist.groupby("Status") if "PEND" in joblists: joblist = joblists["PEND"] else: joblist = Joblist() joblists = joblist.groupby(args.group) if not args.pending: for group, joblist in joblists.items(): if group: groupn = group if args.group == "User": groupn = joblist[0]["Userstr"] title = "{} = {} [{}]".format(args.group, groupn, len(joblist)) else: title = None joblist.display(args.long, args.wide, title, parallel=not args.nopar) return for reasons in sorted(joblists.keys(), key=len): pendjobs = joblists[reasons] if len(reasons) == 1 and reasons[0][1] is True: if reasons[0][0] in ( "New job is waiting for scheduling", "Dependency condition invalid or never satisfied", "The schedule of the job is postponed for a while", ): title = "{} [{}]".format(reasons[0][0], len(pendjobs)) pendjobs.display(args.long, args.wide, title, parallel=not args.nopar) continue lists = {} resgrouped = pendjobs.groupby("Requested Resources") for res, rlist in resgrouped.iteritems(): hostgrouped = rlist.groupby("Specified Hosts") for hosts, hlist in hostgrouped.iteritems(): lists[res, hosts] = hlist for case, casejobs in lists.iteritems(): title = "[{}]".format(len(casejobs)) casejobs.display(args.long, args.wide, title, parallel=not args.nopar) print() print("Pending reasons:") cs = { "Running an exclusive job": "y", "Job's requirement for exclusive execution not satisfied": "y", "An exclusive job has reserved the host": "y", "Job slot limit reached": "y", "Not enough processors to meet the job's spanning requirement": "y", "Not enough slots or resources for whole duration of the job": "r", "Not enough hosts to meet the job's spanning requirement": "r", } for reason, count in reasons: s = reason if reason in cs: s = color(reason, cs[reason]) if count is True: print(" " + s) else: print(" {:>4} ".format(count) + s) if case[1]: req = [case[1]] else: req = case[0] req = re.sub(" && \(hostok\)", "", req) req = re.sub(" && \(mem>\d+\)", "", req) req = ["-R", req] print("Potential hosts:") if sys.stdout.isatty(): print("Reading host list from LSF ...", end="\r") sys.stdout.flush() hl = Hostlist(req) hl.sort() hl.display(wide=args.wide, indent=" ", parallel=not args.nopar) hl = {h["HOST"]: h for h in Hostlist(req)}
def printhosts(hosts, jobs=[], wide=False, header=True, file=sys.stdout): """list the hosts.""" if len(hosts) == 0: return sumhosts = not isinstance(hosts[0]["status"], str) jobsbyhost = groupjobs(jobs, "exec_host") # begin output screencols = int(check_output(["tput", "cols"])) whoami = os.getenv("USER") namelen = max(map(len, (host["host_name"] for host in hosts))) lens = { "host_name": min(20, max(6, namelen + 1)), "status": 8, "title": 15, "cpus": 10 } if wide: lens["title"] = 20 lens["host_name"] = max(6, namelen + 1) lens["model"] = 14 if sumhosts: lens["status"] = 12 lens["cpus"] = 14 if header: h = "" if sumhosts and "title" in hosts[0]: h += "group".ljust(lens["title"]) h += "".join(n.ljust(lens[n]) for n in ("host_name", "status", "cpus")) h += "mem (free/total)" if wide: h += " " + "model".ljust(lens["model"]) h = h.upper() print(h, file=file) for host in hosts: l = "" if sumhosts and "title" in host: # title title = host["title"] if not wide: if len(title) >= lens["title"]: title = title[:lens["title"] - 2] + "*" l += color(title.ljust(lens["title"]), "b") # host_name l += host["host_name"].ljust(lens["host_name"]) # status if sumhosts: l += color("%3d " % host["status"]["ok"], "g") closed = sum(n for stat, n in host["status"].iteritems() if stat.startswith("closed_")) l += color("%3d " % closed, "r") other = len(host["host_names"]) - host["status"]["ok"] - closed if other: l += color("%3d " % other, "y") else: l += " " else: if host["status"] == "ok": l += color("ok".ljust(lens["status"]), "g") elif "closed_" in host["status"]: l += color(host["status"][7:].ljust(lens["status"]), "r") else: l += color(host["status"].ljust(lens["status"]), "y") # cpus total = host["max"] used = host["njobs"] free = total - used c = fractioncolor(free / total) if sumhosts: l += color("%4d" % free, c) + "/%4d" % total else: l += color("%2d" % free, c) + "/%2d" % total # mem if "mem" in host["load"]: free, used = host["load"]["mem"] total = free + used if "maxmem" in host and host["maxmem"]: total = host["maxmem"] c = fractioncolor(free / total) l += " " + format_mem(free, c) + "/" + format_mem(total) if wide: if sumhosts: if len(host["model"]) == 1: l += host["model"][0].ljust(lens["model"]) else: nmodel = len(host["model"]) l += color((" %d" % nmodel).ljust(lens["model"]), "b") else: hoststr = host["model"] # Xeon Phi(s) phis = 0 if "mic0" in host["load"]: phis += int(bool(host["load"]["mic0"][0])) if "mic1" in host["load"]: phis += int(bool(host["load"]["mic1"][0])) if phis > 0: hoststr += "+%dPhi" % phis # GPU if "gpu" in host["resources"]: hoststr += "+GPU" l += " " + hoststr.ljust(14) l += " " if host["rsv"] > 0: l += " %3d*" % host["rsv"] + color("reserved", "y") if sumhosts: hostnames = host["host_names"] else: hostnames = [host["host_name"]] jobs = [] for hostname in hostnames: if hostname in jobsbyhost: for job in jobsbyhost[hostname]: if job not in jobs: jobs.append(job) if sumhosts: jobgroups = groupjobs(jobs, "user") jobs = [] for user in sorted(jobgroups.keys()): jobs.append(sumjobs(jobgroups[user])) if jobs: for job in jobs: exclusive = job["exclusive"] if sumhosts: exclusive = len(exclusive) == 1 and True in exclusive times = color("x", "r") if exclusive else "*" nslots = sum(job["exec_host"][hn] for hn in hostnames if hn in job["exec_host"]) c = "r" if nslots >= 100 else "y" if nslots >= 20 else 0 l += color(" %3d" % nslots, c) user = job["user"] if sumhosts: user = user.keys()[0] c = "g" if user == whoami else 0 l += times + color(getuseralias(user).ljust(8), c) if wide and not sumhosts: if job["mem"]: l += format_mem(job["mem"]) else: l += " " if job["%complete"] and job["runlimit"]: ptime = job["%complete"] c = fractioncolor(1 - ptime / 100) l += color("%3d" % ptime, c) + "% " l += format_duration(job["runlimit"]) if host["comment"]: if sumhosts: for key, val in host["comment"].iteritems(): if key: l += " %3dx" % val + color(key, "b") else: l += " " + color(host["comment"], "b") print(l, file=file) file.flush()
def printjobs(jobs, wide=False, long=False, title=None, header=True, file=sys.stdout): """list the jobs""" if len(jobs) == 0: return sumjob = not isinstance(jobs[0]["jobid"], str) if long: for job in jobs: printjoblong(job, sumjob=sumjob, file=file) return # begin output whoami = os.getenv("USER") namelen = max(map(len, (job["job_name"] for job in jobs))) lens = { "title": 10, "jobid": 10, "name": min(20, max(6, namelen + 1)), "stat": 6, "user": 10, "time": 12 } if sumjob: lens["stat"] = 12 else: if any(job["jobid"][-1] == "]" for job in jobs): lens["jobid"] = 14 if wide: lens["title"] = 20 lens["name"] = max(6, namelen + 1) lens["queue"] = 8 lens["project"] = 8 lens["prio."] = 6 # header if header: h = "" if sumjob and "title" in jobs[0]: h += "group".ljust(lens["title"]) if not sumjob: h += "jobid".ljust(lens["jobid"]) h += "".join(n.ljust(lens[n]) for n in ("name", "stat", "user")) if wide: h += "".join(n.ljust(lens[n]) for n in ("queue", "project")) if not sumjob: h += "prio.".ljust(lens["prio."]) if sumjob: h += "runtime".rjust(lens["time"]) else: h += "wait/runtime".rjust(lens["time"]) h += " resources" h = h.upper() if title: h += " " + color(title, "b") print(h, file=file) for job in jobs: l = "" if sumjob and "title" in job: # title title = job["title"] if not wide: if len(title) >= lens["title"]: title = title[:lens["title"] - 2] + "*" l += color(title.ljust(lens["title"]), "b") if not sumjob: # jobid l += (job["jobid"] + " ").ljust(lens["jobid"]) # job name jobname = job["job_name"] if job["job_name"] else "" if not wide: if len(jobname) >= lens["name"]: jobname = "*" + jobname[-lens["name"] + 2:] l += jobname.ljust(lens["name"]) # status if sumjob: l += color("%3d " % job["stat"]["PEND"], "r") l += color("%3d " % job["stat"]["RUN"], "g") done = job["stat"]["EXIT"] + job["stat"]["DONE"] if done: l += color("%3d " % done, "y") else: l += " " else: stat = job["stat"] c = "r" if stat == "PEND" else "g" if stat == "RUN" else "y" l += color(stat.ljust(lens["stat"]), c) # user if sumjob: if len(job["user"]) == 1: user = job["user"].keys()[0] c = "g" if user == whoami else 0 username = getuseralias(user) l += color(username.ljust(lens["user"]), c) else: l += color(str(len(job["user"])).ljust(lens["user"]), "b") else: c = "g" if job["user"] == whoami else 0 username = getuseralias(job["user"]) l += color((username + " ").ljust(lens["user"]), c) if wide: # queue if sumjob: if len(job["queue"]) == 1: l += job["queue"].keys()[0].ljust(lens["queue"]) else: nqueues = len(job["queue"]) l += color(str(nqueues).ljust(lens["queue"]), "b") else: l += job["queue"].ljust(lens["queue"]) # project if sumjob: if len(job["project"]) == 1: l += job["project"].keys()[0].ljust(lens["project"]) else: n = len(job["project"]) else: l += job["project"].ljust(lens["project"]) if not sumjob: # priority l += str(job["priority"]).rjust(lens["prio."] - 1) + " " # wait/runtime t = job["run_time"] if not sumjob and job["stat"] == "PEND": t = time() - job["submit_time"] s = format_duration(t) l += s.rjust(lens["time"]) # resources # %t if job["%complete"]: ptime = job["%complete"] c = fractioncolor(1 - ptime / 100) if wide: s = "%6.2f" % round(ptime, 2) else: s = "%3d" % int(round(ptime)) l += " " + color(s, c) + "%t" elif not sumjob and job["stat"] == "RUN": l += " " if wide: l += " " # %m if job["memlimit"] and job["mem"] and job["slots"]: memlimit = job["memlimit"] * job["slots"] pmem = 100 * job["mem"] / memlimit c = fractioncolor(1 - pmem / 100) if wide: s = "%6.2f" % round(pmem, 2) else: s = "%3d" % int(round(pmem)) l += " " + color(s, c) + "%m" elif not sumjob and job["stat"] == "RUN": l += " " if wide: l += " " # time if job["runlimit"]: l += " " + format_duration(job["runlimit"]) # memory if job["memlimit"]: l += format_mem(job["memlimit"]).rjust(10) else: l += "".rjust(10) # Hosts if job["exec_host"]: if wide or len(job["exec_host"]) == 1: d = job["exec_host"] else: d = defaultdict(int) for key, val in job["exec_host"].iteritems(): d[re.match("(.*?)\d+", key).groups()[0] + "*"] += val for key in sorted(d.keys()): val = d[key] c = "r" if val >= 100 else "y" if val >= 20 else 0 exclusive = job["exclusive"] if sumjob: exclusive = len(exclusive) == 1 and True in exclusive times = color("x", "r") if exclusive else "*" l += color(" %3d" % val, c) + times + "%s" % key else: if not sumjob: if job["min_req_proc"]: times = color("x", "r") if job["exclusive"] else "*" l += " %3d" % job["min_req_proc"] + times elif job["exclusive"]: l += " 1" + color("x", "r") else: l += " 1*" if job["resreq"]: match = re.search("model==(\w+)", job["resreq"]) if match: l += match.groups()[0] if re.search("phi", job["resreq"]): if match: l += "+" l += "Phi" if job["rsvd_host"]: l += color(" rsvd:", "y") if wide or len(job["rsvd_host"]) == 1: d = job["rsvd_host"] else: d = defaultdict(int) for key, val in job["rsvd_host"].iteritems(): d[re.match("(.*?)\d+", key).groups()[0] + "*"] += val for key, val in d.iteritems(): c = "r" if val >= 100 else "y" if val >= 20 else 0 l += color(" %3d" % val, c) + "*%s" % key print(l, file=file) file.flush()
def printjobs(jobs, wide=False, long=False, output=None, title=None, header=True, file=sys.stdout): """Print a list of jobs.""" if len(jobs) == 0: return sumjob = not isinstance(jobs[0]["jobid"], str) if long: for job in jobs: printjoblong(job, sumjob=sumjob, file=file) return if output: if header: print(*output, sep="\t", file=file) for job in jobs: print(*[job[field] for field in output], sep="\t", file=file) return # begin output whoami = os.getenv("USER") namelen = max(map(len, (job["job_name"] for job in jobs))) if sumjob: titlelen = 0 if "title" in jobs[0]: titlelen = max(map(len, (job["title"] for job in jobs))) lens = { "title": 10, "jobid": 10, "name": min(20, max(6, namelen + 1)), "stat": 6, "user": 10, "time": 12, "model": 14 } if sumjob: lens["stat"] = 12 else: if any(job["jobid"][-1] == "]" for job in jobs): lens["jobid"] = 14 if wide: if sumjob: lens["title"] = max(6, titlelen + 1) lens["name"] = max(6, namelen + 1) lens["queue"] = 8 lens["project"] = 8 lens["prio."] = 6 # header if header: h = "" if sumjob and "title" in jobs[0]: h += "group".ljust(lens["title"]) if not sumjob: h += "jobid".ljust(lens["jobid"]) h += "".join(n.ljust(lens[n]) for n in ("name", "stat", "user")) if wide: h += "".join(n.ljust(lens[n]) for n in ("queue", "project")) if not sumjob: h += "prio.".ljust(lens["prio."]) if sumjob: h += "runtime".rjust(lens["time"]) else: h += "wait/runtime".rjust(lens["time"]) h += " resources" h = h.upper() if title: h += " " + color(title, "b") print(h, file=file) for job in jobs: l = "" if sumjob and "title" in job: # title title = job["title"] if not wide: if len(title) >= lens["title"]: title = title[:lens["title"] - 2] + "*" l += color(title.ljust(lens["title"]), "b") if not sumjob: # jobid l += (job["jobid"] + " ").ljust(lens["jobid"]) # job name jobname = job["job_name"] if job["job_name"] else "" if not wide: if len(jobname) >= lens["name"]: jobname = "*" + jobname[-lens["name"] + 2:] l += jobname.ljust(lens["name"]) # status if sumjob and isinstance(job["stat"], defaultdict): l += color("%3d " % job["stat"]["PEND"], "r") l += color("%3d " % job["stat"]["RUN"], "g") done = job["stat"]["EXIT"] + job["stat"]["DONE"] if done: l += color("%3d " % done, "y") else: l += " " else: stat = job["stat"] if stat == "PEND": c = "r" if len(job["pend_reason"]) == 1: pr = job["pend_reason"][0] if "New job is waiting for scheduling" in pr[0]: stat = "NEW" c = "b" if "Waiting for rescheduling after parameters" in pr[0]: stat = "MOD" c = "b" if "Job dependency condition not satisfied" in pr[0]: stat = "DEP" c = "b" elif stat == "RUN": c = "g" if job["interactive"]: stat = "INT" if job["X11"]: stat = "X11" else: c = "y" l += color(stat.ljust(lens["stat"]), c) # user if sumjob and isinstance(job["user"], defaultdict): l += color(str(len(job["user"])).ljust(lens["user"]), "b") else: c = "g" if job["user"] == whoami else 0 username = getuseralias(job["user"]) l += color((username + " ").ljust(lens["user"]), c) if wide: # queue if sumjob and isinstance(job["queue"], defaultdict): l += color(str(len(job["queue"])).ljust(lens["queue"]), "b") else: l += job["queue"].ljust(lens["queue"]) # project if sumjob and isinstance(job["project"], defaultdict): l += color( str(len(job["project"])).ljust(lens["project"]), "b") else: l += job["project"].ljust(lens["project"]) if not sumjob: # priority l += str(job["priority"]).rjust(lens["prio."] - 1) + " " # wait/runtime t = job["run_time"] if not sumjob and job["stat"] == "PEND": t = time() - job["submit_time"] s = format_duration(t) l += s.rjust(lens["time"]) # resources # %t if job["%complete"]: ptime = job["%complete"] c = fractioncolor(1 - ptime / 100) if wide: s = "%6.2f" % round(ptime, 2) else: s = "%3d" % int(round(ptime)) l += " " + color(s, c) + "%t" elif not sumjob and job["stat"] == "RUN": l += " " if wide: l += " " # %m if job["memlimit"] and job["mem"] and job["slots"]: memlimit = job["memlimit"] * job["slots"] pmem = 100 * job["mem"] / memlimit c = fractioncolor(1 - pmem / 100) if wide: s = "%6.2f" % round(pmem, 2) else: s = "%3d" % int(round(pmem)) l += " " + color(s, c) + "%m" elif not sumjob and job["stat"] == "RUN": l += " " if wide: l += " " # time if job["runlimit"]: l += " " + format_duration(job["runlimit"]) # memory memlimit = None if job["memlimit"]: memlimit = job["memlimit"] if job["min_req_proc"]: memlimit *= job["min_req_proc"] if memlimit is not None: l += format_mem(memlimit).rjust(10) else: l += "".rjust(10) # Hosts if job["exec_host"]: if wide or len(job["exec_host"]) == 1: d = job["exec_host"] else: d = defaultdict(int) for key, val in job["exec_host"].iteritems(): d[re.match("(.*?)\d+", key).groups()[0] + "*"] += val for key in sorted(d.keys()): val = d[key] c = "r" if val >= 100 else "y" if val >= 20 else 0 exclusive = job["exclusive"] if sumjob and exclusive not in (True, False): exclusive = False times = color("x", "r") if exclusive else "*" l += color(" %3d" % val, c) + times + "%s" % key else: if not sumjob: if job["min_req_proc"]: times = color("x", "r") if job["exclusive"] else "*" l += " %3d" % job["min_req_proc"] + times elif job["exclusive"]: l += " 1" + color("x", "r") else: l += " 1*" if job["host_req"]: hosts = job["host_req"] if len(hosts) == 1: hosts = hosts[0] else: if wide: hosts = "(%s)" % ", ".join(hosts) else: hosts = findstringpattern(hosts) l += hosts.ljust(lens["model"]) elif job["resreq"]: match = re.search("model==(\w+)", job["resreq"]) model = "" if match: model += match.groups()[0] if re.search("phi", job["resreq"]): if match: model += "+" model += "Phi" l += model.ljust(lens["model"]) if job["alloc_slot"]: l += color(" rsvd:", "y") if wide or len(job["alloc_slot"]) == 1: d = job["alloc_slot"] else: d = defaultdict(int) for key, val in job["alloc_slot"].iteritems(): d[re.match("(.*?)\d+", key).groups()[0] + "*"] += val for key, val in d.iteritems(): c = "r" if val >= 100 else "y" if val >= 20 else 0 l += color(" %3d" % val, c) + "*%s" % key if wide and job["pend_reason"] and len(job["pend_reason"]) == 1: reason = job["pend_reason"][0][0] if reason != title: l += color(" %s" % reason, "b") if job["dependency"]: l += color(":", "b") if job["dependency"]: l += color(" %s" % job["dependency"], "b") print(l, file=file) file.flush()
def remote_resolve(name): matches = filter(lambda t: t[0] == name, remote_modules()) if len(matches) > 0: return matches[0][1] print utility.color(' - failed to resolve module: ' + name, 'red')
def unindex(name): mods = filter(lambda t: t[0] != name, local_modules()) with open(module_list, 'w') as f: f.writelines(map(', '.join, mods)) print utility.color(' - unindexed module: ' + name, 'green')
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 printjobs(jobs, wide=False, long=False, output=None, title=None, header=True, file=sys.stdout): """Print a list of jobs.""" if len(jobs) == 0: return sumjob = not isinstance(jobs[0]["jobid"], str) if long: for job in jobs: printjoblong(job, sumjob=sumjob, file=file) return if output: # header print(*output, sep="\t", file=file) for job in jobs: print(*[job[field] for field in output], sep="\t", file=file) return # begin output whoami = os.getenv("USER") namelen = max(map(len, (job["job_name"] for job in jobs))) if sumjob: titlelen = 0 if "title" in jobs[0]: titlelen = max(map(len, (job["title"] for job in jobs))) lens = { "title": 10, "jobid": 10, "name": min(20, max(6, namelen + 1)), "stat": 6, "user": 10, "time": 12, "model": 14 } if sumjob: lens["stat"] = 12 else: if any(job["jobid"][-1] == "]" for job in jobs): lens["jobid"] = 14 if wide: if sumjob: lens["title"] = max(6, titlelen + 1) lens["name"] = max(6, namelen + 1) lens["queue"] = 8 lens["project"] = 8 lens["prio."] = 6 # header if header: h = "" if sumjob and "title" in jobs[0]: h += "group".ljust(lens["title"]) if not sumjob: h += "jobid".ljust(lens["jobid"]) h += "".join(n.ljust(lens[n]) for n in ("name", "stat", "user")) if wide: h += "".join(n.ljust(lens[n]) for n in ("queue", "project")) if not sumjob: h += "prio.".ljust(lens["prio."]) if sumjob: h += "runtime".rjust(lens["time"]) else: h += "wait/runtime".rjust(lens["time"]) h += " resources" h = h.upper() if title: h += " " + color(title, "b") print(h, file=file) for job in jobs: l = "" if sumjob and "title" in job: # title title = job["title"] if not wide: if len(title) >= lens["title"]: title = title[:lens["title"] - 2] + "*" l += color(title.ljust(lens["title"]), "b") if not sumjob: # jobid l += (job["jobid"] + " ").ljust(lens["jobid"]) # job name jobname = job["job_name"] if job["job_name"] else "" if not wide: if len(jobname) >= lens["name"]: jobname = "*" + jobname[-lens["name"] + 2:] l += jobname.ljust(lens["name"]) # status if sumjob and isinstance(job["stat"], defaultdict): l += color("%3d " % job["stat"]["PEND"], "r") l += color("%3d " % job["stat"]["RUN"], "g") done = job["stat"]["EXIT"] + job["stat"]["DONE"] if done: l += color("%3d " % done, "y") else: l += " " else: stat = job["stat"] if stat == "PEND": c = "r" if len(job["pend_reason"]) == 1: pr = job["pend_reason"][0] if "New job is waiting for scheduling" in pr[0]: stat = "NEW" c = "b" if "Waiting for rescheduling after parameters" in pr[0]: stat = "MOD" c = "b" if "Job dependency condition not satisfied" in pr[0]: stat = "DEP" c = "b" elif stat == "RUN": c = "g" if job["interactive"]: stat = "INT" if job["X11"]: stat = "X11" else: c = "y" l += color(stat.ljust(lens["stat"]), c) # user if sumjob and isinstance(job["user"], defaultdict): l += color(str(len(job["user"])).ljust(lens["user"]), "b") else: c = "g" if job["user"] == whoami else 0 username = getuseralias(job["user"]) l += color((username + " ").ljust(lens["user"]), c) if wide: # queue if sumjob and isinstance(job["queue"], defaultdict): l += color(str(len(job["queue"])).ljust(lens["queue"]), "b") else: l += job["queue"].ljust(lens["queue"]) # project if sumjob and isinstance(job["project"], defaultdict): l += color(str(len(job["project"])).ljust(lens["project"]), "b") else: l += job["project"].ljust(lens["project"]) if not sumjob: # priority l += str(job["priority"]).rjust(lens["prio."] - 1) + " " # wait/runtime t = job["run_time"] if not sumjob and job["stat"] == "PEND": t = time() - job["submit_time"] s = format_duration(t) l += s.rjust(lens["time"]) # resources # %t if job["%complete"]: ptime = job["%complete"] c = fractioncolor(1 - ptime / 100) if wide: s = "%6.2f" % round(ptime, 2) else: s = "%3d" % int(round(ptime)) l += " " + color(s, c) + "%t" elif not sumjob and job["stat"] == "RUN": l += " " if wide: l += " " # %m if job["memlimit"] and job["mem"] and job["slots"]: memlimit = job["memlimit"] * job["slots"] pmem = 100 * job["mem"] / memlimit c = fractioncolor(1 - pmem / 100) if wide: s = "%6.2f" % round(pmem, 2) else: s = "%3d" % int(round(pmem)) l += " " + color(s, c) + "%m" elif not sumjob and job["stat"] == "RUN": l += " " if wide: l += " " # time if job["runlimit"]: l += " " + format_duration(job["runlimit"]) # memory memlimit = None if job["memlimit"]: memlimit = job["memlimit"] if job["min_req_proc"]: memlimit *= job["min_req_proc"] if memlimit is not None: l += format_mem(memlimit).rjust(10) else: l += "".rjust(10) # Hosts if job["exec_host"]: if wide or len(job["exec_host"]) == 1: d = job["exec_host"] else: d = defaultdict(int) for key, val in job["exec_host"].iteritems(): d[re.match("(.*?)\d+", key).groups()[0] + "*"] += val for key in sorted(d.keys()): val = d[key] c = "r" if val >= 100 else "y" if val >= 20 else 0 exclusive = job["exclusive"] if sumjob and exclusive not in (True, False): exclusive = False times = color("x", "r") if exclusive else "*" l += color(" %3d" % val, c) + times + "%s" % key else: if not sumjob: if job["min_req_proc"]: times = color("x", "r") if job["exclusive"] else "*" l += " %3d" % job["min_req_proc"] + times elif job["exclusive"]: l += " 1" + color("x", "r") else: l += " 1*" if job["host_req"]: hosts = job["host_req"] if len(hosts) == 1: hosts = hosts[0] else: if wide: hosts = "(%s)" % ", ".join(hosts) else: hosts = findstringpattern(hosts) l += hosts.ljust(lens["model"]) elif job["resreq"]: match = re.search("model==(\w+)", job["resreq"]) model = "" if match: model += match.groups()[0] if re.search("phi", job["resreq"]): if match: model += "+" model += "Phi" l += model.ljust(lens["model"]) if job["alloc_slot"]: l += color(" rsvd:", "y") if wide or len(job["alloc_slot"]) == 1: d = job["alloc_slot"] else: d = defaultdict(int) for key, val in job["alloc_slot"].iteritems(): d[re.match("(.*?)\d+", key).groups()[0] + "*"] += val for key, val in d.iteritems(): c = "r" if val >= 100 else "y" if val >= 20 else 0 l += color(" %3d" % val, c) + "*%s" % key if wide and job["pend_reason"] and len(job["pend_reason"]) == 1: reason = job["pend_reason"][0][0] if reason != title: l += color(" %s" % reason, "b") if job["dependency"]: l += color(":", "b") if job["dependency"]: l += color(" %s" % job["dependency"], "b") print(l, file=file) file.flush()
def print(self): """ print game map to window """ if self.resized: self.resized = False self.setup() self.screen.addstr(1, 3, f"Ebene {self.player.level}") self.screen.addstr(1, 20, f'Position: {self.current_position}') if self.player.level < len(self.visited): self.visit(*self.current_position) for i in (-1, 1): if self.level_value(self.current_position[0] + i, self.current_position[1]) == ' ': self.see(self.current_position[0] + i, self.current_position[1]) if self.level_value(self.current_position[0], self.current_position[1] + i) == ' ': self.see(self.current_position[0], self.current_position[1] + i) if 0 <= self.player.level < len(self.levels): for y_index, row in enumerate(self.levels[self.player.level]): for x_index, value in enumerate(row): if (x_index, y_index) not in self.seen[self.player.level]: self.map.addstr(y_index, x_index, '#', color(foreground=curses.COLOR_BLUE)) elif (x_index, y_index) \ not in self.visited[self.player.level] \ and value in ('M', 'O', 'I'): self.map.addstr(y_index, x_index, constants.UNKNOWN, color(foreground=curses.COLOR_MAGENTA)) elif value == 'I': self.map.addstr(y_index, x_index, constants.ITEM, color(foreground=curses.COLOR_CYAN)) elif value == 'X': self.map.addstr(y_index, x_index, constants.SAVEPOINT, color(foreground=curses.COLOR_BLUE)) elif value == '=': self.map.addstr(y_index, x_index, constants.LADDER_UP, color(foreground=curses.COLOR_GREEN)) elif value == '%': self.map.addstr(y_index, x_index, constants.LADDER_DOWN, color(foreground=curses.COLOR_GREEN)) elif value == 'M': self.map.addstr(y_index, x_index, constants.MONSTER, color(foreground=curses.COLOR_RED)) elif value == 'O': self.map.addstr(y_index, x_index, constants.HOLE) else: self.map.addstr(y_index, x_index, value) self.map.addstr(self.current_position[1], self.current_position[0], constants.PLAYER, color(foreground=curses.COLOR_YELLOW)) self.status_info.addstr(1, 2, "HP: ") self.status_info.addstr(1, 6, 10 * ' ', color(foreground=curses.COLOR_RED)) self.status_info.addstr(1, 6, self.health_bar, color(foreground=curses.COLOR_RED)) self.status_info.addstr( 1, 17, f'{self.player.current_health:3}/' f'{self.player.max_health:3}') self.status_info.addstr(1, 27, f"Staerke: {self.player.strength}") self.refresh()
def printhosts(hosts, jobs=[], wide=False, header=True, file=sys.stdout): """Print a list of hosts.""" if len(hosts) == 0: return sumhosts = not isinstance(hosts[0]["status"], str) jobsbyhost = groupjobs(jobs, "exec_host") # begin output screencols = int(check_output(["tput", "cols"])) whoami = os.getenv("USER") namelen = max(map(len, (host["host_name"] for host in hosts))) lens = { "host_name": min(20, max(6, namelen + 1)), "status": 8, "title": 15, "cpus": 10 } if wide: lens["title"] = 20 lens["host_name"] = max(6, namelen + 1) lens["model"] = 14 if sumhosts: lens["status"] = 12 lens["cpus"] = 14 if header: h = "" if sumhosts and "title" in hosts[0]: h += "group".ljust(lens["title"]) h += "".join(n.ljust(lens[n]) for n in ("host_name", "status", "cpus")) h += "mem (free/total)" if wide: h += " " + "model".ljust(lens["model"]) h = h.upper() print(h, file=file) for host in hosts: l = "" if sumhosts and "title" in host: # title title = host["title"] if not wide: if len(title) >= lens["title"]: title = title[:lens["title"] - 2] + "*" l += color(title.ljust(lens["title"]), "b") # host_name l += host["host_name"].ljust(lens["host_name"]) # status if sumhosts: l += color("%3d " % host["status"]["ok"], "g") closed = sum(n for stat, n in host["status"].iteritems() if stat.startswith("closed_")) l += color("%3d " % closed, "r") other = len(host["host_names"]) - host["status"]["ok"] - closed if other: l += color("%3d " % other, "y") else: l += " " else: if host["status"] == "ok": l += color("ok".ljust(lens["status"]), "g") elif "closed_" in host["status"]: l += color(host["status"][7:].ljust(lens["status"]), "r") else: l += color(host["status"].ljust(lens["status"]), "y") # cpus total = host["max"] used = host["njobs"] free = total - used c = fractioncolor(free, total) if sumhosts: l += color("%4d" % free, c) + "/%4d" % total else: l += color("%2d" % free, c) + "/%2d" % total # mem if "mem" in host["load"]: free, used = host["load"]["mem"] total = free if used: # used can be None total += used if "maxmem" in host and host["maxmem"]: total = host["maxmem"] c = fractioncolor(free, total) l += " " + format_mem(free, c) + "/" + format_mem(total) if wide: if sumhosts: if len(host["model"]) == 1: l += host["model"][0].ljust(lens["model"]) else: nmodel = len(host["model"]) l += color((" %d" % nmodel).ljust(lens["model"]), "b") else: hoststr = host["model"] # Xeon Phi(s) phis = 0 if "mic0" in host["load"]: phis += int(bool(host["load"]["mic0"][0])) phis += int(bool(host["load"]["mic0"][1])) if "mic1" in host["load"]: phis += int(bool(host["load"]["mic1"][0])) phis += int(bool(host["load"]["mic1"][1])) if phis > 0: hoststr += "+%dPhi" % phis # GPU if "gpu" in host["resources"]: hoststr += "+GPU" l += " " + hoststr.ljust(14) l += " " if host["rsv"] > 0: l += " %3d*" % host["rsv"] + color("reserved", "y") if sumhosts: hostnames = host["host_names"] else: hostnames = [host["host_name"]] jobs = [] for hostname in hostnames: if hostname in jobsbyhost: for job in jobsbyhost[hostname]: if job not in jobs: jobs.append(job) if sumhosts: jobgroups = groupjobs(jobs, "user") jobs = [] for user in sorted(jobgroups.keys()): jobs.append(sumjobs(jobgroups[user])) if jobs: for job in jobs: exclusive = job["exclusive"] if sumhosts: exclusive = len(exclusive) == 1 and True in exclusive times = color("x", "r") if exclusive else "*" nslots = sum(job["exec_host"][hn] for hn in hostnames if hn in job["exec_host"]) c = "r" if nslots >= 100 else "y" if nslots >= 20 else 0 l += color(" %3d" % nslots, c) user = job["user"] if sumhosts: user = user.keys()[0] c = "g" if user == whoami else 0 l += times + color(getuseralias(user).ljust(8), c) if wide and not sumhosts: if job["mem"]: l += format_mem(job["mem"]) else: l += " " if job["%complete"] and job["runlimit"]: ptime = job["%complete"] c = fractioncolor(1 - ptime / 100) l += color("%3d" % ptime, c) + "% " l += format_duration(job["runlimit"]) if host["comment"]: if sumhosts: for key, val in host["comment"].iteritems(): if key: l += " %3dx" % val + color(key, "b") else: l += " " + color(host["comment"], "b") print(l, file=file) file.flush()