Skip to content

Commit

Permalink
- Better non exportable types [kiorky]
Browse files Browse the repository at this point in the history
- better references restore [kiorky]
- Support for  Products.ATExtensions formattable names field [kiorky]
- Again, better error traces [kiorky]
  • Loading branch information
pg0lfuser committed Apr 12, 2013
1 parent f03e043 commit 9b1183b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 14 deletions.
1 change: 1 addition & 0 deletions Products/csvreplicata/AppConfig.py
Expand Up @@ -25,5 +25,6 @@
'Products.AttachmentField.AttachmentField.AttachmentField': {'handler_class' : file.CSVFile(), 'file' : True},
'Products.Maps.field.LocationField': {'handler_class' : maps.CSVMap(), 'file' : False},
'Products.ATBackRef.BackReferenceField': {'handler_class' : reference.CSVReference(), 'file' : False},
'Products.ATExtensions.field.formattablenames.FormattableNamesField': {'handler_class' : base.CSVPateFormattableNames(), 'file' : False},
}

7 changes: 6 additions & 1 deletion Products/csvreplicata/browser/manager.py
Expand Up @@ -117,7 +117,12 @@ def doImport(self):
self.writeMessageOnPage(["All lines imported, %d object(s) created, %d object(s) modified." % (count_created, count_modified)])
self.writeMessageOnPage(["This CSV file has been produced on "+str(export_date)+". To avoid inconsistencies, do not import this file anymore. It is preferable to export a new one."])
else:
self.writeMessageOnPage(["%d object(s) created, %d object(s) modified." % (count_created, count_modified)])
for i in errors:
logger.error(i)
errors.insert(
0,
"%d object(s) created, %d object(s) modified." % (
count_created, count_modified))
self.writeMessageOnPage(errors, error = True)

self.request.RESPONSE.redirect(self.context.absolute_url()+'/@@csvreplicata')
Expand Down
45 changes: 45 additions & 0 deletions Products/csvreplicata/handlers/base.py
Expand Up @@ -22,9 +22,20 @@

from Products.csvreplicata.exceptions import *

try:
from Products.ATExtensions import field
HAS_PATE = True
except:
HAS_PATE=False

import logging
logger = logging.getLogger('HANDLER')

try:
import json
except:
import simplejson as json


def get_padded_year(v, format):
yformat = format.replace('%Y', '_YEARBEGIN_%Y_YEAREND_')
Expand Down Expand Up @@ -204,8 +215,11 @@ def get(self, obj, field, context=None):
if v is None:
return ''
else:
if isinstance(v, (tuple, set)):
v = list(v)
return '\n'.join(v)


def set(self, obj, field, value, context=None):
if value=='':
value = []
Expand Down Expand Up @@ -274,3 +288,34 @@ def set(self, obj, field, value, context=None):
except DateTime.DateTimeError, e:
raise csvreplicataException, v + " is not a valid date/time"


class CSVPateFormattableNames(CSVLines):
""" """
def get(self, obj, field, context=None):
"""
"""
v = obj.Schema().getField(field).get(obj)
if v is None:
return ''
else:
return '\n'.join([repr(a) for a in v])

def set(self, obj, field, value, context=None):
if value == '':
value = None
else:
value = value.split('\n')
values = []
for v in [v for v in value if v.strip()]:
if v:
if (
v[-1] == "}"
and v[0] == "{"
and 'middlename' in v
and 'firstname' in v
and 'lastname' in v
):
values.append(eval(v))
if values:
self.store(field, obj, values)

28 changes: 17 additions & 11 deletions Products/csvreplicata/replicator.py
Expand Up @@ -11,6 +11,7 @@

import logging
from DateTime import DateTime
import traceback
from time import strptime

from pprint import pprint
Expand Down Expand Up @@ -391,19 +392,21 @@ def _csvimport(self,

except csvreplicataNonExistentContainer, e:
needs_another_loop = True

except csvreplicataMissingFileInArchive, e:
errors.append("Error in line "+str(line) + ": %s" % (e))
trace = traceback.format_exc()
errors.append("Error in line "+str(line) + ": %s %s" % (e, trace))

except Exception, e:
errors.append("Error in line "+str(line) + \
": %s" % (e))
trace = traceback.format_exc()
errors.append("Error in line "+str(line) + ": %s %s" % (e, trace))
except csvreplicataMissingFileInArchive, e:
errors.append("Error in line "+str(line) + ": %s" % (e))
#raise Exception, "Error in csv file line "+str(line) + ": %s \n%s" % (e, row)
else:
label_line = False
# commit at the end of the loop if we want partial commits
if partial_commit_number and (bool(needs_another_loop)==True):
transaction.commit()
transaction.commit()
self.flag = needs_another_loop
return (count_created, count_modified, export_date, errors)

Expand Down Expand Up @@ -546,18 +549,19 @@ def importObject(self,
handler += '\thandler: %s\n' % hc.__class__
if hfile:
handler += '\thandlerfile: %s\n' % hfile

trace = traceback.format_exc()
logger.warning(
'Oops:\n'
'%s'
'%s'
'%s'
'\tException: %s\n'
'\tException: %s\n%s\n'
'\tMessage: %s\n' % (
where,
what,
handler,
e.__class__,
trace,
e
)
)
Expand Down Expand Up @@ -610,11 +614,13 @@ def importObject(self,
'/'.join(obj.getPhysicalPath()),
obj.Title(),
)
trace = traceback.format_exc()
logger.warning(
'Plugin Oops:\n'
'%s\n'
'%s\n'
'%s\n' % (e, pluginid, where)
'%s\n'
'%s\n' % (e, pluginid, where, trace)
)
return (is_new_object, modified, incomplete)

Expand Down Expand Up @@ -769,7 +775,7 @@ def export_plain(self,
# search plugins that can add cells to our objects
plugins = list(
getAdapters(
[self, obj],
[self, obj],
ICSVReplicataExportImportPlugin))
type_info = str(obj.getTypeInfo().id)
# get type fields
Expand Down Expand Up @@ -844,7 +850,7 @@ def export_split(self,
if obj == self.context : continue
# search plugins that can add cells to our objects
plugins = list(
getAdapters([self, obj],
getAdapters([self, obj],
ICSVReplicataExportImportPlugin))
type_info = str(obj.getTypeInfo().id)
if not(type_info == currenttype):
Expand Down Expand Up @@ -915,7 +921,7 @@ def getTypeFields(self, type):
('type' , 'Content type')]
types = {}
try:
attool = getToolByName(self.context,
attool = getToolByName(self.context,
'archetype_tool')
types = getPortalTypes(self.context)
except Exception, e:
Expand Down
6 changes: 4 additions & 2 deletions docs/HISTORY.txt
Expand Up @@ -5,8 +5,10 @@ Changelog
1.1.10 (unreleased)
-------------------

- Better non exportable types[kiorky]
- "better references restore [kiorky]
- Better non exportable types [kiorky]
- better references restore [kiorky]
- Support for Products.ATExtensions formattable names field [kiorky]
- Again, better error traces [kiorky]

1.1.8 (2012-05-28)
------------------
Expand Down

0 comments on commit 9b1183b

Please sign in to comment.