Changeset da8bb53 in sasview for src/sas/sascalc/dataloader/file_reader_base_class.py
- Timestamp:
- Apr 17, 2017 4:30:10 PM (8 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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- ad92c5a
- Parents:
- 8ffafd1
- git-author:
- Jeff Krzywon <krzywon@…> (04/17/17 16:30:10)
- git-committer:
- krzywon <krzywon@…> (04/17/17 16:30:10)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/file_reader_base_class.py
rb09095a rda8bb53 10 10 from abc import abstractmethod 11 11 from loader_exceptions import NoKnownLoaderException, FileContentsException,\ 12 DataReaderException 12 DataReaderException, DefaultReaderException 13 13 from data_info import Data1D, Data2D, DataInfo, plottable_1D, plottable_2D,\ 14 14 combine_data_info_with_plottable … … 47 47 if os.path.isfile(filepath): 48 48 basename, extension = os.path.splitext(os.path.basename(filepath)) 49 self.extension = extension.lower() 49 50 # If the file type is not allowed, return nothing 50 if extension in self.ext or self.allow_all:51 if self.extension in self.ext or self.allow_all: 51 52 # Try to load the file, but raise an error if unable to. 52 53 try: 53 self. unit_converter()54 self.load_unit_converter() 54 55 self.f_open = open(filepath, 'rb') 55 56 self.get_file_contents() 56 57 self.sort_one_d_data() 57 except RuntimeError: 58 # Reader specific errors 59 # TODO: Give a specific error. 60 pass 58 except FileContentsException as e: 59 self.handle_error_message(e.message) 61 60 except OSError as e: 62 61 # If the file cannot be opened … … 64 63 msg += e.message 65 64 self.handle_error_message(msg) 66 except Exception as e:67 # Handle any other generic error68 # TODO: raise or log?69 raise70 65 finally: 66 # Close the file handle if it is open 71 67 if not self.f_open.closed: 72 68 self.f_open.close() … … 98 94 self.output.append(data_obj) 99 95 100 def unit_converter(self):96 def load_unit_converter(self): 101 97 """ 102 98 Generic unit conversion import … … 134 130 self.output = final_list 135 131 132 def set_all_to_none(self): 133 """ 134 Set all mutable values to None for error handling purposes 135 """ 136 self.current_dataset = None 137 self.current_datainfo = None 138 self.output = [] 139 136 140 @staticmethod 137 141 def splitline(line):
Note: See TracChangeset
for help on using the changeset viewer.