Skip to content

Instantly share code, notes, and snippets.

@will-moore
Created September 4, 2014 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will-moore/a23dc5ffa6a5394bae89 to your computer and use it in GitHub Desktop.
Save will-moore/a23dc5ffa6a5394bae89 to your computer and use it in GitHub Desktop.
Delete OMERO file attachments created by the 'Batch Image Export' script
from omero.gateway import BlitzGateway
from omero.constants.namespaces import NSCREATED
user = 'root'
pw = 'omero'
host = 'localhost'
conn = BlitzGateway(user, pw, host=host, port=4064)
conn.connect()
# get all File Annotations with the 'Batch_Image_Export' namespace
namespace = NSCREATED + "/omero/export_scripts/Batch_Image_Export"
# process a group at a time...
for g in conn.listGroups():
print 'group', g.getId(), g.getName()
# restrict query to group
conn.SERVICE_OPTS.setOmeroGroup(g.getId())
# Query attachments by namespace
fileAnnotations = conn.getObjects("FileAnnotation", attributes={'ns': namespace})
dcs = []
for fa in fileAnnotations:
print fa.id, fa.getFile().getName()
dcs.append(fa.id)
if len(dcs) == 0:
continue
print "Deleting %s files..." % len(dcs)
# This will delete Annotations and linked files.
handle = conn.deleteObjects('/Annotation', dcs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment