/examples/Delete/FileAnnotationDelete.py

https://github.com/qidane/openmicroscopy
Python | 58 lines | 42 code | 9 blank | 7 comment | 7 complexity | 603d0a13f4898d1620245ab1032982ae MD5 | raw file
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Uses the default {@link DeleteCallbackI} instance.
  5. to delete a FileAnnotation along with its associated
  6. OriginalFile and any annotation links.
  7. """
  8. import omero
  9. import omero.callbacks
  10. c = omero.client()
  11. ice_config = c.getProperty("Ice.Config")
  12. from omero.rtypes import *
  13. from omero.model import *
  14. try:
  15. s = c.createSession()
  16. d = DatasetI()
  17. d.setName(rstring("FileAnnotationDelete"))
  18. d = s.getUpdateService().saveAndReturnObject(d)
  19. file = c.upload(ice_config)
  20. fa = FileAnnotationI()
  21. fa.setFile(OriginalFileI(file.id.val, False))
  22. link = DatasetAnnotationLinkI()
  23. link.parent = DatasetI(d.id.val, False)
  24. link.child = fa
  25. link = s.getUpdateService().saveAndReturnObject(link)
  26. fa = link.child
  27. graph_spec = "/Annotation"
  28. options = {}
  29. delCmd = omero.cmd.Delete(graph_spec, long(fa.id.val), options)
  30. dcs = [delCmd]
  31. doall = omero.cmd.DoAll()
  32. doall.requests = dcs
  33. handle = s.submit(doall)
  34. callback = None
  35. try:
  36. callback = omero.callbacks.CmdCallbackI(c, handle)
  37. loops = 10
  38. delay = 500
  39. callback.loop(loops, delay) # Throw LockTimeout
  40. rsp = callback.getResponse()
  41. if isinstance(rsp, omero.cmd.OK):
  42. print "OK"
  43. finally:
  44. if callback:
  45. callback.close(True)
  46. else:
  47. handle.close()
  48. finally:
  49. c.closeSession()