@@ -5,7 +5,7 @@ class Job():
5
5
6
6
def __init__ (self ,
7
7
client ,
8
- job_dict = None ):
8
+ job_dict = None ):
9
9
10
10
self .client = client
11
11
@@ -36,11 +36,11 @@ def __init__(self,
36
36
self .attached_directories_dict = None
37
37
38
38
self .refresh_from_dict (
39
- job_dict = job_dict )
39
+ job_dict = job_dict )
40
40
41
41
def refresh_from_dict (
42
42
self ,
43
- job_dict = None ):
43
+ job_dict = None ):
44
44
45
45
if not job_dict :
46
46
return
@@ -51,7 +51,7 @@ def refresh_from_dict(
51
51
def __repr__ (self ):
52
52
return str (self .serialize ())
53
53
54
- def __add_directory_to_job (self , directory : Directory , mode = 'sync' ):
54
+ def __add_directory_to_job (self , directory : Directory , mode = 'sync' ):
55
55
"""
56
56
57
57
:param directories: Array of directories Objects
@@ -67,7 +67,7 @@ def __add_directory_to_job(self, directory: Directory, mode='sync'):
67
67
)
68
68
return self .attached_directories
69
69
70
- def attach_directories (self , directories , mode = 'sync' , override_existing = False ):
70
+ def attach_directories (self , directories , mode = 'sync' , override_existing = False ):
71
71
"""
72
72
Attaches directories to a job.
73
73
:param directories: Array of directories Objects
@@ -96,7 +96,7 @@ def attach_directories(self, directories, mode='sync', override_existing=False):
96
96
data ['job_id' ] = self .id
97
97
response = self .client .session .post (
98
98
self .client .host + endpoint ,
99
- json = data )
99
+ json = data )
100
100
101
101
self .client .handle_errors (response )
102
102
@@ -139,23 +139,23 @@ def serialize(self):
139
139
}
140
140
141
141
def new (self ,
142
- name = None ,
143
- instance_type = None ,
144
- share = "project" ,
145
- job_type = "Normal" ,
142
+ name = None ,
143
+ instance_type = None ,
144
+ share = "project" ,
145
+ job_type = "Normal" ,
146
146
label_schema_id = None ,
147
- permission = None ,
148
- field = None ,
149
- category = None ,
150
- review_by_human_freqeuncy = None ,
151
- label_mode = None ,
152
- passes_per_file = None ,
153
- guide = None ,
154
- launch_datetime = None ,
155
- sync_directories = [],
156
- single_copy_directories = [],
147
+ permission = None ,
148
+ field = None ,
149
+ category = None ,
150
+ review_by_human_freqeuncy = None ,
151
+ label_mode = None ,
152
+ passes_per_file = None ,
153
+ guide = None ,
154
+ launch_datetime = None ,
155
+ sync_directories = [],
156
+ single_copy_directories = [],
157
157
members_list_ids = [],
158
- auto_launch = True ,
158
+ auto_launch = True ,
159
159
tag_list = [],
160
160
):
161
161
"""
@@ -174,7 +174,7 @@ def new(self,
174
174
# QUESTION create job object eariler instead of after response?
175
175
if len (members_list_ids ) == 0 :
176
176
raise ValueError ('Please provide at least one member_id in members_list_ids.' )
177
- job = Job (client = self .client )
177
+ job = Job (client = self .client )
178
178
179
179
if label_schema_id is None :
180
180
if self .client .label_schema_list :
@@ -201,10 +201,10 @@ def new(self,
201
201
'Please provide at least one attached directory to the job in either sync_directories param or single_copy_directories' )
202
202
203
203
for dir in sync_directories :
204
- job .__add_directory_to_job (directory = dir , mode = 'sync' )
204
+ job .__add_directory_to_job (directory = dir , mode = 'sync' )
205
205
206
206
for dir in single_copy_directories :
207
- job .__add_directory_to_job (directory = dir , mode = 'sync' )
207
+ job .__add_directory_to_job (directory = dir , mode = 'sync' )
208
208
209
209
job .attached_directories_dict = {
210
210
'attached_directories_list' : job .attached_directories
@@ -214,7 +214,7 @@ def new(self,
214
214
215
215
response = self .client .session .post (
216
216
self .client .host + endpoint ,
217
- json = job .serialize ())
217
+ json = job .serialize ())
218
218
219
219
self .client .handle_errors (response )
220
220
@@ -225,7 +225,7 @@ def new(self,
225
225
job .id = data ["job" ]["id" ]
226
226
227
227
if guide :
228
- job .guide_update (guide = guide )
228
+ job .guide_update (guide = guide )
229
229
230
230
if auto_launch :
231
231
endpoint_launch = "/api/v1/job/launch" .format (self .client .project_string_id )
@@ -236,35 +236,42 @@ def new(self,
236
236
})
237
237
self .client .handle_errors (response )
238
238
239
-
240
-
241
239
return job
242
240
243
-
244
- def list ( self ,
245
- limit = 10 ,
246
- status = "All" ):
241
+ def list ( self ,
242
+ limit = 10 ,
243
+ status = "All" ,
244
+ tags = [] ):
247
245
248
246
# Example usage print(project.job.list().json())
249
-
247
+ tag_id_list = None
248
+ if len (tags ) > 0 :
249
+ # fetch tag id list
250
+ tag_path = f'/api/v1/project/{ self .client .project_string_id } /tags/list'
251
+ response_tags = self .client .session .get (self .client .host + tag_path )
252
+ tag_list = response_tags .json ()['tag_list' ]
253
+ tag_id_list = []
254
+ for elm in tag_list :
255
+ if elm ['name' ] in tags :
256
+ tag_id_list .append (elm ['id' ])
250
257
endpoint = "/api/v1/job/list"
251
-
252
- request_json_body = {"metadata" :
258
+ request_json_body = {"metadata" :
253
259
{
254
- "limit" : limit ,
255
- "status" : status ,
256
- "project_string_id" : self .client .project_string_id
260
+ "limit" : limit ,
261
+ "data_mode" : "with_tags" ,
262
+ "status" : status ,
263
+ "tag_list" : tag_id_list ,
264
+ "project_string_id" : self .client .project_string_id
257
265
}
258
266
}
259
267
260
268
response = self .client .session .post (
261
- self .client .host + endpoint ,
262
- json = request_json_body )
269
+ self .client .host + endpoint ,
270
+ json = request_json_body )
263
271
264
272
self .client .handle_errors (response )
265
-
266
- return response
267
-
273
+ result = response .json ()
274
+ return result ['Job_list' ]
268
275
269
276
def launch (
270
277
self
@@ -288,7 +295,7 @@ def launch(
288
295
289
296
response = self .client .session .post (
290
297
self .client .host + endpoint ,
291
- json = request )
298
+ json = request )
292
299
293
300
self .client .handle_errors (response )
294
301
@@ -303,8 +310,8 @@ def launch(
303
310
def guide_update (
304
311
self ,
305
312
guide ,
306
- kind = "default" ,
307
- action = "update"
313
+ kind = "default" ,
314
+ action = "update"
308
315
):
309
316
"""
310
317
@@ -329,7 +336,7 @@ def guide_update(
329
336
'update_or_remove' : action }
330
337
331
338
response = self .client .session .post (self .client .host + endpoint ,
332
- json = update_dict )
339
+ json = update_dict )
333
340
334
341
self .client .handle_errors (response )
335
342
@@ -347,7 +354,7 @@ def get_by_id(
347
354
"""
348
355
"""
349
356
350
- job = Job (client = self .client )
357
+ job = Job (client = self .client )
351
358
job .id = id
352
359
353
360
job .refresh_info ()
@@ -356,13 +363,13 @@ def get_by_id(
356
363
357
364
def generate_export (
358
365
self ,
359
- kind = 'Annotations' ,
360
- return_type = "data" ,
361
- source = "job" ,
362
- masks = False ,
363
- directory_id = None ,
364
- wait_for_export_generation = True ,
365
- ann_is_complete = None # Bool. None=='all', True=='complete' tasks only
366
+ kind = 'Annotations' ,
367
+ return_type = "data" ,
368
+ source = "job" ,
369
+ masks = False ,
370
+ directory_id = None ,
371
+ wait_for_export_generation = True ,
372
+ ann_is_complete = None # Bool. None=='all', True=='complete' tasks only
366
373
):
367
374
"""
368
375
@@ -400,7 +407,7 @@ def generate_export(
400
407
}
401
408
402
409
response = self .client .session .post (self .client .host + endpoint ,
403
- json = spec_dict )
410
+ json = spec_dict )
404
411
405
412
self .client .handle_errors (response )
406
413
@@ -414,7 +421,7 @@ def generate_export(
414
421
415
422
def refresh_info (
416
423
self ,
417
- mode_data = None
424
+ mode_data = None
418
425
):
419
426
"""
420
427
Assumptions
@@ -434,7 +441,7 @@ def refresh_info(
434
441
435
442
response = self .client .session .post (
436
443
self .client .host + endpoint ,
437
- json = spec_dict )
444
+ json = spec_dict )
438
445
439
446
self .client .handle_errors (response )
440
447
@@ -443,4 +450,4 @@ def refresh_info(
443
450
# print(data)
444
451
445
452
self .refresh_from_dict (
446
- job_dict = data ['job' ])
453
+ job_dict = data ['job' ])
0 commit comments