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

Source Code for Module omero.plugins.submit

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