Logging to a log file
This commit is contained in:
parent
033e7840b2
commit
a74e01ca6d
|
@ -14,6 +14,7 @@ from Products.CMFCore.WorkflowCore import WorkflowException
|
|||
|
||||
class Migrate(BrowserView):
|
||||
def __call__(self):
|
||||
self.logfile = file('/tmp/migration.log', 'a+')
|
||||
if self.request['REQUEST_METHOD'] == 'GET':
|
||||
filename = self.request.form.get('filename')
|
||||
if not filename:
|
||||
|
@ -27,10 +28,11 @@ class Migrate(BrowserView):
|
|||
workflow_tool = getToolByName(self.context, 'portal_workflow')
|
||||
plone_tool = getToolByName(self.context, 'plone_utils')
|
||||
|
||||
print 'I: Processing', doc.get('id')
|
||||
print 'Processing', doc.get('id')
|
||||
print >> self.logfile, 'I: Processing', doc.get('id')
|
||||
|
||||
if doc.get('meta_type') == 'PFBArbitralCourt' and doc.get('id').startswith('cour-d-arbitrage'):
|
||||
print 'I: skipped, arbitral court document'
|
||||
print >> self.logfile, 'I: skipped, arbitral court document'
|
||||
return 'Arbitral Court documents are not to be imported\n'
|
||||
|
||||
# first step is to create a "courrier entrant" object
|
||||
|
@ -74,7 +76,7 @@ class Migrate(BrowserView):
|
|||
}.get(doc.get('meta_type'))]
|
||||
|
||||
if ob.categorie_de_courrier is None:
|
||||
print 'W: failed to get a category'
|
||||
print >> self.logfile, 'W: failed to get a category'
|
||||
|
||||
ob.expediteur = []
|
||||
shipper_id = None
|
||||
|
@ -90,7 +92,7 @@ class Migrate(BrowserView):
|
|||
if doc.get('authors'):
|
||||
shipper_id = self.get_ministry(doc.get('authors')[0])
|
||||
else:
|
||||
print 'W: document without an author'
|
||||
print >> self.logfile, 'W: document without an author'
|
||||
elif doc.get('meta_type') in ('PFBChallenge',
|
||||
'PFBCurrentEventsQuestion', 'PFBOralRequest',
|
||||
'PFBProposal', 'PFBWriteRequest'):
|
||||
|
@ -98,7 +100,7 @@ class Migrate(BrowserView):
|
|||
if doc.get('authors'):
|
||||
shipper_id = self.get_deputy(doc.get('authors')[0])
|
||||
else:
|
||||
print 'W: document without an author'
|
||||
print >> self.logfile, 'W: document without an author'
|
||||
|
||||
if shipper_id:
|
||||
ob.expediteur.append(shipper_id)
|
||||
|
@ -120,7 +122,7 @@ class Migrate(BrowserView):
|
|||
except WorkflowException:
|
||||
pass
|
||||
except Exception, e:
|
||||
print 'E: Exception %r' % e
|
||||
print >> self.logfile, 'E: Exception %r' % e
|
||||
raise
|
||||
|
||||
second_object_typename = {
|
||||
|
@ -140,7 +142,7 @@ class Migrate(BrowserView):
|
|||
'prop_modif_statut': 'proposition_resolution_modificationD'
|
||||
}.get(doc.get('type'))
|
||||
if second_object_typename is None:
|
||||
print 'W: proposal of unknown type'
|
||||
print >> self.logfile, 'W: proposal of unknown type'
|
||||
|
||||
if second_object_typename:
|
||||
# XXX: this is a temporary location, no decision has been taken yet
|
||||
|
@ -183,7 +185,7 @@ class Migrate(BrowserView):
|
|||
except WorkflowException:
|
||||
pass
|
||||
except Exception, e:
|
||||
print 'E: Exception(b) %r' % e
|
||||
print >> self.logfile, 'E: Exception(b) %r' % e
|
||||
raise
|
||||
|
||||
|
||||
|
@ -201,7 +203,11 @@ class Migrate(BrowserView):
|
|||
return 'ministry:college'
|
||||
if not portal.ministres.has_key(author_id):
|
||||
workflow_tool = getToolByName(self.context, 'portal_workflow')
|
||||
lastname, firstname = author.split(',')
|
||||
try:
|
||||
lastname, firstname = author.split(',')
|
||||
except ValueError:
|
||||
print >> self.logfile, 'E: ministry??? (%r)' % author
|
||||
raise
|
||||
portal.ministres.invokeFactory('themis.datatypes.ministry', author_id,
|
||||
firstname=firstname.strip(),
|
||||
lastname=lastname.strip())
|
||||
|
@ -218,11 +224,17 @@ class Migrate(BrowserView):
|
|||
portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
||||
author = unicode(author, 'utf-8')
|
||||
if len(author.split()) > 3:
|
||||
print 'W: author with (too?) many parts:', author
|
||||
if not 'Warnaffe' in author and \
|
||||
not 'Jonghe' in author:
|
||||
print >> self.logfile, 'W: author with (too?) many parts: %r' % author
|
||||
author_id = plone_tool.normalizeString(author)
|
||||
if not portal.deputes.has_key(author_id):
|
||||
workflow_tool = getToolByName(self.context, 'portal_workflow')
|
||||
lastname, firstname = author.split(',')
|
||||
try:
|
||||
lastname, firstname = author.split(',')
|
||||
except ValueError:
|
||||
print >> self.logfile, 'E: deputy??? (%r)' % author
|
||||
raise
|
||||
portal.deputes.invokeFactory('themis.datatypes.deputy', author_id,
|
||||
firstname=firstname.strip(),
|
||||
lastname=lastname.strip())
|
||||
|
|
Reference in New Issue