def makeFilelist(self, files = {}): """ _makeFilelist_ Create a new filelist document containing the id """ input = {"collection_name": self.collectionName, "collection_type": self.collectionType, "fileset_name": self["name"], "files": files, "timestamp": time.time()} document = CMSCouch.Document(None, input) self.owner.ownThis(document) commitInfo = self.couchdb.commitOne(document) document['_id'] = commitInfo[0]['id'] if 'rev' in commitInfo[0]: document['_rev'] = commitInfo[0]['rev'] else: if commitInfo[0]['reason'].find('{exit_status,0}') != -1: #TODO: in this case actually insert succeeded but return error # due to the bug # https://issues.apache.org/jira/browse/COUCHDB-893 # if rev is needed to proceed need to get by # self.couchdb.documentExist(document['_id']) # but that function need to be changed to return _rev document['_rev'] = "NeedToGet" else: msg = "Unable to insert document: check acdc server doc id: %s" % document['_id'] raise RuntimeError(msg) return document
def create(self): """ _create_ Create the couch document for this object. """ if not self.couch.documentExists(self.document_id): couchDoc = CMSCouch.Document(self.document_id, { self.cdb_document_data : dict(self)}) self.couch.commitOne(couchDoc)
def makeFilelist(self, files={}): """ _makeFilelist_ Create a new filelist document containing the id """ input = { "collection_name": self.collectionName, "collection_type": self.collectionType, "fileset_name": self["name"], "files": files } document = CMSCouch.Document(None, input) self.owner.ownThis(document) commitInfo = self.couchdb.commitOne(document) document['_id'] = commitInfo[0]['id'] document['_rev'] = commitInfo[0]['rev'] return document
def removeOwner(self, owner): """ _removeOwner_ Remove an owner and all the associated collections and filesets """ result = self.couchdb.loadView( "GroupUser", 'owner_group_user', { 'startkey': [owner.group.name, owner.name], 'endkey': [owner.group.name, owner.name] }, []) for row in result[u'rows']: deleteMe = CMSCouch.Document() deleteMe[u'_id'] = row[u'value'][u'id'] deleteMe[u'_rev'] = row[u'value'][u'rev'] deleteMe.delete() self.couchdb.queue(deleteMe) self.couchdb.commit() owner.drop() return