def _copy_item(item, source, target, target_user, target_folder_id,
               relationships, copy_dir):
    itemid = item['id']
    item_dir = os.path.join(copy_dir, itemid)
    os.makedirs(item_dir)
    try:

        # Create a new items with the subset of properties we want to
        # copy to the target portal
        target_item = _select_properties(item, ITEM_COPY_PROPERTIES)

        # If its a text-based item, then read the text and
        # add it to the request. Otherwise treat it as a
        # file-based item, download it and add to the request
        # as a file
        data_file = None
        if item['type'] in TEXT_BASED_ITEM_TYPES:
            text = source.item_data(itemid)
            if text and len(text) > 0:
                target_item['text'] = text
        elif item['type'] in FILE_BASED_ITEM_TYPES:
            data_file = source.item_datad(itemid, item_dir, item.get('name'))

        # Handle the thumbnail (if one exists)
        thumbnail_file = None
        if item in 'thumbnail':
            thumbnail_file = source.item_thumbnaild(
                itemid, item_dir, unicode_to_ascii(item['thumbnail']))

        # Handle the metadata (if it exists)
        metadata_file = source.item_metadatad(itemid, item_dir)

        # Add the item to the target portal
        target_itemid = target.add_item(
            target_item, data_file, thumbnail_file, metadata_file,
            target_user, unicode_to_ascii(target_folder_id))
        if target_itemid:
            _log.info('Copied item ' + itemid + ' in source portal '
                      + 'to ' + target_itemid + ' in target portal')

            # We're returning a mapping of source id to target (dict).
            # But before we return, handle the related items (if specified)
            copied_items = dict({itemid: target_itemid})
            if relationships:
                related_items = _copy_relationships(copied_items, source,
                                                    target, target_user, target_folder_id,
                                                    relationships, copy_dir)
                copied_items.update(related_items)
            return target_itemid, copied_items

        else:
            _log.warning('Item ' + itemid + ' was not copied '\
                         + 'to target portal')

    # Just log IOErrors (includes HTTPErrors)
    except IOError as e:
        _log.warning('Item ' + itemid + ' was not copied to target portal ' \
                     + '(' + str(e) + ')')

    # Clean up the item directories as we go
    finally:
        if clean_temp_files:
            shutil.rmtree(item_dir)

    # Return an empty tuple, if for some reason the copy didn't happen
    return None, None
dataset/ETHPy150Open Esri/ops-server-config/Publish/Portal/portalpy/provision.py/_copy_item/swapped operands of `in`