def delete(blobId, release='draft'): try: try: thumbnail = None dbGrid = Db().getGridFs('blobs') filename = "%s.%s" % (blobId, release) thumbnail = dbGrid.get_last_version(filename) dbGrid.delete(thumbnail._id) thumbnail = thumbnail.__dict__['_file'] except CorruptGridFile as e: pass except NoFile: pass finally: if not thumbnail or not 'activity' in thumbnail: return True a = ActivityFactory.get(thumbnail['activity']) node = a.__dict__[release] if not 'blobs' in node: return True if not thumbnail['type'] in node['blobs']: return True node['blobs'][thumbnail['type']].remove(str(blobId)) ActivityFactory.update(a) except DbError: output.error('cannot access db', 503)
def update(blobId, blobType, release, data, content_type, **args): try: dbGrid = Db().getGridFs('blobs') dbGrid.put( data, content_type=content_type, filename="%s.%s" % (blobId, release), type=blobType, blobId=str(blobId), release=release, **args ) try: oldFile = dbGrid.get_version("%s.%s" % (blobId, release), -2) dbGrid.delete(oldFile._id) except NoFile: pass except CorruptGridFile: pass except DbError: output.error('cannot access db', 503)