Changeset 1605 in products for quintagroup.transmogrifier/branches/ofs/quintagroup/transmogrifier/ofsmanager.py
- Timestamp:
- Jan 29, 2010 2:05:17 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.transmogrifier/branches/ofs/quintagroup/transmogrifier/ofsmanager.py
r1602 r1605 49 49 fields['height'] = getattr(obj, 'height', 0) 50 50 51 if not self.condition(item, context=obj, 52 fprop_info=fields): 53 continue 54 51 55 files['file-properties'] = { 52 56 'name': '.file-properties.xml', … … 96 100 return data 97 101 102 103 class OFSImporterSection(object): 104 classProvides(ISectionBlueprint) 105 implements(ISection) 106 107 def __init__(self, transmogrifier, name, options, previous): 108 self.previous = previous 109 self.context = transmogrifier.context 110 111 self.pathkey = defaultMatcher(options, 'path-key', name, 'path') 112 self.fileskey = defaultMatcher(options, 'files-key', name, 'files') 113 self.contextkey = defaultMatcher(options, 'context-key', name, 'import_context') 114 115 self.condition = Condition(options.get('condition', 'python:True'), 116 transmogrifier, name, options) 117 self.ttt = 0 118 119 def __iter__(self): 120 for item in self.previous: 121 pathkey = self.pathkey(*item.keys())[0] 122 fileskey = self.fileskey(*item.keys())[0] 123 124 if not (pathkey and fileskey): 125 yield item; continue 126 if 'file-properties' not in item[fileskey]: 127 yield item; continue 128 129 path = item[pathkey] 130 obj = self.context.unrestrictedTraverse(path, None) 131 if obj is None: # path doesn't exist 132 yield item; continue 133 134 if obj.meta_type in ["File", "Image"]: 135 if not self.ttt: 136 self.ttt = 1 137 import pdb;pdb.set_trace() 138 try: 139 manifest = item[fileskey]['file-properties']['data'] 140 prop_info = self.parseManifest(manifest) 141 # Update file/image properties 142 if not self.condition(item, context=obj, 143 fprop_info=prop_info): 144 continue 145 for prop_id, prop_val in prop_info.items(): 146 setattr(obj, prop_id, prop_val) 147 148 # Add data for file/image 149 name = prop_info.get('__name__', None) 150 if name is None: 151 continue 152 data = item[fileskey].get(name, None) 153 if data is None: 154 continue 155 obj.data = data['data'] 156 157 except Exception, e: 158 print "Exception in ofsimporter section:" 159 print '-'*60 160 traceback.print_exc() 161 print '-'*60 162 163 yield item 164 165 def parseManifest(self, manifest): 166 doc = minidom.parseString(manifest) 167 props = {} 168 for prop in doc.getElementsByTagName('prop'): 169 prop_id = str(prop.getAttribute('id')) 170 if not prop_id: 171 continue 172 props[prop_id] = str(prop.firstChild.nodeValue.strip()) 173 174 return props
Note: See TracChangeset
for help on using the changeset viewer.