[ckan-changes] commit/ckanext-harvest: kindly: take tables out of global scope at import time

Bitbucket commits-noreply at bitbucket.org
Tue May 31 17:02:26 UTC 2011


1 new changeset in ckanext-harvest:

http://bitbucket.org/okfn/ckanext-harvest/changeset/f9d8f1d3d95c/
changeset:   f9d8f1d3d95c
branches:    
user:        kindly
date:        2011-05-31 19:02:07
summary:     take tables out of global scope at import time
affected #:  1 file (815 bytes)

--- a/ckanext/harvest/model/__init__.py	Fri May 20 13:50:15 2011 +0100
+++ b/ckanext/harvest/model/__init__.py	Tue May 31 18:02:07 2011 +0100
@@ -19,8 +19,17 @@
 ]
 
 
+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,106 +101,113 @@
     '''
     pass
 
+def create_harvester_tables():
 
-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('gathered', DateTime, default=datetime.datetime.utcnow),
-    Column('fetch_started', DateTime),
-    Column('content', types.UnicodeText, nullable=True),
-    Column('fetch_finished', DateTime),
-    Column('metadata_modified_date', DateTime),
-    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,
-    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),  
-)
+    global harvest_source_table
+    global harvest_job_table
+    global harvest_object_table
+    global harvest_gather_error_table
+    global harvest_object_error_table
 
-mapper(
-    HarvestSource,
-    harvest_source_table,
-    properties={
-        'jobs': relation(
-            HarvestJob,
-            backref=u'source',
-            order_by=harvest_job_table.c.created,
-        ),
-    },
-)
+    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('gathered', DateTime, default=datetime.datetime.utcnow),
+        Column('fetch_started', DateTime),
+        Column('content', types.UnicodeText, nullable=True),
+        Column('fetch_finished', DateTime),
+        Column('metadata_modified_date', DateTime),
+        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,
+        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(
-    HarvestJob,
-    harvest_job_table,
-)
+    mapper(
+        HarvestSource,
+        harvest_source_table,
+        properties={
+            'jobs': relation(
+                HarvestJob,
+                backref=u'source',
+                order_by=harvest_job_table.c.created,
+            ),
+        },
+    )
 
-mapper(
-    HarvestObject,
-    harvest_object_table,
-    properties={
-        'package':relation(
-            Package,
-            backref='harvest_objects',
-        ),
-        'job': relation(
-            HarvestJob,
-            backref=u'objects',
-        ),
-    },
-)
+    mapper(
+        HarvestJob,
+        harvest_job_table,
+    )
 
-mapper(
-    HarvestGatherError,
-    harvest_gather_error_table,
-    properties={
-        'job':relation(
-            HarvestJob,
-            backref='gather_errors'
-        ),
-    },
-)
+    mapper(
+        HarvestObject,
+        harvest_object_table,
+        properties={
+            'package':relation(
+                Package,
+                backref='harvest_objects',
+            ),
+            'job': relation(
+                HarvestJob,
+                backref=u'objects',
+            ),
+        },
+    )
 
-mapper(
-    HarvestObjectError,
-    harvest_object_error_table,
-    properties={
-        'object':relation(
-            HarvestObject,
-            backref='errors'
-        ),
-    },
-)
+    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