take tables out of global scope at import time

This commit is contained in:
David Raznick 2011-05-31 18:02:07 +01:00
parent 2b98080266
commit 264b606c48
1 changed files with 113 additions and 97 deletions

View File

@ -19,9 +19,18 @@ __all__ = [
]
harvest_source_table = None
harvest_job_table = None
harvest_object_table = None
harvest_gather_error_table = None
harvest_object_error_table = None
def setup():
if harvest_source_table is None:
create_harvester_tables()
metadata.create_all()
class HarvestError(Exception):
pass
@ -92,8 +101,15 @@ class HarvestObjectError(HarvestDomainObject):
'''
pass
def create_harvester_tables():
harvest_source_table = Table('harvest_source', metadata,
global harvest_source_table
global harvest_job_table
global harvest_object_table
global harvest_gather_error_table
global harvest_object_error_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''),
@ -103,18 +119,18 @@ harvest_source_table = Table('harvest_source', metadata,
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,
)
# 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,
)
# 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('gathered', DateTime, default=datetime.datetime.utcnow),
@ -125,24 +141,24 @@ harvest_object_table = Table('harvest_object', metadata,
Column('retry_times',types.Integer),
Column('harvest_job_id', types.UnicodeText, ForeignKey('harvest_job.id')),
Column('package_id', types.UnicodeText, ForeignKey('package.id'), nullable=True),
)
# New table
harvest_gather_error_table = Table('harvest_gather_error',metadata,
)
# 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,
)
# 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(
mapper(
HarvestSource,
harvest_source_table,
properties={
@ -152,14 +168,14 @@ mapper(
order_by=harvest_job_table.c.created,
),
},
)
)
mapper(
mapper(
HarvestJob,
harvest_job_table,
)
)
mapper(
mapper(
HarvestObject,
harvest_object_table,
properties={
@ -172,9 +188,9 @@ mapper(
backref=u'objects',
),
},
)
)
mapper(
mapper(
HarvestGatherError,
harvest_gather_error_table,
properties={
@ -183,9 +199,9 @@ mapper(
backref='gather_errors'
),
},
)
)
mapper(
mapper(
HarvestObjectError,
harvest_object_error_table,
properties={
@ -194,4 +210,4 @@ mapper(
backref='errors'
),
},
)
)