Package omero :: Package plugins :: Module delete
[hide private]
[frames] | no frames]

Source Code for Module omero.plugins.delete

 1  #!/usr/bin/env python 
 2  """ 
 3     Startup plugin for command-line deletes 
 4   
 5     Copyright 2009 Glencoe Software, Inc. All rights reserved. 
 6     Use is subject to license terms supplied in LICENSE.txt 
 7   
 8  """ 
 9   
10  import os 
11  import sys 
12  import array 
13  import exceptions 
14   
15  from omero.cli import BaseControl, CLI 
16   
17  HELP = """Delete OMERO data. 
18   
19  Where available (currently: Image & Plate) special methods 
20  are used for deleting the objects. Otherwise, IUpdate.deleteObject() 
21  is used. 
22   
23   
24  Examples: 
25   
26      bin/omero delete Image:50 
27      bin/omero delete Plate:1 
28   
29  """ 
30   
31 -class DeleteControl(BaseControl):
32
33 - def _configure(self, parser):
34 parser.add_argument("obj", nargs="+", help="""Objects to be deleted in the form "<Classs>:<Id>""") 35 parser.set_defaults(func=self.delete)
36
37 - def delete(self, args):
38 39 import omero 40 client = self.ctx.conn(args) 41 42 images = [] 43 plates = [] 44 objects = [] 45 for arg in args.obj: 46 klass, id = arg.split(":") 47 if klass == "Image": 48 images.append(long(id)) 49 elif klass == "Plate": 50 plates.append(long(id)) 51 else: 52 ctor = getattr(omero.model, "%sI" % klass) 53 if not ctor: 54 ctor = getattr(omero.model, klass) 55 try: 56 objects.append(ctor(long(id), False)) 57 except exceptions.Exception, e: 58 self.ctx.dbg("Exception on ctor: %s" % e) 59 self.ctx.die(5, "Can't delete type: %s" % klass) 60 61 def action(klass, method, *args): 62 import omero 63 self.ctx.out(("Deleting %s %s... " % (klass, args)), newline = False) 64 try: 65 method(*args) 66 self.ctx.out("ok.") 67 except omero.ApiUsageException, aue: 68 self.ctx.out(aue.message) 69 except exceptions.Exception, e: 70 self.ctx.out("failed (%s)" % e)
71 72 deleteSrv = client.getSession().getDeleteService() 73 updateSrv = client.getSession().getUpdateService() 74 for image in images: action("Image", deleteSrv.deleteImage, image, True) 75 for plate in plates: action("Plate", deleteSrv.deletePlate, plate) 76 for object in objects: action(object.__class__.__name__, updateSrv.deleteObject, object)
77 78 try: 79 register("delete", DeleteControl, HELP) 80 except NameError: 81 if __name__ == "__main__": 82 cli = CLI() 83 cli.register("delete", DeleteControl, HELP) 84 cli.invoke(sys.argv[1:]) 85