Skip to content

Commit

Permalink
SXDEDPCXZIC-275 / Implement use DataPusher or XLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel.malko authored and PavloMalko committed Feb 26, 2024
1 parent de8cde1 commit edb2660
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
16 changes: 13 additions & 3 deletions ckanext/datastore_refresh/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import ckan.plugins.toolkit as tk
import click

from ckan.common import config


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -67,12 +69,20 @@ def _submit_resource(dataset, resource, context):
"""resource: resource dictionary"""
# Copied and modifed from ckan/default/src/ckanext-xloader/ckanext/xloader/cli.py to check for Xloader formats before submitting
# import here, so that that loggers are setup
from ckanext.xloader.plugin import XLoaderFormats

if not XLoaderFormats.is_it_an_xloader_format(resource["format"]):
try:
from ckanext.xloader.plugin import XLoaderFormats

can_subbmit = XLoaderFormats.is_it_an_xloader_format(resource["format"])
except ImportError:
can_subbmit = resource["format"] and resource[
"format"
].lower() in config.get("ckan.datapusher.formats")

if not can_subbmit:
click.echo(
f'Skipping resource {resource["id"]} because format'
f' "{resource["format"]}" is not configured to be xloadered'
f' "{resource["format"]}" is not configured to be loadered'
)
return
if resource["url_type"] in ("datapusher", "xloader"):
Expand Down
14 changes: 11 additions & 3 deletions ckanext/datastore_refresh/plugin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
from __future__ import annotations

import logging

import requests

from typing import Any

import ckan.plugins as plugins
import ckan.plugins.toolkit as tk
from ckan.views.api import API_DEFAULT_VERSION

import ckanext.xloader.interfaces as xloader_interfaces
try:
import ckanext.xloader.interfaces as xloader_interfaces
loader_interface = xloader_interfaces.IXloader
except ImportError:
import ckanext.datapusher.interfaces as datapusher_interfaces
loader_interface = datapusher_interfaces.IDataPusher

from . import cli, helpers, view
from .logic import auth, action
Expand All @@ -22,7 +31,7 @@ class DatastoreRefreshPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IClick)
plugins.implements(plugins.IBlueprint)
plugins.implements(xloader_interfaces.IXloader, inherit=True)
plugins.implements(loader_interface, inherit=True)

# ITemplateHelpers
def get_helpers(self):
Expand Down Expand Up @@ -57,7 +66,6 @@ def get_commands(self):
def get_blueprint(self):
return view.get_blueprints()

# IXLoader
def after_upload(self, context, resource_dict, dataset_dict):
_purge_section_cache(context, resource_dict, dataset_dict)

Expand Down

0 comments on commit edb2660

Please sign in to comment.