Changes in src/sas/sascalc/dataloader/loader.py [463e7ffc:dcb91cf] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/loader.py
r463e7ffc rdcb91cf 1 1 """ 2 2 File handler to support different file extensions. 3 Uses reflectomet ry'sregistry utility.3 Uses reflectometer registry utility. 4 4 5 5 The default readers are found in the 'readers' sub-module … … 14 14 """ 15 15 ##################################################################### 16 # This software was developed by the University of Tennessee as part of the17 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE)18 # project funded by the US National Science Foundation.19 # See the license text in license.txt20 # copyright 2008, University of Tennessee16 # 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 DefaultReaderException 31 33 from readers import ascii_reader 32 34 from readers import cansas_reader 35 from readers import cansas_reader_HDF5 33 36 34 37 logger = logging.getLogger(__name__) 38 35 39 36 40 class Registry(ExtensionRegistry): … … 39 43 Readers and writers are supported. 40 44 """ 41 42 45 def __init__(self): 43 46 super(Registry, self).__init__() 44 47 45 # #Writers48 # Writers 46 49 self.writers = {} 47 50 48 # #List of wildcards51 # List of wildcards 49 52 self.wildcards = ['All (*.*)|*.*'] 50 53 51 # #Creation time, for testing54 # Creation time, for testing 52 55 self._created = time.time() 53 56 … … 63 66 of a particular reader 64 67 65 Defaults to the ascii (multi-column) reader 66 if no reader was registered for the file's 67 extension. 68 """ 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 69 73 try: 70 74 return super(Registry, self).load(path, format=format) 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) 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) 79 125 80 126 def find_plugins(self, dir):
Note: See TracChangeset
for help on using the changeset viewer.