Exemple #1
0
def set_meta_text(obj, meta_type, text, metadata_type=INTENT_META_TYPE, timestamp=True):
    if not isinstance(obj, XigtContainerMixin):
        raise Exception("Attempt to add meta object on object ({}) that cannot contain meta".format(meta_type(obj)))
    else:
        m = find_meta(obj, meta_type, metadata_type=metadata_type)
        if m is None:
            m = Meta(type=meta_type, text=text)
            set_meta(obj, m, metadata_type=metadata_type, timestamp=timestamp)
        else:
            m.text = text
        timestamp_meta(m)
Exemple #2
0
def set_meta_attr(obj, meta_type, attr, val, metadata_type=INTENT_META_TYPE, timestamp=True):
    """
    Add an arbitrary piece of metadata to a XIGT object that accepts metadata

    :param obj: XIGT object to add a piece of metadata to.
    :meta_type obj: XigtContainerMixin
    :param meta_type: Type of the Meta object to add
    :param val: Text value for the meta object to be added.
    :param metadata_type: Type for the metadata container in which to append the item.
    :raise Exception: If ``obj`` is of a meta_type that does not contain metadata.
    """
    if not isinstance(obj, XigtContainerMixin):
        raise Exception('Attempt to add meta object on object ({}) that cannot contain meta'.format(obj))
    else:
        m = find_meta(obj, meta_type, metadata_type=metadata_type)
        if m is None:
            m = Meta(type=meta_type, attributes={attr:val})
            set_meta(obj, m, metadata_type=metadata_type, timestamp=timestamp)
        else:
            m.attributes[attr] = val
        timestamp_meta(m)