/components/tools/OmeroPy/src/omero/plugins/submit.py

https://github.com/will-moore/openmicroscopy
Python | 84 lines | 52 code | 19 blank | 13 comment | 10 complexity | 65bf35d141be27fd0004344565567431 MD5 | raw file
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. submit plugin
  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. Copyright 2007 Glencoe Software, Inc. All rights reserved.
  8. Use is subject to license terms supplied in LICENSE.txt
  9. """
  10. from omero.cli import BaseControl, CLI
  11. import sys
  12. prompt = "omero submit [%s]> "
  13. class Save(Exception):
  14. pass
  15. class Cancel(Exception):
  16. pass
  17. class SubmitCLI(CLI):
  18. def __init__(self):
  19. CLI.__init__(self)
  20. self.queue = []
  21. self.prompt = prompt % str(0)
  22. def postcmd(self, stop, line):
  23. self.queue.append(line)
  24. self.prompt = prompt % str(len(self.queue))
  25. return CLI.postcmd(self, stop, line)
  26. def do_save(self, arg):
  27. raise Save()
  28. def do_cancel(self, arg):
  29. raise Cancel()
  30. def post_process(self):
  31. print "Uploading"
  32. print self.queue
  33. HELP = """When run without arguments, submit shell is opened
  34. which takes commands without executing them. On save,
  35. the file is trasferred to the server, and executed."""
  36. class SubmitControl(BaseControl):
  37. def _configure(self, parser):
  38. parser.add_argument("arg", nargs="*", help="single command with args")
  39. parser.set_defaults(func=self.__call__)
  40. def __call__(self, args):
  41. submit = SubmitCLI()
  42. arg = args.arg
  43. if arg and len(arg) > 0:
  44. submit.invoke(arg)
  45. submit.post_process()
  46. else:
  47. try:
  48. submit.invokeloop()
  49. except Save:
  50. submit.execute()
  51. except Cancel:
  52. l = len(submit.queue)
  53. if l > 0:
  54. print l, " items queued. Really cancel? [Yn]"
  55. try:
  56. # register("submit", SubmitControl, HELP)
  57. pass
  58. except NameError:
  59. if __name__ == "__main__":
  60. cli = CLI()
  61. cli.register("submit", SubmitControl, HELP)
  62. cli.invoke(sys.argv[1:])