Changeset 755
- Timestamp:
- 02/25/11 01:19:18 (2 years ago)
- Location:
- Products.ecmigration/trunk/Products/ecmigration
- Files:
-
- 3 edited
-
MigrationTool.py (modified) (1 diff)
-
__init__.py (modified) (1 diff)
-
migrate.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Products.ecmigration/trunk/Products/ecmigration/MigrationTool.py
r754 r755 67 67 security.declareProtected(ManagePortal, 'importContent') 68 68 def importContent(self, REQUEST=None): 69 mig = ECMigration(self) 69 """ Import migrated content into eduCommons """ 70 mig = ECMigration(self.portal_url.getPortalObject()) 70 71 mig.importContent() 71 72 72 def exportContent(self, REQUEST=None): 73 mig = ECMigration(self) 73 security.declareProtected(ManagePortal, 'exportContent') 74 def exportContent(self, REQUEST=None, filename=None): 75 """ Export content from eduCommons """ 76 mig = ECMigration(self.portal_url.getPortalObject()) 74 77 mig.exportContent() 75 78 -
Products.ecmigration/trunk/Products/ecmigration/__init__.py
r754 r755 35 35 import MigrationTool 36 36 37 #from Products.GenericSetup import profile_registry38 #from Products.GenericSetup import EXTENSION39 #from Products.CMFPlone.interfaces import IPloneSiteRoot40 #41 #profile_registry.registerProfile('default',42 # 'ecmigration',43 # 'Migration tool for eduCommons',44 # 'profiles/default',45 # 'ecmigration',46 # EXTENSION,47 # for_=IPloneSiteRoot)48 49 37 tools = (MigrationTool.ECMigrationTool,) 50 38 -
Products.ecmigration/trunk/Products/ecmigration/migrate.py
r754 r755 121 121 } 122 122 123 id_transforms = { 124 'About':'about', 125 'Help':'help', 126 } 127 128 129 123 130 def __init__(self, context): 124 131 self.context = context … … 160 167 oid = '/'.join(data['filename'].split(os.sep)) 161 168 print oid 162 context = self.portal_url.getPortalObject() 163 obj = self.getObjectByPath(context, oid) 164 if not obj: 165 # Object does not exist, create it 166 parent = self.getObjectByPath(context, '/'.join(oid.split('/')[:-1])) 167 if parent: 168 nid = oid.split('/')[-1] 169 _createObjectByType(data['type'], parent, id=nid) 170 obj = getattr(parent, nid) 171 if obj: 172 self.updateObject(obj, data) 169 try: 170 obj = self.getObjectByPath(oid) 171 except TypeError: 172 pass 173 else: 174 if not obj: 175 # Object does not exist, create it 176 parent = self.getObjectByPath('/'.join(oid.split('/')[:-1])) 177 if parent: 178 nid = oid.split('/')[-1] 179 _createObjectByType(data['type'], parent, id=nid) 180 obj = getattr(parent, nid) 181 if obj: 182 if getattr(obj, 'getId', None): 183 self.updateObject(obj, data) 173 184 174 185 def updateObject(self, obj, data): 175 186 """ Update the object with the new settings """ 176 187 for x in data['fields']: 177 obj.getField(x).set(obj, data['fields'][x]) 188 try: 189 field = obj.getField(x) 190 except AttributeError: 191 import pdb; pdb.set_trace() 192 if field: 193 field.set(obj, data['fields'][x]) 178 194 obj.workflow_history = data['workflowhistory'] 179 195 if data.has_key('rightsholder'): … … 194 210 order = ICourseOrder(obj) 195 211 order.setPositionInCourse(data['courseorder']) 196 obj.reindexObject() 197 198 def getObjectByPath(self, context, path): 212 try: 213 obj.reindexObject() 214 except AttributeError: 215 import pdb; pdb.set_trace() 216 217 def getObjectByPath(self, path): 199 218 """ Return an object via its path """ 200 219 try: 201 obj = context.restrictedTraverse(path)220 obj = self.context.restrictedTraverse(path) 202 221 except KeyError: 203 222 obj = None … … 215 234 brains = self.context.portal_catalog(path={'query':'/', 'depth':2,},) 216 235 tf = TarArchiveManager(fn, 'w:bz2') 217 #self.exportUsers(context, tf)236 self.exportUsers(context, tf) 218 237 self.exportObjects(brains, tf) 219 #for x in brains:220 # print x.getPath()221 # self.exportObject(x, tf)222 238 tf.close() 223 224 def exportObjects(self, brains, tf):225 for x in brains:226 self.exportObject(x, tf)227 if x.is_folderish:228 brains = self.context.portal_catalog(path={'query':x.getPath(), 'depth':1,},)229 self.exportObjects(brains, tf)230 239 231 240 def exportUsers(self, portal, archive): … … 243 252 archive.addFile(fn, objstore, float(DateTime())) 244 253 254 def exportObjects(self, brains, tf): 255 for x in brains: 256 self.exportObject(x, tf) 257 if x.is_folderish: 258 brains = self.context.portal_catalog(path={'query':x.getPath(), 'depth':1,},) 259 self.exportObjects(brains, tf) 260 245 261 def exportObject(self, brain, archive): 246 262 """ Export an object """ 247 263 fn = self._getPath(brain) 248 264 print fn 265 objstore = { 'filename':fn } 249 266 obj = brain.getObject() 250 objstore = { 'filename':fn }251 267 self._storeData(obj, objstore) 252 268 lmod = obj.getRawModification_date() … … 261 277 opath = brain.getPath() 262 278 fn = opath.split('/') 279 self._transformId(fn) 263 280 return os.sep.join(fn[1:]) 264 281 265 282 def _storeData(self, obj, objstore): 266 283 """ Export Object Metadata """ 267 objstore['type'] = self.transformType(obj.portal_type) 284 objstore['type'] = self._transformType(obj.portal_type) 285 # Get field data 268 286 objstore['fields'] = {} 269 287 for x in obj.Schema().fields(): … … 271 289 if 'id' != fid: 272 290 if fid in ['file', 'image']: # and 'ATBlob' == obj.meta_type: 291 # Object is a file, must get data from the file 292 # In order to pickle it 273 293 objstore['fields'][fid] = x.get(obj).data 274 294 else: 275 objstore['fields'][fid] = x.get(obj) 295 if 'clearedCopyright' == fid: 296 # if clearedcopyright flag is stored as a field 297 # move it to annotations instead 298 objstore['clearedcopyright'] = x.get(obj) 299 else: 300 # Use the usual method to get the field data 301 objstore['fields'][fid] = x.get(obj) 302 # Get non field related data 276 303 objstore['owner'] = obj.getOwner().getId() 277 304 objstore['workflowhistory'] = obj.workflow_history 305 # Get annotation related data 278 306 if ILicensable.providedBy(obj): 279 307 lic = ILicense(obj) … … 293 321 objstore['courseorder'] = order.getPositionInCourse() 294 322 295 def transformType(self, ptype):323 def _transformType(self, ptype): 296 324 """ Change type """ 297 325 if self.transforms.has_key(ptype): … … 299 327 else: 300 328 return ptype 329 330 def _transformId(self, fn): 331 """ Change IDs """ 332 if len(fn) > 1 and self.id_transforms.has_key(fn[1]): 333 import pdb; pdb.set_trace() 334 fn[1] = self.id_transforms[fn[1]]
Note: See TracChangeset
for help on using the changeset viewer.
