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

Source Code for Module omero.plugins.submit

 1  #!/usr/bin/env python 
 2  """ 
 3     submit plugin 
 4   
 5     Plugin read by omero.cli.Cli during initialization. The method(s) 
 6     defined here will be added to the Cli class for later use. 
 7   
 8     Copyright 2007 Glencoe Software, Inc. All rights reserved. 
 9     Use is subject to license terms supplied in LICENSE.txt 
10   
11  """ 
12   
13  from omero.cli import BaseControl, CLI 
14  import cmd, sys, exceptions 
15  import sys 
16   
17  prompt = "omero submit [%s]> " 
18   
19 -class Save(exceptions.Exception):
20 pass
21
22 -class Cancel(exceptions.Exception):
23 pass
24
25 -class SubmitCLI(CLI):
26
27 - def __init__(self):
28 CLI.__init__(self) 29 self.queue = [] 30 self.prompt = prompt % str(0)
31
32 - def postcmd(self, stop, line):
33 self.queue.append(line) 34 self.prompt = prompt % str(len(self.queue)) 35 return CLI.postcmd(self, stop, line)
36
37 - def do_save(self, arg):
38 raise Save()
39
40 - def do_cancel(self, arg):
41 raise Cancel()
42
43 - def post_process(self):
44 print "Uploading" 45 print submit.queue
46 47 HELP = """When run without arguments, submit shell is opened 48 which takes commands without executing them. On save, 49 the file is trasferred to the server, and executed.""" 50
51 -class SubmitControl(BaseControl):
52
53 - def _configure(self, parser):
54 parser.add_argument("arg", nargs="*", help="single command with args") 55 parser.set_defaults(func=self.__call__)
56
57 - def __call__(self, args):
58 submit = SubmitCLI() 59 arg = args.arg 60 if arg and len(arg) > 0: 61 submit.invoke(arg) 62 submit.post_process() 63 else: 64 try: 65 submit.invokeloop() 66 except Save, s: 67 submit.execute() 68 except Cancel, c: 69 l = len(submit.queue) 70 if l > 0: 71 print l," items queued. Really cancel? [Yn]"
72 73 try: 74 # register("submit", SubmitControl, HELP) 75 pass 76 except NameError: 77 if __name__ == "__main__": 78 cli = CLI() 79 cli.register("submit", SubmitControl, HELP) 80 cli.invoke(sys.argv[1:]) 81