Changeset 4224 for waeup


Ignore:
Timestamp:
8 Jun 2009, 17:00:37 (15 years ago)
Author:
uli
Message:

Make use of new CSV file framework.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/datacenter.py

    r4190 r4224  
    1010import grok
    1111from datetime import datetime
    12 from zope.component import getUtility
     12from zope.component import getUtility, getMultiAdapter
    1313from zope.interface import Interface
     14from waeup.csvfile import getCSVFile
    1415from waeup.interfaces import IWAeUPObject, IWAeUPCSVImporter, ICSVDataReceivers
    1516from waeup.utils.helpers import copyFileSystemTree
     
    5152        result = []
    5253        receivers = self.getReceivers()
     54        files = self.getFiles()
    5355        for receiver in receivers:
    54             try:
    55                 importer = IWAeUPCSVImporter(receiver)
    56                 result.append(importer)
    57             except:
    58                 pass
     56            for file in files:
     57                wrapped_file = getCSVFile(file.context)
     58                try:
     59                    importer = getMultiAdapter((wrapped_file, receiver),
     60                                           IWAeUPCSVImporter)
     61                    result.append(importer)
     62                except:
     63                    # No multi-adapter for this combination available...
     64                    pass
    5965        return result
    6066   
     
    97103                attr = getattr(obj, attr_name)
    98104                # This might fail...
    99                 IWAeUPCSVImporter(attr)
     105                #IWAeUPCSVImporter(attr)
    100106                result.append(attr)
    101107            except:
     
    118124            possible_importers = []
    119125            for importer in importers:
    120                 try:
    121                     # We could also try a complete parse...
    122                     importer.checkHeader(filedescr.context)
    123                 except:
    124                     continue
    125126                importer_context = (
    126                     importer, self.getReceiverId(importer.context))
     127                    importer, self.getReceiverId(importer.receiver))
    127128                possible_importers.append(importer_context)
    128129            if len(possible_importers) == 0:
     
    153154        return 'z%s' % struct.unpack('>Q', oid)[0]
    154155
    155     def doImport(self, csvfile, receiverid, clear=None):
     156    def doImport(self, path, receiverid, clear=None):
    156157        receivers = self.getReceiverIds()
    157158        if receiverid not in receivers.keys():
    158159            raise ValueError('The requested data receiver cannot be found.')
    159160        receiver = receivers[receiverid]
    160         importer = IWAeUPCSVImporter(receiver)
     161        filewrapper = getCSVFile(path)
     162        if filewrapper is None:
     163            raise ValueError('Format of CSV file not supported.')
     164        importer = getMultiAdapter((filewrapper, receiver), IWAeUPCSVImporter)
    161165        if clear is not None:
    162             importer.doImport(csvfile, clear_old_data=clear)
     166            importer.doImport(clear_old_data=clear)
    163167        else:
    164             importer.doImport(csvfile)
     168            importer.doImport()
    165169        return
    166170
Note: See TracChangeset for help on using the changeset viewer.