@@ -147,7 +147,7 @@ def exists(cls, software, name):
147
147
return qdb .sql_connection .TRN .execute_fetchlast ()
148
148
149
149
@classmethod
150
- def create (cls , software , name , description , parameters ):
150
+ def create (cls , software , name , description , parameters , outputs = None ):
151
151
r"""Creates a new command in the system
152
152
153
153
The supported types for the parameters are:
@@ -175,6 +175,9 @@ def create(cls, software, name, description, parameters):
175
175
format is: {parameter_name: (parameter_type, default)},
176
176
where parameter_name, parameter_type and default are strings. If
177
177
default is None.
178
+ outputs : dict, optional
179
+ The description of the outputs that this command generated. The
180
+ format is: {output_name: artifact_type}
178
181
179
182
Returns
180
183
-------
@@ -216,7 +219,7 @@ def create(cls, software, name, description, parameters):
216
219
ptype , dflt = vals
217
220
# Check that the type is one of the supported types
218
221
supported_types = ['string' , 'integer' , 'float' , 'reference' ,
219
- 'boolean' ]
222
+ 'boolean' , 'prep_template' ]
220
223
if ptype not in supported_types and not ptype .startswith (
221
224
('choice' , 'artifact' )):
222
225
supported_types .extend (['choice' , 'artifact' ])
@@ -281,6 +284,17 @@ def create(cls, software, name, description, parameters):
281
284
for at in atypes ]
282
285
qdb .sql_connection .TRN .add (sql_type , sql_params , many = True )
283
286
287
+ # Add the outputs to the command
288
+ if outputs :
289
+ sql = """INSERT INTO qiita.command_output
290
+ (name, command_id, artifact_type_id)
291
+ VALUES (%s, %s, %s)"""
292
+ sql_args = [
293
+ [pname , c_id , qdb .util .convert_to_id (at , 'artifact_type' )]
294
+ for pname , at in outputs .items ()]
295
+ qdb .sql_connection .TRN .add (sql , sql_args , many = True )
296
+ qdb .sql_connection .TRN .execute ()
297
+
284
298
return cls (c_id )
285
299
286
300
@property
@@ -425,6 +439,31 @@ def outputs(self):
425
439
qdb .sql_connection .TRN .add (sql , [self .id ])
426
440
return qdb .sql_connection .TRN .execute_fetchindex ()
427
441
442
+ @property
443
+ def active (self ):
444
+ """Returns if the command is active or not
445
+
446
+ Returns
447
+ -------
448
+ bool
449
+ Whether the command is active or not
450
+ """
451
+ with qdb .sql_connection .TRN :
452
+ sql = """SELECT active
453
+ FROM qiita.software_command
454
+ WHERE command_id = %s"""
455
+ qdb .sql_connection .TRN .add (sql , [self .id ])
456
+ return qdb .sql_connection .TRN .execute_fetchlast ()
457
+
458
+ def activate (self ):
459
+ """Activates the command"""
460
+ with qdb .sql_connection .TRN :
461
+ sql = """UPDATE qiita.software_command
462
+ SET active = %s
463
+ WHERE command_id = %s"""
464
+ qdb .sql_connection .TRN .add (sql , [True , self .id ])
465
+ return qdb .sql_connection .TRN .execute ()
466
+
428
467
429
468
class Software (qdb .base .QiitaObject ):
430
469
r"""A software package available in the system
@@ -456,6 +495,8 @@ def deactivate_all(cls):
456
495
with qdb .sql_connection .TRN :
457
496
sql = "UPDATE qiita.software SET active = False"
458
497
qdb .sql_connection .TRN .add (sql )
498
+ sql = "UPDATE qiita.software_command SET active = False"
499
+ qdb .sql_connection .TRN .add (sql )
459
500
qdb .sql_connection .TRN .execute ()
460
501
461
502
@classmethod
0 commit comments