add logging
This commit is contained in:
parent
b3090851da
commit
4b4f9204c3
|
@ -3,6 +3,7 @@
|
|||
import datetime
|
||||
import re
|
||||
import time
|
||||
import logging
|
||||
|
||||
from DateTime.DateTime import DateTime
|
||||
|
||||
|
@ -28,6 +29,7 @@ from plone.registry.interfaces import IRegistry
|
|||
|
||||
from tabellio.config.interfaces import ITabellioSettings
|
||||
|
||||
log = logging.getLogger('Plone')
|
||||
|
||||
class SyncFromPcfDbView(BrowserView):
|
||||
def setup(self):
|
||||
|
@ -179,11 +181,11 @@ class SyncFromPcfDbView(BrowserView):
|
|||
elif st in ('S_CREATED', 'S_DEAD'):
|
||||
obj = getattr(self.persons_folder, new_id)
|
||||
else:
|
||||
print 'unhandled type', st, author_id, new_id
|
||||
log.debug('unhandled type: %s %s %s' % (st, author_id, new_id))
|
||||
self._author_intids[author_id] = None
|
||||
return None
|
||||
except AttributeError:
|
||||
print 'missing author:', fullname
|
||||
log.debug('missing author: %s', fullname)
|
||||
self._author_intids[author_id] = None
|
||||
return None
|
||||
author_intid = self.intids.getId(obj)
|
||||
|
@ -208,7 +210,7 @@ class SyncFromPcfDbView(BrowserView):
|
|||
try:
|
||||
obj = getattr(folder, doc_id)
|
||||
except AttributeError:
|
||||
print 'missing doc', doc_id
|
||||
log.debug('missing doc: %s', doc_id)
|
||||
return None, None
|
||||
try:
|
||||
return obj, self.intids.getId(obj)
|
||||
|
@ -323,6 +325,7 @@ class SyncFromPcfDbView(BrowserView):
|
|||
|
||||
timestamp = self.request.form.get('timestamp')
|
||||
objects = self.request.form.get('objects', '').split(',')
|
||||
log.info('sync: start [%r] [%r]' % (timestamp, objects))
|
||||
report = []
|
||||
for object in ('polgroups', 'sessions', 'deputies', 'ministries', 'persons', 'commissions',
|
||||
'documents', 'dossiers', 'questions', 'reunions', 'deptables', 'thesaurus'):
|
||||
|
@ -332,7 +335,8 @@ class SyncFromPcfDbView(BrowserView):
|
|||
t0 = time.time()
|
||||
result = getattr(self, 'sync_'+object)(timestamp)
|
||||
duration = time.time() - t0
|
||||
report.append('%-14s: %6s [%s]' % (object, result, format_duration(duration)))
|
||||
report.append('%-14s: %6s [%s]' % (object, result, format_duration(duration))
|
||||
log.info('sync: %-14s: %6s [%s]' % (object, result, format_duration(duration)))
|
||||
transaction.commit()
|
||||
|
||||
print '\n'.join(report)
|
||||
|
@ -582,7 +586,7 @@ class SyncFromPcfDbView(BrowserView):
|
|||
elif type in ('M_MINT', 'M_CMPT'):
|
||||
continue
|
||||
else:
|
||||
print 'unknown type:', type
|
||||
log.debug('unknown person type: %s', type)
|
||||
continue
|
||||
|
||||
start_str = debut.strftime('%d/%m/%Y')
|
||||
|
@ -863,10 +867,10 @@ class SyncFromPcfDbView(BrowserView):
|
|||
}.get(doctype)
|
||||
|
||||
if intit is None:
|
||||
print 'missing intit, skipping', doc_id, ' (type was %s)' % doctype
|
||||
log.debug('missing intit, skipping %s (type was %s)', doc_id, doctype)
|
||||
continue
|
||||
|
||||
print 'doc id:', doc_id
|
||||
log.debug('doc id: %s', doc_id)
|
||||
|
||||
new_one = False
|
||||
if not hasattr(self.documents_folder, doc_id):
|
||||
|
@ -896,7 +900,7 @@ class SyncFromPcfDbView(BrowserView):
|
|||
authors = [self.get_author_intid(x) for x in authors]
|
||||
object.authors = [RelationValue(x) for x in authors if x]
|
||||
if len(object.authors) != len(authors):
|
||||
print ' different number of authors'
|
||||
log.debug('different number of authors')
|
||||
else:
|
||||
object.authors = []
|
||||
if polgroups:
|
||||
|
@ -969,12 +973,14 @@ class SyncFromPcfDbView(BrowserView):
|
|||
row = meeting_cursor.fetchone()
|
||||
if row:
|
||||
meeting_id = row[0]
|
||||
print ' going to update meeting:', meeting_id
|
||||
log.debug('going to update meeting %s with doc %s', meeting_id, object.no)
|
||||
if hasattr(self.parlevents_folder, meeting_id):
|
||||
meeting = getattr(self.parlevents_folder, meeting_id)
|
||||
if meeting.cri is None:
|
||||
doc_intid = self.intids.getId(object)
|
||||
meeting.cri = RelationValue(doc_intid)
|
||||
else:
|
||||
log.debug('not meeting found for %s', object.no)
|
||||
meeting_cursor.close()
|
||||
|
||||
if count % 100 == 0:
|
||||
|
@ -1014,7 +1020,7 @@ class SyncFromPcfDbView(BrowserView):
|
|||
count += 1
|
||||
dos_id, state, dostype, sess, no, intit, authors, curcom, polgroups, topics = row
|
||||
|
||||
print 'dos id:', dos_id
|
||||
logging.debug('dos id: %s', dos_id)
|
||||
|
||||
new_one = False
|
||||
if not hasattr(self.dossiers_folder, dos_id):
|
||||
|
@ -1030,7 +1036,7 @@ class SyncFromPcfDbView(BrowserView):
|
|||
authors = [self.get_author_intid(x) for x in authors]
|
||||
object.authors = [RelationValue(x) for x in authors if x]
|
||||
if len(object.authors) != len(authors):
|
||||
print ' different number of authors'
|
||||
log.debug('different number of authors')
|
||||
else:
|
||||
object.authors = []
|
||||
|
||||
|
@ -1083,7 +1089,7 @@ class SyncFromPcfDbView(BrowserView):
|
|||
break
|
||||
count += 1
|
||||
dos_id, state, dostype, sess, no, intit, authors, polgroups, topics = row
|
||||
print 't_qx/dos id:', dos_id
|
||||
log.debug('t_qx/dos id: %s', dos_id)
|
||||
if not hasattr(self.questions_folder, dos_id):
|
||||
self.questions_folder.invokeFactory('tabellio.documents.question', dos_id)
|
||||
object = getattr(self.questions_folder, dos_id)
|
||||
|
@ -1100,7 +1106,7 @@ class SyncFromPcfDbView(BrowserView):
|
|||
authors = [self.get_author_intid(x) for x in authors]
|
||||
object.authors = [RelationValue(x) for x in authors if x]
|
||||
if len(object.authors) != len(authors):
|
||||
print ' different number of authors'
|
||||
log.debug('different number of authors')
|
||||
else:
|
||||
object.authors = []
|
||||
|
||||
|
@ -1321,7 +1327,7 @@ class SyncFromPcfDbView(BrowserView):
|
|||
row = doc_cursor.fetchone()
|
||||
doc_cursor.close()
|
||||
if row is None:
|
||||
print 'failed to get document', sess, doctype, docno
|
||||
log.debug('failed to get document, %s %s %s', sess, doctype, docno)
|
||||
else:
|
||||
doc_id, docsess = row
|
||||
doc, doc_intid = self.get_document_and_intid(doc_id)
|
||||
|
|
Reference in New Issue