- Timestamp:
- 26 May 2009, 20:07:37 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/datacenter.py
r4170 r4173 5 5 """ 6 6 import os 7 import shutil 7 8 import sys 8 9 import grok … … 18 19 storage = os.path.join(os.path.dirname(__file__), 'files') 19 20 20 def getImporters(self): 21 """Get a list of all importers available. 22 23 The search for available importers is done in two steps: 24 25 1) Look for a utility providing ICSVDataReceiver, 26 27 2) For every item of that utility: try to get an adapter 28 providing IWAeUPCSVImporter. 29 """ 30 result = [] 21 def getReceivers(self): 31 22 receivers = [] 32 23 curr_obj = getattr(self, '__parent__', None) … … 36 27 break 37 28 curr_obj = getattr(curr_obj, '__parent__', None) 29 return receivers 30 31 def getImporters(self): 32 """Get a list of all importers available. 33 34 The search for available importers is done in two steps: 35 36 1) Look for a utility providing ICSVDataReceiver, 37 38 2) For every item of that utility: try to get an adapter 39 providing IWAeUPCSVImporter. 40 """ 41 result = [] 42 receivers = self.getReceivers() 38 43 for receiver in receivers: 39 44 try: … … 63 68 if not os.path.exists(path): 64 69 raise ValueError('The path given does not exist: %s' % path) 70 if move is True: 71 # copy contents of old location to new one 72 srcdir = self.storage 73 dstdir = path 74 for item in os.listdir(srcdir): 75 if os.path.isdir(item): 76 shutil.copytree(os.path.join(srcdir, item), 77 os.path.join(dstdir, item)) 78 else: 79 shutil.copy2(os.path.join(srcdir, item), dstdir) 80 65 81 self.storage = path 66 82 … … 102 118 except: 103 119 continue 104 possible_importers.append(importer) 120 importer_context = ( 121 importer, self.getReceiverId(importer.context)) 122 possible_importers.append(importer_context) 105 123 if len(possible_importers) == 0: 106 124 continue 107 125 result.append((filedescr, possible_importers)) 108 126 return result 127 128 def getReceiverId(self, obj): 129 """Get a unique id for an object. 130 131 If the object is stored in ZODB it should contain a `_p_oid` 132 attribute, which is guaranteed to be unique over the ZODB. 133 134 If the object has no such attribute, then it will be held in 135 memory only and will vanish as soon as the request is over. In 136 this case we can use the memory address of it. 137 """ 138 if hasattr(obj, '_p_oid'): 139 return getattr(obj, '_p_oid') 140 return str(id(obj)) 109 141 110 142 … … 213 245 def render(self): 214 246 return u'<div class="portlet"><a href="@@settings">Settings</a></div>' 215 247 248 class Import(object): 249 def __init__(self, filedescr, importers): 250 self.file = filedescr 251 self.importers = importers 252 216 253 class ImportCSVMain(grok.Viewlet): 217 254 grok.viewletmanager(MainArea) … … 219 256 grok.view(ImportCSV) 220 257 grok.require('waeup.manageUniversity') 258 259 def getImports(self): 260 result = [] 261 imports = self.context.getPossibleImports() 262 result = [Import(x, y) for x, y in imports] 263 return result 221 264 222 265 def update(self, *args, **kw): 223 print "ARGS: ", args, kw224 266 return super(ImportCSVMain, self).update(*args, **kw) 225 267
Note: See TracChangeset for help on using the changeset viewer.