Changeset 07f8d9a in sasview
- Timestamp:
- Apr 4, 2009 1:18:07 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 692d726
- Parents:
- 28caa03
- Location:
- DataLoader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/loader.py
r954c045 r07f8d9a 53 53 54 54 # Register default readers 55 readers.register_readers(self._identify_plugin) 55 readers.read_associations(self) 56 57 #TODO: remove the following line when ready to switch to the new default readers 58 #readers.register_readers(self._identify_plugin) 59 60 # Look for plug-in readers 61 self.find_plugins('plugins') 62 56 63 57 64 def find_plugins(self, dir): … … 110 117 return readers_found 111 118 119 def associate_file_type(self, ext, module): 120 """ 121 Look into a module to find whether it contains a 122 Reader class. If so, APPEND it to readers and (potentially) 123 to the list of writers for the given extension 124 125 @param ext: file extension [string] 126 @param module: module object 127 """ 128 reader_found = False 129 130 if hasattr(module, "Reader"): 131 try: 132 # Find supported extensions 133 loader = module.Reader() 134 if ext not in self.loaders: 135 self.loaders[ext] = [] 136 # Append the new reader to the list 137 self.loaders[ext].append(loader.read) 138 139 reader_found = True 140 141 # Keep track of wildcards 142 type_name = module.__name__ 143 if hasattr(loader, 'type_name'): 144 type_name = loader.type_name 145 146 wcard = "%s files (*%s)|*%s" % (type_name, ext.lower(), ext.lower()) 147 if wcard not in self.wildcards: 148 self.wildcards.append(wcard) 149 150 # Check whether writing is supported 151 if hasattr(loader, 'write'): 152 if ext not in self.writers: 153 self.writers[ext] = [] 154 # Append the new writer to the list 155 self.writers[ext].append(loader.write) 156 157 except: 158 logging.error("Loader: Error accessing Reader in %s\n %s" % (module.__name__, sys.exc_value)) 159 return reader_found 160 161 112 162 def _identify_plugin(self, module): 113 163 """ … … 126 176 if ext not in self.loaders: 127 177 self.loaders[ext] = [] 128 #The first reading will use the reader with only one ext. 129 if len(self.loaders[ext])>0 and len(loader.ext)>2: 130 self.loaders[ext].insert(1,loader.read) 131 else: 132 self.loaders[ext].insert(0,loader.read) 178 # When finding a reader at run time, treat this reader as the new 179 # default 180 self.loaders[ext].insert(0,loader.read) 133 181 134 182 reader_found = True 135 183 136 184 # Keep track of wildcards 137 for wcard in loader.type: 138 if wcard not in self.wildcards: 139 self.wildcards.append(wcard) 185 type_name = module.__name__ 186 if hasattr(loader, 'type_name'): 187 type_name = loader.type_name 188 wcard = "%s files (*%s)|*%s" % (type_name, ext.lower(), ext.lower()) 189 if wcard not in self.wildcards: 190 self.wildcards.append(wcard) 140 191 141 192 # Check whether writing is supported … … 147 198 148 199 except: 149 logging.error("Loader: Error accessing Reader in %s\n %s" % ( name, sys.exc_value))200 logging.error("Loader: Error accessing Reader in %s\n %s" % (module.__name__, sys.exc_value)) 150 201 return reader_found 151 202 … … 204 255 __registry = Registry() 205 256 257 def associate_file_type(self, ext, module): 258 """ 259 Look into a module to find whether it contains a 260 Reader class. If so, append it to readers and (potentially) 261 to the list of writers for the given extension 262 263 @param ext: file extension [string] 264 @param module: module object 265 """ 266 return self.__registry.associate_file_type(ext, module) 267 206 268 def load(self, file, format=None): 207 269 """ -
DataLoader/setup.py
r71609e47 r07f8d9a 6 6 # Then build and install the modules 7 7 from distutils.core import setup, Extension 8 from distutils.sysconfig import get_python_lib 8 9 9 10 … … 19 20 package_dir = {"DataLoader":"."}, 20 21 21 packages = ["DataLoader","DataLoader.readers"] 22 packages = ["DataLoader","DataLoader.readers"], 23 data_files=[(os.path.join(get_python_lib(),"DataLoader","readers"), ["readers/defaults.xml"])] 22 24 ) 23 25
Note: See TracChangeset
for help on using the changeset viewer.