From 040e4d69561576cc247b240d3b2c4f128dc89ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Mercader?= Date: Wed, 13 Apr 2011 12:39:53 +0100 Subject: [PATCH] [refactoring] Add a command to create the necessary tables in the database --- README.rst | 68 +++++++++++++++------------ ckanext/harvest/commands/harvester.py | 12 +++++ 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/README.rst b/README.rst index 9dbc84b..c9bc6fb 100644 --- a/README.rst +++ b/README.rst @@ -5,28 +5,15 @@ ckanext-harvest - Remote harvesting extension This extension will contain all harvesting related code, now present in ckan core, ckanext-dgu and ckanext-csw. -Dependencies -============ - -You will need ckan installed, as well as the ckanext-dgu and ckanext-csw -plugins activated. - -Tests -===== - -To run the tests, this is the basic command:: - - $ nosetests --ckan tests/ - -Or with postgres:: - - $ nosetests --ckan --with-pylons=../ckan/test-core.ini tests/ - -(See the Ckan README for more information.) - Configuration ============= +Run the following command (in the ckanext-harvest directory) to create +the necessary tables in the database:: + + paster harvester initdb --config=../ckan/development.ini + + The extension needs a user with sysadmin privileges to perform the harvesting jobs. You can create such a user running these two commands in the ckan directory:: @@ -46,32 +33,53 @@ http://localhost:5000/):: ckan.api_url = +Tests +===== + +To run the tests, this is the basic command:: + + $ nosetests --ckan tests/ + +Or with postgres:: + + $ nosetests --ckan --with-pylons=../ckan/test-core.ini tests/ + +(See the Ckan README for more information.) + + Command line interface ====================== The following operations can be run from the command line using the ``paster harvester`` command:: - harvester source {url} [{user-ref} [{publisher-ref}]] + harvester initdb + - Creates the necessary tables in the database + + harvester source {url} {type} [{active}] [{user-id}] [{publisher-id}] - create new harvest source - harvester rmsource {url} - - remove a harvester source (and associated jobs) + harvester rmsource {id} + - remove (inactivate) a harvester source - harvester sources + harvester sources [all] - lists harvest sources + If 'all' is defined, it also shows the Inactive sources - harvester job {source-id} [{user-ref}] - - create new harvesting job - - harvester rmjob {job-id} - - remove a harvesting job + harvester job {source-id} + - create new harvest job harvester jobs - - lists harvesting jobs + - lists harvest jobs harvester run - - runs harvesting jobs + - runs harvest jobs + + harvester gather_consumer + - starts the consumer for the gathering queue + + harvester fetch_consumer + - starts the consumer for the fetching queue The commands should be run from the ckanext-harvest directory and expect a development.ini file to be present. Most of the time you will specify diff --git a/ckanext/harvest/commands/harvester.py b/ckanext/harvest/commands/harvester.py index 3f72cb9..16c2f79 100644 --- a/ckanext/harvest/commands/harvester.py +++ b/ckanext/harvest/commands/harvester.py @@ -10,6 +10,10 @@ class Harvester(CkanCommand): '''Harvests remotely mastered metadata Usage: + + harvester initdb + - Creates the necessary tables in the database + harvester source {url} {type} [{active}] [{user-id}] [{publisher-id}] - create new harvest source @@ -78,12 +82,20 @@ class Harvester(CkanCommand): logging.getLogger('amqplib').setLevel(logging.INFO) consumer = get_fetch_consumer() consumer.wait() + elif cmd == "initdb": + self.initdb() else: print 'Command %s not recognized' % cmd def _load_config(self): super(Harvester, self)._load_config() + + def initdb(self): + from ckanext.harvest.model import setup as db_setup + db_setup() + + print 'DB tables created' def create_harvest_source(self):