@@ -994,6 +994,12 @@ def process_sacct_filter(args, sacct_filter):
994
994
# Set for completed jobs.
995
995
if getattr (args , 'completed' , None ):
996
996
sacct_filter [:0 ] = ['--endtime=now' , f'--state={ COMPLETED_STATES } ' ]
997
+ if getattr (args , 'user' , None ):
998
+ sacct_filter [:0 ] = [f'--user={ args .user } ' ]
999
+ # Set args.user to None. We have already handled it here and
1000
+ # it shouldn't be re-handled in the future SQL code (future
1001
+ # SQL woludn't handle multiple users, for example).
1002
+ args .user = None
997
1003
return sacct_filter
998
1004
999
1005
def import_or_open_db (args , sacct_filter , csv_input = None ):
@@ -1006,17 +1012,17 @@ def import_or_open_db(args, sacct_filter, csv_input=None):
1006
1012
db: filename of a database to open
1007
1013
1008
1014
"""
1009
- sacct_filter = process_sacct_filter (args , sacct_filter )
1010
-
1011
- LOG .debug (f'sacct args: { sacct_filter } ' )
1012
1015
if args .db :
1013
1016
db = sqlite3 .connect (args .db )
1014
1017
if sacct_filter :
1015
1018
LOG .warn ("Warning: reading from database. Any sacct filters are ignored." )
1016
1019
else :
1017
- db = sqlite3 .connect (':memory:' )
1018
- errors = slurm2sql (db , sacct_filter = sacct_filter ,
1019
- csv_input = getattr (args , 'csv_input' , False ) or csv_input )
1020
+ # Import fresh
1021
+ sacct_filter = process_sacct_filter (args , sacct_filter )
1022
+ LOG .debug (f'sacct args: { sacct_filter } ' )
1023
+ db = sqlite3 .connect (':memory:' )
1024
+ errors = slurm2sql (db , sacct_filter = sacct_filter ,
1025
+ csv_input = getattr (args , 'csv_input' , False ) or csv_input )
1020
1026
return db
1021
1027
1022
1028
@@ -1093,6 +1099,7 @@ def sacct_cli(argv=sys.argv[1:], csv_input=None):
1093
1099
help = "SQL order by (arbitrary SQL expression using column names). NOT safe from SQL injection." )
1094
1100
parser .add_argument ('--completed' , '-c' , action = 'store_true' ,
1095
1101
help = f"Select for completed job states ({ COMPLETED_STATES } ) You need to specify --starttime (-S) at some point in the past, due to how saccont default works (for example '-S now-1week'). This option automatically sets '-E now'" )
1102
+ parser .add_argument ('--user' , '-u' , help = "Limit to this or these users. This specific argument will work with --db, if it's a single user." )
1096
1103
parser .add_argument ('--csv-input' ,
1097
1104
help = "Don't parse sacct but import this CSV file. It's read with "
1098
1105
"Python's default csv reader (excel format). Beware badly "
@@ -1113,9 +1120,14 @@ def sacct_cli(argv=sys.argv[1:], csv_input=None):
1113
1120
1114
1121
db = import_or_open_db (args , sacct_filter , csv_input = csv_input )
1115
1122
1116
- from tabulate import tabulate
1123
+ # If we run sacct, then args.user is set to None so we don't do double filtering here
1124
+ if args .user :
1125
+ where_user = "WHERE user=:user"
1126
+ else :
1127
+ where_user = ''
1117
1128
1118
- cur = db .execute (f'select { args .output } from slurm' )
1129
+ from tabulate import tabulate
1130
+ cur = db .execute (f'select { args .output } from slurm { where_user } ' , {'user' :args .user })
1119
1131
headers = [ x [0 ] for x in cur .description ]
1120
1132
print (tabulate (cur , headers = headers , tablefmt = args .format ))
1121
1133
@@ -1151,6 +1163,7 @@ def seff_cli(argv=sys.argv[1:], csv_input=None):
1151
1163
help = "SQL order by (arbitrary SQL expression using column names). NOT safe from SQL injection." )
1152
1164
parser .add_argument ('--completed' , '-c' , action = 'store_true' ,
1153
1165
help = f"Select for completed job states ({ COMPLETED_STATES } ) You need to specify --starttime (-S) at some point in the past, due to how saccont default works (for example '-S now-1week'). This option automatically sets '-E now'." )
1166
+ parser .add_argument ('--user' , '-u' , help = "Limit to this or these users. This specific argument will work with --db, if it's a single user." )
1154
1167
parser .add_argument ('--csv-input' ,
1155
1168
help = "Don't parse sacct but import this CSV file. It's read with "
1156
1169
"Python's default csv reader (excel format). Beware badly "
@@ -1172,6 +1185,13 @@ def seff_cli(argv=sys.argv[1:], csv_input=None):
1172
1185
else :
1173
1186
order_by = ''
1174
1187
1188
+ # If we run sacct, then args.user is set to None so we don't do double filtering here
1189
+ if args .user :
1190
+ where_user = "and user=:user"
1191
+ else :
1192
+ where_user = ''
1193
+
1194
+
1175
1195
db = import_or_open_db (args , sacct_filter , csv_input = csv_input )
1176
1196
1177
1197
from tabulate import tabulate
@@ -1194,9 +1214,9 @@ def seff_cli(argv=sys.argv[1:], csv_input=None):
1194
1214
round(sum(TotDiskWrite/1048576)/sum(Elapsed),2) AS write_MiBps
1195
1215
1196
1216
FROM eff
1197
- WHERE End IS NOT NULL
1217
+ WHERE End IS NOT NULL { where_user }
1198
1218
GROUP BY user ) { order_by }
1199
- """ )
1219
+ """ , { 'user' : args . user } )
1200
1220
headers = [ x [0 ] for x in cur .description ]
1201
1221
data = cur .fetchall ()
1202
1222
if len (data ) == 0 :
@@ -1225,7 +1245,7 @@ def seff_cli(argv=sys.argv[1:], csv_input=None):
1225
1245
round(TotDiskWrite/Elapsed/1048576,2) AS write_MiBps
1226
1246
1227
1247
FROM eff
1228
- WHERE End IS NOT NULL ) { order_by } """ )
1248
+ WHERE End IS NOT NULL { where_user } ) { order_by } """ , { 'user' : args . user } )
1229
1249
headers = [ x [0 ] for x in cur .description ]
1230
1250
data = cur .fetchall ()
1231
1251
if len (data ) == 0 :
0 commit comments