Exemplo n.º 1
0
def add_link(item_or_item_name, channel_uid_or_string):
    """
    This function adds a Link to an Item using a
    ManagedItemChannelLinkProvider.

    Args:
        item_or_item_name (Item or str): the Item object or name to create
            the Link for
        channel_uid_or_string (ChannelUID or str): the ChannelUID or string
            representation of a ChannelUID to link the Item to

    Returns:
        Item or None: the Item that the Link was added to or None
    """
    try:
        item = validate_item(item_or_item_name)
        channel_uid = validate_channel_uid(channel_uid_or_string)
        if item is None or channel_uid is None:
            return None

        link = ItemChannelLink(item.name, channel_uid)
        MANAGED_ITEM_CHANNEL_LINK_PROVIDER.add(link)
        LOG.debug(u"Link added: '{}'".format(link))
        return item
    except:
        import traceback
        LOG.warn(traceback.format_exc())
        return None
Exemplo n.º 2
0
def remove_link(item_or_item_name, channel_uid_or_string):
    """
    This function removes a Link from an Item using a
    ManagedItemChannelLinkProvider.

    Args:
        item_or_item_name (Item or str): the Item object or name to create
            the Link for
        channel_uid_or_string (ChannelUID or str): the ChannelUID or string
            representation of a ChannelUID to link the Item to

    Returns:
        Item or None: the Item that the Link was removed from or None
    """
    try:
        item = validate_item(item_or_item_name)
        channel_uid = validate_channel_uid(channel_uid_or_string)
        if item is None or channel_uid is None:
            return None

        link = ItemChannelLink(item.name, channel_uid)
        ManagedItemChannelLinkProvider.remove(str(link))
        log.debug("Link removed: [{}]".format(link))
        return item
    except:
        import traceback
        log.error(traceback.format_exc())
        return None
Exemplo n.º 3
0
def remove_link(item_or_item_name, channel_uid_or_string):
    try:
        item = validate_item(item_or_item_name)
        channel_uid = validate_channel_uid(channel_uid_or_string)
        if item is None or channel_uid is None:
            return None
        
        link = ItemChannelLink(item.name, channel_uid)
        ManagedItemChannelLinkProvider.remove(str(link))
        log.debug("Link removed: [{}]".format(link))
        return item
    except:
        import traceback
        log.error(traceback.format_exc())
        return None