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 Arguments, BaseControl, VERSION, OMERODIR 
 16   
17 -class DeleteControl(BaseControl):
18
19 - def _run(self, args = []):
20 args = Arguments(args) 21 22 from getopt import getopt, GetoptError 23 try: 24 options, args = getopt(args.args, "s:u:k:w:p:h") 25 if len(options) == 0 and len(args) == 0: 26 raise GetoptError("No arguments") 27 except GetoptError, (msg, opt): 28 self.help("Bad arguments") 29 self.ctx.die(0, "") 30 31 server = None 32 user = None 33 port = 4063 34 pasw = None 35 key = None 36 for option, argument in options: 37 if option == "-u": 38 user = argument 39 elif option == "-w": 40 pasw = argument 41 elif option == "-s": 42 server = argument 43 elif option == "-p": 44 port = int(argument) 45 elif option == "-k": 46 key = argument 47 else: 48 self.ctx.out("Ignoring option: %s" % option) 49 50 if server is None: 51 server = self.ctx.input("Server:") 52 if key: 53 user = key 54 pasw = key 55 else: 56 if file is None and pasw is None: 57 self.ctx.die(3, "Password or key must be provided to send to stdout") 58 if user is None and key is None: 59 user = self.ctx.input("Username:") 60 if pasw is None and key is None: 61 pasw = self.ctx.input("Password:", hidden = True) 62 63 import omero.clients 64 images = [] 65 plates = [] 66 for arg in args: 67 klass, id = arg.split(":") 68 if klass == "Image": 69 images.append(long(id)) 70 elif klass == "Plate": 71 plates.append(long(id)) 72 else: 73 self.ctx.die(5, "Can't add type: %s" % klass) 74 75 c = self.ctx.conn({"omero.host":server, "omero.user":user,"omero.pass":pasw}) 76 e = None 77 78 def action(klass, method, *args): 79 self.ctx.out("Deleting %s %s..." % (klass, args), newline = False) 80 try: 81 method(*args) 82 self.ctx.out("ok.") 83 except exceptions.Exception, e: 84 self.ctx.out("failed (%s)" % e)
85 86 try: 87 deleteSrv = c.getSession().getDeleteService() 88 for image in images: action("Image", deleteSrv.deleteImage, image, True) 89 for plate in plates: action("Plate", deleteSrv.deletePlate, plate) 90 finally: 91 c.closeSession() # FIXME
92
93 - def help(self, args = None):
94 self.ctx.out(""" 95 Usage: %s delete [OPTION]... Image:<id> Plate:<id> ... 96 Delete OMERO data 97 98 Queried arguments: (if not provided, requires user input) 99 -s OMERO server hostname 100 -u OMERO experimenter name (username) 101 -k OMERO session key (can be used in place of -u and -w) 102 -w OMERO experimenter password (Requested if not provided) 103 104 Optional arguments: 105 -p OMERO server port [defaults to 4063] 106 -h Display this help and exit 107 108 ex. %s delete -s localhost -u bart -w simpson Image:50 109 110 Report bugs to <ome-users@openmicroscopy.org.uk>""" % (sys.argv[0], sys.argv[0]))
111
112 - def __call__(self, *args):
113 args = Arguments(*args) 114 self._run(args)
115 116 try: 117 register("delete", DeleteControl) 118 except NameError: 119 DeleteControl()._main() 120