[refactoring] Add a command to create the necessary tables in the database

This commit is contained in:
Adrià Mercader 2011-04-13 12:39:53 +01:00
parent 312e9b8209
commit 040e4d6956
2 changed files with 50 additions and 30 deletions

View File

@ -5,28 +5,15 @@ ckanext-harvest - Remote harvesting extension
This extension will contain all harvesting related code, now present This extension will contain all harvesting related code, now present
in ckan core, ckanext-dgu and ckanext-csw. 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 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 The extension needs a user with sysadmin privileges to perform the
harvesting jobs. You can create such a user running these two commands in harvesting jobs. You can create such a user running these two commands in
the ckan directory:: the ckan directory::
@ -46,32 +33,53 @@ http://localhost:5000/)::
ckan.api_url = <api_url> ckan.api_url = <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 Command line interface
====================== ======================
The following operations can be run from the command line using the The following operations can be run from the command line using the
``paster harvester`` command:: ``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 - create new harvest source
harvester rmsource {url} harvester rmsource {id}
- remove a harvester source (and associated jobs) - remove (inactivate) a harvester source
harvester sources harvester sources [all]
- lists harvest sources - lists harvest sources
If 'all' is defined, it also shows the Inactive sources
harvester job {source-id} [{user-ref}] harvester job {source-id}
- create new harvesting job - create new harvest job
harvester rmjob {job-id}
- remove a harvesting job
harvester jobs harvester jobs
- lists harvesting jobs - lists harvest jobs
harvester run 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 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 a development.ini file to be present. Most of the time you will specify

View File

@ -10,6 +10,10 @@ class Harvester(CkanCommand):
'''Harvests remotely mastered metadata '''Harvests remotely mastered metadata
Usage: Usage:
harvester initdb
- Creates the necessary tables in the database
harvester source {url} {type} [{active}] [{user-id}] [{publisher-id}] harvester source {url} {type} [{active}] [{user-id}] [{publisher-id}]
- create new harvest source - create new harvest source
@ -78,6 +82,8 @@ class Harvester(CkanCommand):
logging.getLogger('amqplib').setLevel(logging.INFO) logging.getLogger('amqplib').setLevel(logging.INFO)
consumer = get_fetch_consumer() consumer = get_fetch_consumer()
consumer.wait() consumer.wait()
elif cmd == "initdb":
self.initdb()
else: else:
print 'Command %s not recognized' % cmd print 'Command %s not recognized' % cmd
@ -85,6 +91,12 @@ class Harvester(CkanCommand):
def _load_config(self): def _load_config(self):
super(Harvester, self)._load_config() 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): def create_harvest_source(self):
if len(self.args) >= 2: if len(self.args) >= 2: