def serialize_items(self, items, path, portal=None):
        """ Serialize items to JSON. """
        base_dir = os.path.abspath(path)
        if not os.path.exists(base_dir):
            os.makedirs(base_dir)
        elif not os.path.isdir(base_dir):
            base_dir = os.path.dirname(base_dir)

        for item in items:
            item_dir = os.path.join(base_dir, item['id'])
            if not os.path.exists(item_dir):
                os.makedirs(item_dir)

            # Write the thumbnail to a file (per the name specified in the item)
            if self.thumbnails:
                if not portal:
                    raise PortalError('The "portal" argument is required to  '\
                                      + 'download thumbnails')
                thumbnail = item.get('thumbnail')
                if thumbnail:
                    portal.item_thumbnaild(item['id'], item_dir, thumbnail)

            # Handle the data
            if self.data:
                if not portal:
                    raise PortalError('The "portal" argument is required to  '\
                                      + 'download data')
                if item['type'] in TEXT_BASED_ITEM_TYPES:
                    text = portal.item_data(item['id'])
                    if text and len(text) > 0:
                        item['text'] = text
                elif item['type'] in FILE_BASED_ITEM_TYPES:
                    data_dir = os.path.join(item_dir, 'data')
                    if not os.path.exists(data_dir):
                        os.makedirs(data_dir)
                    portal.item_datad(item['id'], data_dir, item.get('name'))

            # Write the metadata to a file
            if self.metadata:
                if not portal:
                    raise PortalError('The "portal" argument is required to  '\
                                      + 'download metadata')
                portal.item_metadatad(item['id'], item_dir)

            # Write the item itself to a file (do this at the end, as the data
            # will get writen to the item if the item type is text)
            self.to_file(item, os.path.join(item_dir, 'item.json'))
dataset/ETHPy150Open Esri/ops-server-config/Publish/Portal/portalpy/provision.py/JSONSerializer.serialize_items/original