3434
3535from omero_ext .argparse import SUPPRESS
3636from omero .cli import BaseControl , CLI , ExceptionHandler
37- from omero .rtypes import rlong
37+ from omero .rtypes import rlong , unwrap
3838
3939
4040class TxField (object ):
@@ -278,6 +278,76 @@ def save_and_return(self, ctx):
278278 self .tx_state .set_value (proxy , dest = self .tx_cmd .dest )
279279
280280
281+ class ExtInfoSetTxAction (NonFieldTxAction ):
282+
283+ def on_go (self , ctx , args ):
284+ # ['ext-info-set', 'Project:302', 'lsid', 'entityType', 'entityId']
285+ argc = len (self .tx_cmd .arg_list )
286+ if argc not in [4 , 5 , 6 ]:
287+ ctx .die (345 ,
288+ "usage: ext-info-set OBJ entityId entityType [lsid] [uuid]" )
289+ try :
290+ entity_id = int (self .tx_cmd .arg_list [2 ])
291+ except ValueError :
292+ ctx .die (347 , "entityId must be an integer, got: %s" %
293+ self .tx_cmd .arg_list [2 ])
294+ entity_type = self .tx_cmd .arg_list [3 ]
295+
296+ details = self .obj .getDetails ()
297+ extinfo_id = None
298+ # if externalInfo exists, delete affer replacing below...
299+ if details and details ._externalInfo :
300+ extinfo_id = details ._externalInfo ._id .val
301+
302+ from omero .model import ExternalInfoI
303+ from omero .rtypes import rstring , rlong
304+
305+ extinfo = ExternalInfoI ()
306+ # non-nullable properties
307+ setattr (extinfo , "entityId" , rlong (entity_id ))
308+ setattr (extinfo , "entityType" , rstring (entity_type ))
309+ # nullable properties
310+ if argc > 4 :
311+ lsid = self .tx_cmd .arg_list [4 ]
312+ setattr (extinfo , "lsid" , rstring (lsid ))
313+ if argc == 6 :
314+ uuid = self .tx_cmd .arg_list [5 ]
315+ setattr (extinfo , "uuid" , rstring (uuid ))
316+
317+ self .obj .details .externalInfo = extinfo
318+ self .save_and_return (ctx )
319+
320+ if extinfo_id is not None :
321+ self .update .deleteObject (ExternalInfoI (extinfo_id , False ))
322+
323+
324+ class ExtInfoGetTxAction (NonFieldTxAction ):
325+
326+ def on_go (self , ctx , args ):
327+ details = self .obj .getDetails ()
328+ extinfo = None
329+ if details and details ._externalInfo :
330+ extinfo = self .query .get ("ExternalInfo" ,
331+ details ._externalInfo ._id .val , {"omero.group" : "-1" })
332+
333+ if extinfo is None :
334+ obj , kls = self .instance (ctx )
335+ ctx .die (346 , f"No ExternalInfo found: { kls } :{ obj .id .val } " )
336+
337+ attr_list = ["id" , "entityId" , "entityType" , "lsid" , "uuid" ]
338+ proxy = ""
339+ if len (self .tx_cmd .arg_list ) == 3 :
340+ field = self .tx_cmd .arg_list [2 ]
341+ if field not in attr_list :
342+ ctx .die (335 , f"usage: ext-info-get OBJ [{ '|' .join (attr_list )} ]" )
343+ value = getattr (extinfo , field ) or ""
344+ proxy += f"{ unwrap (value )} "
345+ else :
346+ for field in attr_list :
347+ value = getattr (extinfo , field ) or ""
348+ proxy += f"{ field } ={ unwrap (value )} \n "
349+ self .tx_state .set_value (proxy , dest = self .tx_cmd .dest )
350+
281351class MapSetTxAction (NonFieldTxAction ):
282352
283353 def on_go (self , ctx , args ):
@@ -526,6 +596,11 @@ class ObjControl(BaseControl):
526596 $ omero obj list-get MapAnnotation:456 mapValue 0
527597 (foo,bar)
528598
599+ $ omero obj ext-info-set Image:12 3 myEntityType myLsid
600+ $ omero obj ext-info-set Image:12 3 myEntityType myLsid myUuid
601+ $ omero obj ext-info-get Image:12
602+ $ omero obj ext-info-get Image:12 entityType
603+
529604Bash examples:
530605
531606 $ project=$(omero obj new Project name='my Project')
@@ -546,7 +621,8 @@ def _configure(self, parser):
546621 "command" , nargs = "?" ,
547622 choices = ("new" , "update" , "null" ,
548623 "map-get" , "map-set" ,
549- "get" , "list-get" ),
624+ "get" , "list-get" ,
625+ "ext-info-get" , "ext-info-set" ),
550626 help = "operation to be performed" )
551627 parser .add_argument (
552628 "Class" , nargs = "?" ,
@@ -603,6 +679,10 @@ def parse(self, tx_state, arg_list=None, line=None):
603679 return MapSetTxAction (tx_state , tx_cmd )
604680 elif tx_cmd .action == "map-get" :
605681 return MapGetTxAction (tx_state , tx_cmd )
682+ elif tx_cmd .action == "ext-info-set" :
683+ return ExtInfoSetTxAction (tx_state , tx_cmd )
684+ elif tx_cmd .action == "ext-info-get" :
685+ return ExtInfoGetTxAction (tx_state , tx_cmd )
606686 elif tx_cmd .action == "null" :
607687 return NullTxAction (tx_state , tx_cmd )
608688 elif tx_cmd .action == "get" :
0 commit comments