Ignore:
Timestamp:
05/14/09 23:41:20 (5 years ago)
Author:
brent
Message:

Refactored ccreader and removed ccresourcereader. Refactored imsccreader to be more modular.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • collective.imstransport/trunk/collective/imstransport/utilities/imsinterchange.py

    r197 r199  
    2121    # Helper functions for readPackage 
    2222 
    23     def _createIdFromFile(self, file): 
     23    def createIdFromFile(self, file): 
    2424        """ Get Id from file path """ 
    2525        return file.split('/')[-1] 
    2626 
    27     def _createPathFromFile(self, file): 
     27    def createPathFromFile(self, file): 
    2828        """ Get folder path from file path """ 
    2929        return '/'.join(file.split('/')[:-1]) 
    3030 
    31     def _parseResourceMetadata(self, resourcereader, resourceid): 
    32         """ Read the resource metadata """ 
    33  
    34         resourcereader.readGeneral() 
    35         resourcereader.readLifecycle() 
    36         resourcereader.readMetaMetadata() 
    37         resourcereader.readTechnical() 
    38         resourcereader.readRights() 
    39         customnode = resourcereader.getCustomData('', '') 
    40         if customnode: 
    41             metadict = resourcereader.readCustomMetadata(customnode) 
    42             resourcereader.appendCustomData(metadict) 
    43         return resourcereader.processResourceMetadata() 
    44  
    45     def _parseFile(self, file, objDict, hashref, id, path): 
    46         """ parse a file object and add data to it """ 
    47         objDict[hashref]['file'] = file 
    48         objDict[hashref]['id'] = id 
    49         objDict[hashref]['path'] = path 
    50         objDict[hashref]['type'] = self._determineType(hashref, objDict, file) 
    51         if objDict[hashref].has_key('title') == False: 
    52             objDict[hashref]['title'] = id 
    53  
    54     def _readCustomData(self, prefix, ns, location): 
    55         """  
    56         Hook for reading custom metadata for additional metadata requirements.  
    57         Should return a dictionary of values representing attribute name and value. 
    58         """ 
    59         return {} 
    60  
    61     def _determineType(self, hashref, objDict, filename): 
    62         """ Determine the type of the incoming object """ 
    63  
    64         result = None 
    65         if objDict[hashref].has_key('type') and objDict[hashref]['type']: 
    66             result = objDict[hashref]['type'] 
    67         elif objDict[hashref].has_key('Format') and objDict[hashref]['Format'] in ['text/html', 'text/htm' 'text/plain' 'text/x-rst', 'text/structured']: 
     31    def determineType(self, item, fn): 
     32        result = 'File' 
     33        docmimetypes = ['text/html', 'text/htm' 'text/plain' 'text/x-rst', 'text/structured'] 
     34 
     35        if item.has_key('type'): 
     36            result = type 
     37        elif item.has_key('Format') and item['Format'] in docmimetypes: 
    6838            result = 'Document' 
    69         elif objDict[hashref].has_key('Format') and re.match('^image', objDict[hashref]['Format']): 
     39        elif item.has_key('Format') and 'image' in item['Format']: 
    7040            result = 'Image' 
    7141        else: 
     
    7545            mimetype = mtr.lookupExtension(filename) 
    7646             
    77             if mimetype and mimetype.major() == 'text' and mimetype.minor() == 'html': 
     47            if mimetype in docmimetypes: 
    7848                result = 'Document' 
    79             elif mimetype and mimetype.major() == 'image': 
     49            elif 'image' in mimetype: 
    8050                result = 'Image' 
    81             else: 
    82                 result = 'File' 
    83  
    84         return result 
    85          
     51        return result                     
    8652 
    8753class IMSInterchangeReader(object): 
Note: See TracChangeset for help on using the changeset viewer.