Changes in src/sas/sascalc/dataloader/loader.py [dcb91cf:463e7ffc] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/loader.py
rdcb91cf r463e7ffc 1 1 """ 2 2 File handler to support different file extensions. 3 Uses reflectomet erregistry utility.3 Uses reflectometry's registry utility. 4 4 5 5 The default readers are found in the 'readers' sub-module … … 14 14 """ 15 15 ##################################################################### 16 # 17 # 18 # 19 # 20 # 16 #This software was developed by the University of Tennessee as part of the 17 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 18 #project funded by the US National Science Foundation. 19 #See the license text in license.txt 20 #copyright 2008, University of Tennessee 21 21 ###################################################################### 22 22 … … 29 29 # Default readers are defined in the readers sub-module 30 30 import readers 31 from loader_exceptions import NoKnownLoaderException, FileContentsException,\32 DefaultReaderException33 31 from readers import ascii_reader 34 32 from readers import cansas_reader 35 from readers import cansas_reader_HDF536 33 37 34 logger = logging.getLogger(__name__) 38 39 35 40 36 class Registry(ExtensionRegistry): … … 43 39 Readers and writers are supported. 44 40 """ 41 45 42 def __init__(self): 46 43 super(Registry, self).__init__() 47 44 48 # Writers45 ## Writers 49 46 self.writers = {} 50 47 51 # List of wildcards48 ## List of wildcards 52 49 self.wildcards = ['All (*.*)|*.*'] 53 50 54 # Creation time, for testing51 ## Creation time, for testing 55 52 self._created = time.time() 56 53 … … 66 63 of a particular reader 67 64 68 Defaults to the ascii (multi-column), cansas XML, and cansas NeXuS 69 readers if no reader was registered for the file's extension. 70 """ 71 # Gets set to a string if the file has an associated reader that fails 72 msg_from_reader = None 65 Defaults to the ascii (multi-column) reader 66 if no reader was registered for the file's 67 extension. 68 """ 73 69 try: 74 70 return super(Registry, self).load(path, format=format) 75 except NoKnownLoaderException as nkl_e: 76 pass # Try the ASCII reader 77 except FileContentsException as fc_exc: 78 # File has an associated reader but it failed. 79 # Save the error message to display later, but try the 3 default loaders 80 msg_from_reader = fc_exc.message 81 except Exception: 82 pass 83 84 # File has no associated reader, or the associated reader failed. 85 # Try the ASCII reader 86 try: 87 ascii_loader = ascii_reader.Reader() 88 return ascii_loader.read(path) 89 except DefaultReaderException: 90 pass # Loader specific error to try the cansas XML reader 91 except FileContentsException as e: 92 if msg_from_reader is None: 93 raise RuntimeError(e.message) 94 95 # ASCII reader failed - try CanSAS xML reader 96 try: 97 cansas_loader = cansas_reader.Reader() 98 return cansas_loader.read(path) 99 except DefaultReaderException: 100 pass # Loader specific error to try the NXcanSAS reader 101 except FileContentsException as e: 102 if msg_from_reader is None: 103 raise RuntimeError(e.message) 104 except Exception: 105 pass 106 107 # CanSAS XML reader failed - try NXcanSAS reader 108 try: 109 cansas_nexus_loader = cansas_reader_HDF5.Reader() 110 return cansas_nexus_loader.read(path) 111 except DefaultReaderException as e: 112 logging.error("No default loader can load the data") 113 # No known reader available. Give up and throw an error 114 if msg_from_reader is None: 115 msg = "\nUnknown data format: {}.\nThe file is not a ".format(path) 116 msg += "known format that can be loaded by SasView.\n" 117 raise NoKnownLoaderException(msg) 118 else: 119 # Associated reader and default readers all failed. 120 # Show error message from associated reader 121 raise RuntimeError(msg_from_reader) 122 except FileContentsException as e: 123 err_msg = msg_from_reader if msg_from_reader is not None else e.message 124 raise RuntimeError(err_msg) 71 except: 72 try: 73 # No reader was found. Default to the ascii reader. 74 ascii_loader = ascii_reader.Reader() 75 return ascii_loader.read(path) 76 except: 77 cansas_loader = cansas_reader.Reader() 78 return cansas_loader.read(path) 125 79 126 80 def find_plugins(self, dir):
Note: See TracChangeset
for help on using the changeset viewer.