+class MetadataKey(ORMObject):
+ def __init__(self, key = None):
+ self.key = key
+
+ def properties(self):
+ return ['key']
+
+ def not_null_constraints(self):
+ return ['key']
+
+__all__.append('MetadataKey')
+
+@session_wrapper
+def get_or_set_metadatakey(keyname, session=None):
+ """
+ Returns MetadataKey object for given uidname.
+
+ If no matching keyname is found, a row is inserted.
+
+ @type uidname: string
+ @param uidname: The keyname to add
+
+ @type session: SQLAlchemy
+ @param session: Optional SQL session object (a temporary one will be
+ generated if not supplied). If not passed, a commit will be performed at
+ the end of the function, otherwise the caller is responsible for commiting.
+
+ @rtype: MetadataKey
+ @return: the metadatakey object for the given keyname
+ """
+
+ q = session.query(MetadataKey).filter_by(key=keyname)
+
+ try:
+ ret = q.one()
+ except NoResultFound:
+ ret = MetadataKey(keyname)
+ session.add(ret)
+ session.commit_or_flush()
+
+ return ret
+
+__all__.append('get_or_set_metadatakey')
+
+################################################################################
+
+class BinaryMetadata(ORMObject):
+ def __init__(self, key = None, value = None, binary = None):
+ self.key = key
+ self.value = value
+ self.binary = binary
+
+ def properties(self):
+ return ['binary', 'key', 'value']
+
+ def not_null_constraints(self):
+ return ['value']
+
+__all__.append('BinaryMetadata')
+
+################################################################################
+
+class SourceMetadata(ORMObject):
+ def __init__(self, key = None, value = None, source = None):
+ self.key = key
+ self.value = value
+ self.source = source
+
+ def properties(self):
+ return ['source', 'key', 'value']
+
+ def not_null_constraints(self):
+ return ['value']
+
+__all__.append('SourceMetadata')
+
+################################################################################
+