/examples/Delete/FileAnnotationDelete.py

https://github.com/ximenesuk/openmicroscopy
Python | 52 lines | 35 code | 10 blank | 7 comment | 7 complexity | 1f29a4e320232750f36c3a9e32858bcc 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. fa = FileAnnotationI()
  19. file = c.upload(ice_config)
  20. fa.setFile(file)
  21. d.linkAnnotation(fa)
  22. d = s.getUpdateService().saveAndReturnObject(d)
  23. fa = d.linkedAnnotationList()[0]
  24. deleteServicePrx = s.getDeleteService();
  25. dc = omero.api.delete.DeleteCommand("/Annotation", fa.id.val, None)
  26. deleteHandlePrx = deleteServicePrx .queueDelete([dc])
  27. cb = omero.callbacks.DeleteCallbackI(c, deleteHandlePrx)
  28. try:
  29. try:
  30. cb.loop(10, 500)
  31. except omero.LockTimeout:
  32. print "Not finished in 5 seconds. Cancelling..."
  33. if not deleteHandlePrx.cancel():
  34. print "ERROR: Failed to cancel"
  35. reports = deleteHandlePrx.report()
  36. r = reports[0] # We only sent one command
  37. print "Report:error=%s,warning=%s,deleted=%s" % \
  38. (r.error, r.warning, r.actualDeletes)
  39. finally:
  40. cb.close()
  41. finally:
  42. c.closeSession()