Created
September 4, 2014 09:35
-
-
Save will-moore/a23dc5ffa6a5394bae89 to your computer and use it in GitHub Desktop.
Delete OMERO file attachments created by the 'Batch Image Export' script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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