- Timestamp:
- 05/14/09 23:41:20 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
collective.imstransport/trunk/collective/imstransport/utilities/imsinterchange.py
r197 r199 21 21 # Helper functions for readPackage 22 22 23 def _createIdFromFile(self, file):23 def createIdFromFile(self, file): 24 24 """ Get Id from file path """ 25 25 return file.split('/')[-1] 26 26 27 def _createPathFromFile(self, file):27 def createPathFromFile(self, file): 28 28 """ Get folder path from file path """ 29 29 return '/'.join(file.split('/')[:-1]) 30 30 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: 68 38 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']: 70 40 result = 'Image' 71 41 else: … … 75 45 mimetype = mtr.lookupExtension(filename) 76 46 77 if mimetype and mimetype.major() == 'text' and mimetype.minor() == 'html':47 if mimetype in docmimetypes: 78 48 result = 'Document' 79 elif mimetype and mimetype.major() == 'image':49 elif 'image' in mimetype: 80 50 result = 'Image' 81 else: 82 result = 'File' 83 84 return result 85 51 return result 86 52 87 53 class IMSInterchangeReader(object):
Note: See TracChangeset
for help on using the changeset viewer.
