[ckan-changes] commit/ckanext-harvest: kindly: take tables out of global scope at import time
Bitbucket
commits-noreply at bitbucket.org
Tue May 31 16:05:07 UTC 2011
1 new changeset in ckanext-harvest:
http://bitbucket.org/okfn/ckanext-harvest/changeset/1236cf036c61/
changeset: 1236cf036c61
branches:
user: kindly
date: 2011-05-31 18:04:52
summary: take tables out of global scope at import time
affected #: 1 file (728 bytes)
--- a/ckanext/harvest/model/__init__.py Tue Apr 19 17:16:25 2011 +0100
+++ b/ckanext/harvest/model/__init__.py Tue May 31 17:04:52 2011 +0100
@@ -18,8 +18,14 @@
'HarvestObjectError', 'harvest_object_error_table',
]
+harvest_source_table = None
+harvest_job_table = None
+harvest_object_table = None
+harvest_gather_error_table = None
def setup():
+ if harvest_source_table is None:
+ make_harvest_tables()
metadata.create_all()
class HarvestError(Exception):
@@ -95,104 +101,111 @@
pass
-harvest_source_table = Table('harvest_source', metadata,
- Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
- Column('url', types.UnicodeText, nullable=False),
- Column('description', types.UnicodeText, default=u''),
- Column('config', types.UnicodeText, default=u''),
- Column('created', DateTime, default=datetime.datetime.utcnow),
- Column('type',types.UnicodeText,nullable=False),
- Column('active',types.Boolean,default=True),
- Column('user_id', types.UnicodeText, default=u''),
- Column('publisher_id', types.UnicodeText, default=u''),
-)
-# Was harvesting_job
-harvest_job_table = Table('harvest_job', metadata,
- Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
- Column('created', DateTime, default=datetime.datetime.utcnow),
- Column('gather_started', DateTime),
- Column('gather_finished', DateTime),
- Column('source_id', types.UnicodeText, ForeignKey('harvest_source.id')),
- Column('status', types.UnicodeText, default=u'New', nullable=False),
-)
-# Was harvested_document
-harvest_object_table = Table('harvest_object', metadata,
- Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
- Column('guid', types.UnicodeText, default=''),
- Column('created', DateTime, default=datetime.datetime.utcnow),
- Column('content', types.UnicodeText, nullable=True),
- Column('harvest_job_id', types.UnicodeText, ForeignKey('harvest_job.id')),
- Column('fetch_started', DateTime),
- Column('fetch_finished', DateTime),
- Column('retry_times',types.Integer),
- Column('package_id', types.UnicodeText, ForeignKey('package.id'), nullable=True),
-)
-# New table
-harvest_gather_error_table = Table('harvest_gather_error',metadata,
- Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
- Column('harvest_job_id', types.UnicodeText, ForeignKey('harvest_job.id')),
- Column('message', types.UnicodeText),
- Column('created', DateTime, default=datetime.datetime.utcnow),
-)
-# New table
-harvest_object_error_table = Table('harvest_object_error',metadata,
- Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
- Column('harvest_object_id', types.UnicodeText, ForeignKey('harvest_object.id')),
- Column('message',types.UnicodeText),
- Column('stage', types.UnicodeText),
- Column('created', DateTime, default=datetime.datetime.utcnow),
-)
+def make_harvest_tables():
-mapper(
- HarvestSource,
- harvest_source_table,
- properties={
- 'jobs': relation(
- HarvestJob,
- backref=u'source',
- order_by=harvest_job_table.c.created,
- ),
- },
-)
+ global harvest_source_table
+ global harvest_job_table
+ global harvest_object_table
+ global harvest_gather_error_table
-mapper(
- HarvestJob,
- harvest_job_table,
-)
+ harvest_source_table = Table('harvest_source', metadata,
+ Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
+ Column('url', types.UnicodeText, nullable=False),
+ Column('description', types.UnicodeText, default=u''),
+ Column('config', types.UnicodeText, default=u''),
+ Column('created', DateTime, default=datetime.datetime.utcnow),
+ Column('type',types.UnicodeText,nullable=False),
+ Column('active',types.Boolean,default=True),
+ Column('user_id', types.UnicodeText, default=u''),
+ Column('publisher_id', types.UnicodeText, default=u''),
+ )
+ # Was harvesting_job
+ harvest_job_table = Table('harvest_job', metadata,
+ Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
+ Column('created', DateTime, default=datetime.datetime.utcnow),
+ Column('gather_started', DateTime),
+ Column('gather_finished', DateTime),
+ Column('source_id', types.UnicodeText, ForeignKey('harvest_source.id')),
+ Column('status', types.UnicodeText, default=u'New', nullable=False),
+ )
+ # Was harvested_document
+ harvest_object_table = Table('harvest_object', metadata,
+ Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
+ Column('guid', types.UnicodeText, default=''),
+ Column('created', DateTime, default=datetime.datetime.utcnow),
+ Column('content', types.UnicodeText, nullable=True),
+ Column('harvest_job_id', types.UnicodeText, ForeignKey('harvest_job.id')),
+ Column('fetch_started', DateTime),
+ Column('fetch_finished', DateTime),
+ Column('retry_times',types.Integer),
+ Column('package_id', types.UnicodeText, ForeignKey('package.id'), nullable=True),
+ )
+ # New table
+ harvest_gather_error_table = Table('harvest_gather_error',metadata,
+ Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
+ Column('harvest_job_id', types.UnicodeText, ForeignKey('harvest_job.id')),
+ Column('message', types.UnicodeText),
+ Column('created', DateTime, default=datetime.datetime.utcnow),
+ )
+ # New table
+ harvest_object_error_table = Table('harvest_object_error',metadata,
+ Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
+ Column('harvest_object_id', types.UnicodeText, ForeignKey('harvest_object.id')),
+ Column('message',types.UnicodeText),
+ Column('stage', types.UnicodeText),
+ Column('created', DateTime, default=datetime.datetime.utcnow),
+ )
-mapper(
- HarvestObject,
- harvest_object_table,
- properties={
- 'package':relation(
- Package,
- backref='harvest_objects',
- ),
- 'job': relation(
- HarvestJob,
- backref=u'objects',
- ),
- },
-)
+ mapper(
+ HarvestSource,
+ harvest_source_table,
+ properties={
+ 'jobs': relation(
+ HarvestJob,
+ backref=u'source',
+ order_by=harvest_job_table.c.created,
+ ),
+ },
+ )
-mapper(
- HarvestGatherError,
- harvest_gather_error_table,
- properties={
- 'job':relation(
- HarvestJob,
- backref='gather_errors'
- ),
- },
-)
+ mapper(
+ HarvestJob,
+ harvest_job_table,
+ )
-mapper(
- HarvestObjectError,
- harvest_object_error_table,
- properties={
- 'object':relation(
- HarvestObject,
- backref='errors'
- ),
- },
-)
+ mapper(
+ HarvestObject,
+ harvest_object_table,
+ properties={
+ 'package':relation(
+ Package,
+ backref='harvest_objects',
+ ),
+ 'job': relation(
+ HarvestJob,
+ backref=u'objects',
+ ),
+ },
+ )
+
+ mapper(
+ HarvestGatherError,
+ harvest_gather_error_table,
+ properties={
+ 'job':relation(
+ HarvestJob,
+ backref='gather_errors'
+ ),
+ },
+ )
+
+ mapper(
+ HarvestObjectError,
+ harvest_object_error_table,
+ properties={
+ 'object':relation(
+ HarvestObject,
+ backref='errors'
+ ),
+ },
+ )
Repository URL: https://bitbucket.org/okfn/ckanext-harvest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list