Changeset 4220 for waeup/branches/ulif-rewrite/src
- Timestamp:
- 8 Jun 2009, 16:54:29 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/utils/importexport.py
r4158 r4220 7 7 from xml.dom.minidom import Document, getDOMImplementation 8 8 from zope.interface import Interface 9 from waeup.csvfile.interfaces import ICSVFile 9 10 from waeup.interfaces import (IWAeUPObject, IWAeUPExporter, IWAeUPXMLExporter, 10 11 IWAeUPXMLImporter, IWAeUPCSVImporter) … … 86 87 return obj 87 88 88 class CSVImporter(grok.Adapter): 89 grok.context(IWAeUPObject) 89 90 class CSVImporter(grok.MultiAdapter): 91 grok.adapts(ICSVFile, IWAeUPObject) 90 92 grok.provides(IWAeUPCSVImporter) 91 grok.baseclass() # We don't want this base to be registered really.92 column_terms = [] # The column terms supported by this importer 93 94 def __init__(self, context):95 self. context = context96 97 def doImport(self , filepath):93 grok.baseclass() # We don't want this base to be registered really. 94 95 def __init__(self, csvfile, receiver): 96 self.csvfile = csvfile 97 self.receiver = receiver 98 99 def doImport(self): 98 100 pass 99 100 def getData(self, filepath):101 result = readFile(open(filepath, 'rb'))102 return result103 104 def validate(self, filepath):105 self.checkHeader(filepath)106 self.getData(filepath)107 return True108 109 def checkHeader(self, filepath):110 missing = []111 headerline = ''112 113 # Extract the header fields...114 for line in open(filepath, 'rb'):115 headerline = line116 if len(headerline.strip()) == 0:117 continue # Ignore leading empty lines...118 break # We only want the first line...119 tmpfile = StringIO(headerline)120 headerfields = readFile(tmpfile)[0]121 122 # Find missing header fields...123 for key in self.column_terms:124 if key not in headerfields:125 missing.append(key)126 if len(missing):127 raise KeyError(128 'Validation Error: the follwing '129 'columns could not be found: %s' % (', '.join(missing))130 )131 return
Note: See TracChangeset for help on using the changeset viewer.