2011-03-28 16:52:43 +02:00
|
|
|
import os
|
|
|
|
from logging import getLogger
|
|
|
|
|
2012-03-02 17:49:39 +01:00
|
|
|
from pylons import config
|
2011-03-28 16:52:43 +02:00
|
|
|
from genshi.input import HTML
|
|
|
|
from genshi.filters import Transformer
|
|
|
|
|
|
|
|
import ckan.lib.helpers as h
|
|
|
|
|
|
|
|
from ckan.plugins import implements, SingletonPlugin
|
|
|
|
from ckan.plugins import IRoutes, IConfigurer
|
2012-03-01 13:02:16 +01:00
|
|
|
from ckan.plugins import IConfigurable, IActions, IAuthFunctions
|
2012-03-05 18:10:02 +01:00
|
|
|
from ckanext.harvest.model import setup as model_setup
|
2011-03-28 16:52:43 +02:00
|
|
|
|
|
|
|
log = getLogger(__name__)
|
2012-04-10 21:53:29 +02:00
|
|
|
assert not log.disabled
|
2011-03-28 16:52:43 +02:00
|
|
|
|
|
|
|
class Harvest(SingletonPlugin):
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2011-03-28 16:52:43 +02:00
|
|
|
implements(IConfigurable)
|
|
|
|
implements(IRoutes, inherit=True)
|
|
|
|
implements(IConfigurer, inherit=True)
|
2012-02-29 11:59:02 +01:00
|
|
|
implements(IActions)
|
2012-03-01 13:02:16 +01:00
|
|
|
implements(IAuthFunctions)
|
2012-02-29 11:59:02 +01:00
|
|
|
|
2011-03-28 16:52:43 +02:00
|
|
|
def configure(self, config):
|
2012-03-05 18:10:02 +01:00
|
|
|
|
|
|
|
auth_profile = config.get('ckan.harvest.auth.profile',None)
|
|
|
|
|
|
|
|
if auth_profile:
|
|
|
|
# Check if auth profile exists
|
|
|
|
module_root = 'ckanext.harvest.logic.auth'
|
|
|
|
module_path = '%s.%s' % (module_root, auth_profile)
|
|
|
|
try:
|
|
|
|
module = __import__(module_path)
|
|
|
|
except ImportError,e:
|
|
|
|
raise ImportError('Unknown auth profile: %s' % auth_profile)
|
|
|
|
|
|
|
|
# If we are using the publisher auth profile, make sure CKAN core
|
|
|
|
# also uses it.
|
|
|
|
if auth_profile == 'publisher' and \
|
|
|
|
not config.get('ckan.auth.profile','') == 'publisher':
|
|
|
|
raise Exception('You must enable the "publisher" auth profile'
|
|
|
|
+' in CKAN in order to use it on the harvest extension'
|
|
|
|
+' (adding "ckan.auth.profile=publisher" to your ini file)')
|
|
|
|
|
|
|
|
# Setup harvest model
|
|
|
|
model_setup()
|
2011-03-28 16:52:43 +02:00
|
|
|
|
|
|
|
def before_map(self, map):
|
|
|
|
|
2011-05-13 15:17:58 +02:00
|
|
|
controller = 'ckanext.harvest.controllers.view:ViewController'
|
|
|
|
map.connect('harvest', '/harvest',controller=controller,action='index')
|
2011-03-28 16:52:43 +02:00
|
|
|
|
2011-05-13 15:17:58 +02:00
|
|
|
map.connect('/harvest/new', controller=controller, action='new')
|
2012-03-01 13:02:16 +01:00
|
|
|
map.connect('/harvest/edit/:id', controller=controller, action='edit')
|
2011-05-13 15:17:58 +02:00
|
|
|
map.connect('/harvest/delete/:id',controller=controller, action='delete')
|
|
|
|
map.connect('/harvest/:id', controller=controller, action='read')
|
2011-03-28 16:52:43 +02:00
|
|
|
|
2012-03-01 13:02:16 +01:00
|
|
|
map.connect('harvesting_job_create', '/harvest/refresh/:id',controller=controller,
|
2011-05-13 15:17:58 +02:00
|
|
|
action='create_harvesting_job')
|
2011-09-08 11:27:36 +02:00
|
|
|
|
|
|
|
map.connect('/harvest/object/:id', controller=controller, action='show_object')
|
|
|
|
|
2011-03-28 16:52:43 +02:00
|
|
|
return map
|
|
|
|
|
|
|
|
def update_config(self, config):
|
|
|
|
here = os.path.dirname(__file__)
|
2011-04-18 10:49:25 +02:00
|
|
|
template_dir = os.path.join(here, 'templates')
|
|
|
|
public_dir = os.path.join(here, 'public')
|
2011-03-28 16:52:43 +02:00
|
|
|
if config.get('extra_template_paths'):
|
2011-06-07 12:58:35 +02:00
|
|
|
config['extra_template_paths'] += ',' + template_dir
|
2011-03-28 16:52:43 +02:00
|
|
|
else:
|
|
|
|
config['extra_template_paths'] = template_dir
|
|
|
|
if config.get('extra_public_paths'):
|
2011-06-07 12:58:35 +02:00
|
|
|
config['extra_public_paths'] += ',' + public_dir
|
2011-03-28 16:52:43 +02:00
|
|
|
else:
|
|
|
|
config['extra_public_paths'] = public_dir
|
2012-02-29 11:59:02 +01:00
|
|
|
|
|
|
|
def get_actions(self):
|
|
|
|
from ckanext.harvest.logic.action.get import (harvest_source_show,
|
|
|
|
harvest_source_list,
|
2012-06-01 18:03:40 +02:00
|
|
|
harvest_source_for_a_dataset,
|
2012-02-29 11:59:02 +01:00
|
|
|
harvest_job_show,
|
2012-02-29 16:20:35 +01:00
|
|
|
harvest_job_list,
|
2012-03-01 13:02:16 +01:00
|
|
|
harvest_object_show,
|
|
|
|
harvest_object_list,
|
2012-02-29 16:20:35 +01:00
|
|
|
harvesters_info_show,)
|
|
|
|
from ckanext.harvest.logic.action.create import (harvest_source_create,
|
|
|
|
harvest_job_create,
|
|
|
|
harvest_job_create_all,)
|
|
|
|
from ckanext.harvest.logic.action.update import (harvest_source_update,
|
|
|
|
harvest_objects_import,
|
|
|
|
harvest_jobs_run)
|
|
|
|
from ckanext.harvest.logic.action.delete import (harvest_source_delete,)
|
2012-02-29 11:59:02 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
'harvest_source_show': harvest_source_show,
|
|
|
|
'harvest_source_list': harvest_source_list,
|
2012-06-01 18:03:40 +02:00
|
|
|
'harvest_source_for_a_dataset': harvest_source_for_a_dataset,
|
2012-02-29 11:59:02 +01:00
|
|
|
'harvest_job_show': harvest_job_show,
|
|
|
|
'harvest_job_list': harvest_job_list,
|
2012-03-01 13:02:16 +01:00
|
|
|
'harvest_object_show': harvest_object_show,
|
|
|
|
'harvest_object_list': harvest_object_list,
|
|
|
|
'harvesters_info_show': harvesters_info_show,
|
2012-02-29 16:20:35 +01:00
|
|
|
'harvest_source_create': harvest_source_create,
|
|
|
|
'harvest_job_create': harvest_job_create,
|
|
|
|
'harvest_job_create_all': harvest_job_create_all,
|
|
|
|
'harvest_source_update': harvest_source_update,
|
|
|
|
'harvest_source_delete': harvest_source_delete,
|
2012-03-01 13:02:16 +01:00
|
|
|
'harvest_objects_import': harvest_objects_import,
|
|
|
|
'harvest_jobs_run':harvest_jobs_run
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_auth_functions(self):
|
|
|
|
|
2012-03-02 17:49:39 +01:00
|
|
|
module_root = 'ckanext.harvest.logic.auth'
|
|
|
|
auth_profile = config.get('ckan.harvest.auth.profile', '')
|
|
|
|
|
|
|
|
auth_functions = _get_auth_functions(module_root)
|
|
|
|
if auth_profile:
|
|
|
|
module_root = '%s.%s' % (module_root, auth_profile)
|
|
|
|
auth_functions = _get_auth_functions(module_root,auth_functions)
|
|
|
|
|
2012-06-08 18:09:22 +02:00
|
|
|
log.debug('Using auth profile at %s' % module_root)
|
2012-03-02 17:49:39 +01:00
|
|
|
|
|
|
|
return auth_functions
|
|
|
|
|
|
|
|
def _get_auth_functions(module_root, auth_functions = {}):
|
|
|
|
|
|
|
|
for auth_module_name in ['get', 'create', 'update','delete']:
|
|
|
|
module_path = '%s.%s' % (module_root, auth_module_name,)
|
|
|
|
try:
|
|
|
|
module = __import__(module_path)
|
|
|
|
except ImportError,e:
|
|
|
|
log.debug('No auth module for action "%s"' % auth_module_name)
|
|
|
|
continue
|
|
|
|
|
|
|
|
for part in module_path.split('.')[1:]:
|
|
|
|
module = getattr(module, part)
|
|
|
|
|
|
|
|
for key, value in module.__dict__.items():
|
|
|
|
if not key.startswith('_'):
|
|
|
|
auth_functions[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
return auth_functions
|
2012-03-01 13:02:16 +01:00
|
|
|
|