Skip to content

Commit a45f628

Browse files
authored
Merge pull request #4 from vanderwb/subjob-support
Add proper support for array flags
2 parents 4c58daa + d5d54be commit a45f628

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ Options:
3030
-f display full output for a job
3131
-Fjson display full output in JSON format (use with -f)
3232
-H job output regardless of state or all finished jobs
33+
-J only show information for jobs (or subjobs with -t)
3334
-l disable labels (no header)
3435
-n display a list of nodes at the end of the line
3536
-s display administrator comment on the next line
3637
--status filter jobs by specific single-character status code
38+
-t show information for both jobs and array subjobs
3739
-u filter jobs by the submitting user
3840
-w use wide format output (120 columns)
3941
-x include recently finished jobs in output

gen_data.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ function main_gen {
6060

6161
# Get data from PBS
6262
QSS_TIME=$SECONDS
63-
$PBSPREFIX $QSTATBIN -x | sed '/^[0-9]/,$!d' | sed 's/\([0-9]\+\) b/ \1b/' > newlist-default.dat &
64-
$PBSPREFIX $QSTATBIN -1 -n -s -x | sed '/^[0-9]/,$!d' | sed 's/\([0-9]\+\) b/ \1b/' > newlist-info.dat &
65-
$PBSPREFIX $QSTATBIN -a -1 -n -s -w -x | sed '/^[0-9]/,$!d' | sed 's/\([0-9]\+\) b/ \1b/' > newlist-wide.dat &
63+
$PBSPREFIX $QSTATBIN -t -x | sed '/^[0-9]/,$!d' | sed 's/\([0-9]\+\) b/ \1b/' > newlist-default.dat &
64+
$PBSPREFIX $QSTATBIN -t -1 -n -s -x | sed '/^[0-9]/,$!d' | sed 's/\([0-9]\+\) b/ \1b/' > newlist-info.dat &
65+
$PBSPREFIX $QSTATBIN -t -a -1 -n -s -w -x | sed '/^[0-9]/,$!d' | sed 's/\([0-9]\+\) b/ \1b/' > newlist-wide.dat &
6666

6767
if [[ " $CACHEFLAGS " == *" f "* ]]; then
68-
$PBSPREFIX $QSTATBIN -f > joblist-full.dat &
68+
$PBSPREFIX $QSTATBIN -t -f > joblist-full.dat &
6969
else
7070
rm -f joblist-full.dat
7171
fi
@@ -75,7 +75,7 @@ function main_gen {
7575
# 1. Numbers after a number 0 (octal) that aren't strings
7676
# 2. Trailing decimal points in numbers
7777
# 3. Numbers that begin with a decimal point
78-
$PBSPREFIX $QSTATBIN -f -F json | sed 's/":\(0[0-9][^,]*\)/":"\1"/; s/":\([0-9]*\)\.,/":"\1\.",/; s/":\(\.[^,]*\)/":"\1"/' > joblist-fulljson.dat &
78+
$PBSPREFIX $QSTATBIN -t -f -F json | sed 's/":\(0[0-9][^,]*\)/":"\1"/; s/":\([0-9]*\)\.,/":"\1\.",/; s/":\(\.[^,]*\)/":"\1"/' > joblist-fulljson.dat &
7979
else
8080
rm -f joblist-fulljson.dat
8181
fi

qstat

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ Options:
2121
-f display full output for a job
2222
-Fjson display full output in JSON format (use with -f)
2323
-H job output regardless of state or all finished jobs
24+
-J only show information for jobs (or subjobs with -t)
2425
-l disable labels (no header)
2526
-n display a list of nodes at the end of the line
2627
-s display administrator comment on the next line
2728
--status filter jobs by specific single-character status code
29+
-t show information for both jobs and array subjobs
2830
-u filter jobs by the submitting user
2931
-w use wide format output (120 columns)
3032
-x include recently finished jobs in output
@@ -241,6 +243,10 @@ while [[ $# -gt 0 ]]; do
241243
HMODE=true
242244
DATAFILE=${DATAFILE/default/info}
243245
;;
246+
J)
247+
JMODE=true
248+
JSOPTS="-J $JSOPTS"
249+
;;
244250
l)
245251
NOLABELS=true
246252
;;
@@ -253,6 +259,10 @@ while [[ $# -gt 0 ]]; do
253259
DATAFILE=${DATAFILE/job/comm}
254260
DATAFILE=${DATAFILE/default/info}
255261
;;
262+
t)
263+
SUBJOBS=true
264+
JSOPTS="-t $JSOPTS"
265+
;;
256266
u)
257267
DATAFILE=${DATAFILE/default/info}
258268

@@ -288,7 +298,11 @@ while [[ $# -gt 0 ]]; do
288298
find_server
289299
;;&
290300
[0-9]*)
291-
JOBID=${1%%@*}
301+
if [[ $1 == *\[[0-9]*\]* ]]; then
302+
JOBID=$(sed 's/\[/\\\[/; s/\]/\\\]/' <<< ${1%%@*})
303+
else
304+
JOBID=$(sed 's/\[\]/\\[\[0-9\]\*\\]/' <<< ${1%%@*})
305+
fi
292306

293307
if [[ -z $CUSTOMSERVER ]] && [[ $JOBID == *.* ]]; then
294308
CUSTOMSERVER=${JOBID#*.} find_server
@@ -358,7 +372,7 @@ if [[ $FULLMODE == true ]]; then
358372
DATAFILE=joblist-fulljson.dat
359373

360374
if [[ -n $JOBLIST ]]; then
361-
JSOPTS="-j $JOBLIST"
375+
JSOPTS="$JSOPTS -j $JOBLIST"
362376
else
363377
if [[ -n $DESTLIST ]]; then
364378
JSOPTS="$JSOPTS -q $DESTLIST"
@@ -397,7 +411,7 @@ if [[ $FULLMODE == true ]]; then
397411
fi
398412

399413
if [[ -n $JOBLIST ]]; then
400-
CMD="awk -vRS='' '/Job Id: ($JOBLIST)./{print \$0\"\n\"}' $DATAPATH/$DATAFILE"
414+
CMD="awk -vRS='' '/Job Id: ($JOBLIST)\./{print \$0\"\n\"}' $DATAPATH/$DATAFILE"
401415
else
402416
if [[ $SHOWALL == true ]]; then
403417
CMD="cat $DATAPATH/$DATAFILE"
@@ -414,6 +428,14 @@ if [[ $FULLMODE == true ]]; then
414428
CMD="$CMD | awk -vRS='' '/job_state = $STATCODE/{print \$0\"\n\"}'"
415429
fi
416430

431+
if [[ $SUBJOBS == true ]]; then
432+
if [[ $JMODE == true ]]; then
433+
CMD="$CMD | awk -vRS='' '/Job Id:.*\[[0-9]+\]/{print \$0\"\n\"}'"
434+
fi
435+
else
436+
CMD="$CMD | awk -vRS='' '!/Job Id:.*\[[0-9]+\]/{print \$0\"\n\"}'"
437+
fi
438+
417439
# Get requested output
418440
query_cache
419441

@@ -453,19 +475,32 @@ else
453475
# Attach various filters to output
454476
if [[ ! -z "$STATCODE" ]]; then
455477
CMD="$CMD | awk '\$$SCOL && \$$SCOL $COPER \"$STATCODE\" && \$1 ~ /^[0-9]/ { $AWKOPT }'"
478+
AWKOPT=print
456479
fi
457480

458481
if [[ ! -z "$USERSTR" ]] && [[ ${USERSTR^^} != ALL ]]; then
459482
CMD="$CMD | awk '\$$UCOL == \"$USERSTR\" { $AWKOPT }'"
483+
AWKOPT=print
460484
fi
461485

462486
if [[ ! -z "$JOBLIST" ]]; then
463-
JOBLIST=${JOBLIST/\[\]/\\\[\\\]}
464487
CMD="$CMD | awk '\$1 ~ /^($JOBLIST)\./ { $AWKOPT }'"
488+
AWKOPT=print
465489
fi
466490

467491
if [[ ! -z "$DESTLIST" ]]; then
468492
CMD="$CMD | awk '\$$DCOL ~ /^($DESTLIST)$/ { $AWKOPT }'"
493+
AWKOPT=print
494+
fi
495+
496+
if [[ $SUBJOBS == true ]]; then
497+
if [[ $JMODE == true ]]; then
498+
CMD="$CMD | awk '\$1 ~ /\[[0-9]+\]/ { $AWKOPT }'"
499+
AWKOPT=print
500+
fi
501+
else
502+
CMD="$CMD | awk '\$1 !~ /\[[0-9]+\]/ { $AWKOPT }'"
503+
AWKOPT=print
469504
fi
470505

471506
# Get requested output

qstat-json.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
#!/usr/bin/env python3
22

3-
import json, collections, argparse, sys
3+
import json, collections, argparse, sys, re
44

55
from signal import signal, SIGPIPE, SIG_DFL
66
signal(SIGPIPE,SIG_DFL)
77

88
parser = argparse.ArgumentParser()
99
parser.add_argument("input_file")
1010
parser.add_argument("--jobs", "-j", nargs='*')
11+
parser.add_argument("--filter", "-J", action = "store_true")
1112
parser.add_argument("--queues", "-q", nargs='*')
1213
parser.add_argument("--status", "-s")
14+
parser.add_argument("--arrays", "-t", action = "store_true")
1315
parser.add_argument("--user", "-u")
1416
args = parser.parse_args()
1517

1618
with open(args.input_file, 'r') as f:
1719
try:
18-
data = json.load(f, object_pairs_hook=collections.OrderedDict)
20+
data = json.load(f, object_pairs_hook=collections.OrderedDict, strict = False)
1921
except json.decoder.JSONDecodeError:
2022
sys.exit(3)
2123

@@ -25,9 +27,12 @@
2527
if "." in job:
2628
jobs.append(job)
2729
else:
28-
jobs.append("{}.".format(job))
30+
jobs.append("{}\.".format(job))
2931

30-
data['Jobs'] = { job : data['Jobs'][job] for job in data['Jobs'].keys() if job.startswith(tuple(jobs)) }
32+
try:
33+
data['Jobs'] = { job : data['Jobs'][job] for job in data['Jobs'].keys() if any([re.match(jid, job) for jid in jobs]) }
34+
except:
35+
sys.exit(3)
3136

3237
if args.queues:
3338
data['Jobs'] = { job : data['Jobs'][job] for job in data['Jobs'].keys() if data['Jobs'][job]['queue'] in args.queues }
@@ -38,4 +43,10 @@
3843
if args.status:
3944
data['Jobs'] = { job : data['Jobs'][job] for job in data['Jobs'].keys() if data['Jobs'][job]['job_state'] == args.status }
4045

46+
if args.arrays:
47+
if args.filter:
48+
data['Jobs'] = { job : data['Jobs'][job] for job in data['Jobs'].keys() if re.search("\[[0-9]+\]", job) }
49+
else:
50+
data['Jobs'] = { job : data['Jobs'][job] for job in data['Jobs'].keys() if not re.search("\[[0-9]+\]", job) }
51+
4152
print(json.dumps(data, indent = 4))

0 commit comments

Comments
 (0)