add some debugging and safety measures

This commit is contained in:
Frédéric Péters 2011-12-05 16:40:19 +01:00
parent 82568ec1b7
commit c024b8b3a0
1 changed files with 6 additions and 0 deletions

View File

@ -3,6 +3,7 @@
import cPickle
import os
import datetime
import time
import cStringIO
import xml.etree.ElementTree as ET
@ -522,6 +523,7 @@ class UpdateToBlobs(BrowserView):
class SplitDocNumbers(BrowserView):
def __call__(self):
catalog = getToolByName(self.context, 'portal_catalog')
fd = file('/tmp/archive-numeros.%d' % int(time.time()%10000000), 'w')
for count, brain in enumerate(catalog.search({'portal_type': ['bqrD', 'biqD',
'cr_seanceD', 'ProjetD', 'proposition_decret_reglementD',
'proposition_resolution_modificationD', 'PropositionD',
@ -541,6 +543,7 @@ class SplitDocNumbers(BrowserView):
try:
new_number = re.findall(r'(\d+) \(', attr_value)[0]
except IndexError:
print 'object:', object.id
print 'failed to get doc number for', attr_value
continue
no_suite = None
@ -548,8 +551,10 @@ class SplitDocNumbers(BrowserView):
try:
no_suite = re.findall(r'°\s*(\d+)', attr_value)[0]
except IndexError:
print 'object:', object.id
print 'failed to get suite number for', attr_value
continue
print >> fd, object.id, attr_value
setattr(object, attr, new_number)
if no_suite:
object.numero_suite = no_suite
@ -557,3 +562,4 @@ class SplitDocNumbers(BrowserView):
notify(ObjectModifiedEvent(object))
if count%100 == 0:
transaction.commit()
fd.close()