harvester/ext/importer/ckan.py
def import_to_ckan(storage, ckan_url, api_key, source_name,
                   organization_merge_strategy='create',
                   group_merge_strategy='create',
                   dataset_preserve_names=True,
                   dataset_preserve_organization=True,
                   dataset_group_merge_strategy='add'):
    """
    Import data from a storage to CKAN.

    :param storage:
        Input storage. Must contain data in CKAN format.
        Can be either a Storage object or a dict
        like ``{'url': '...', 'conf': {}}``.

    :param ckan_url: URL to the CKAN instance

    :param api_key: CKAN API key

    :param source_name: Name for the import source

    :param organization_merge_strategy:
        One of: create, update.

    :param group_merge_strategy:
        One of: create, update.

    :param dataset_preserve_names:
         If ``True`` (the default) will preserve old names of
         existing datasets. Otherwise, it will regenerate them
         (not recommended!)

    :param dataset_preserve_organization:
         Preserve current dataset organization?

    :param dataset_group_merge_strategy:
         One of: add, replace, preserve (default: 'add')

    """

    logger.info("Starting data synchronization to ckan")

    storage = get_storage_from_arg(storage)

    # ------------------------------------------------------------
    # Initialize the client taking some kwargs from configuration
    # todo: we need some way to make the sync client report status!

    client = SynchronizationClient(
        ckan_url, api_key,
        organization_merge_strategy=organization_merge_strategy,
        group_merge_strategy=group_merge_strategy,
        dataset_preserve_names=dataset_preserve_names,
        dataset_preserve_organization=dataset_preserve_organization,
        dataset_group_merge_strategy=dataset_group_merge_strategy)

    # ------------------------------------------------------------
    # New-style storage is dict-like, no need to pre-query.

    data = {
        'dataset': storage.documents['dataset'],
        'group': storage.documents['group'],
        'organization': storage.documents['organization'],
    }

    client.sync(source_name, data)

    Import data from a storage to CKAN.

    :param storage:
        Input storage. Must contain data in CKAN format.
        Can be either a Storage object or a dict
        like ``{'url': '...', 'conf': {}}``.

    :param ckan_url: URL to the CKAN instance

    :param api_key: CKAN API key

    :param source_name: Name for the import source

    :param organization_merge_strategy:
        One of: create, update.

    :param group_merge_strategy:
        One of: create, update.

    :param dataset_preserve_names:
         If ``True`` (the default) will preserve old names of
         existing datasets. Otherwise, it will regenerate them
         (not recommended!)

    :param dataset_preserve_organization:
         Preserve current dataset organization?

    :param dataset_group_merge_strategy:
         One of: add, replace, preserve (default: 'add')

    
Import data from a storage to CKAN.
Import data from a storage to CKAN .
def import_to_ckan(storage, ckan_url, api_key, source_name,
                   organization_merge_strategy='create',
                   group_merge_strategy='create',
                   dataset_preserve_names=True,
                   dataset_preserve_organization=True,
                   dataset_group_merge_strategy='add'):
    logger.info("Starting data synchronization to ckan")
    storage = get_storage_from_arg(storage)
    client = SynchronizationClient(
        ckan_url, api_key,
        organization_merge_strategy=organization_merge_strategy,
        group_merge_strategy=group_merge_strategy,
        dataset_preserve_names=dataset_preserve_names,
        dataset_preserve_organization=dataset_preserve_organization,
        dataset_group_merge_strategy=dataset_group_merge_strategy)
    data = {
        'dataset': storage.documents['dataset'],
        'group': storage.documents['group'],
        'organization': storage.documents['organization'],
    }
    client.sync(source_name, data)
def import_to_ckan ( storage , ckan_url , api_key , source_name , organization_merge_strategy = 'create' , group_merge_strategy = 'create' , dataset_preserve_names = True , dataset_preserve_organization = True , dataset_group_merge_strategy = 'add' ) : logger . info ( "Starting data synchronization to ckan" ) storage = get_storage_from_arg ( storage ) client = SynchronizationClient ( ckan_url , api_key , organization_merge_strategy = organization_merge_strategy , group_merge_strategy = group_merge_strategy , dataset_preserve_names = dataset_preserve_names , dataset_preserve_organization = dataset_preserve_organization , dataset_group_merge_strategy = dataset_group_merge_strategy ) data = { 'dataset' : storage . documents [ 'dataset' ] , 'group' : storage . documents [ 'group' ] , 'organization' : storage . documents [ 'organization' ] , } client . sync ( source_name , data )
Import data from a storage to CKAN.
Import data from a storage to CKAN .
"""
    Import data from a storage to CKAN.

    :param storage:
        Input storage. Must contain data in CKAN format.
        Can be either a Storage object or a dict
        like ``{'url': '...', 'conf': {}}``.

    :param ckan_url: URL to the CKAN instance

    :param api_key: CKAN API key

    :param source_name: Name for the import source

    :param organization_merge_strategy:
        One of: create, update.

    :param group_merge_strategy:
        One of: create, update.

    :param dataset_preserve_names:
         If ``True`` (the default) will preserve old names of
         existing datasets. Otherwise, it will regenerate them
         (not recommended!)

    :param dataset_preserve_organization:
         Preserve current dataset organization?

    :param dataset_group_merge_strategy:
         One of: add, replace, preserve (default: 'add')

    """ # ------------------------------------------------------------ # Initialize the client taking some kwargs from configuration # todo: we need some way to make the sync client report status! # ------------------------------------------------------------ # New-style storage is dict-like, no need to pre-query.
storage
Input storage. Must contain data in CKAN format.
Can be either a Storage object or a dict
like ``{'url': '...', 'conf': {}}``.
Input storage . Must contain data in CKAN format . Can be either a Storage object or a dict like ` ` { ' url ' : ' ... ' ' conf ' : {} } ` ` .
ckan_url
URL to the CKAN instance
URL to the CKAN instance
api_key
CKAN API key
CKAN API key
source_name
Name for the import source
Name for the import source
organization_merge_strategy
One of: create, update.
One of : create update .
group_merge_strategy
One of: create, update.
One of : create update .
dataset_preserve_names
If ``True`` (the default) will preserve old names of
existing datasets. Otherwise, it will regenerate them
(not recommended!)
If ` ` True ` ` ( the default ) will preserve old names of existing datasets . Otherwise it will regenerate them ( not recommended! )
dataset_preserve_organization
None
dataset_group_merge_strategy
One of: add, replace, preserve (default: 'add')
One of : add replace preserve ( default : ' add ' )