Ignore:
Timestamp:
Apr 17, 2017 4:30:10 PM (8 years ago)
Author:
krzywon
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)
Message:

Added a 4th data loader exception for generic readers that cannot open file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/file_reader_base_class.py

    rb09095a rda8bb53  
    1010from abc import abstractmethod 
    1111from loader_exceptions import NoKnownLoaderException, FileContentsException,\ 
    12     DataReaderException 
     12    DataReaderException, DefaultReaderException 
    1313from data_info import Data1D, Data2D, DataInfo, plottable_1D, plottable_2D,\ 
    1414    combine_data_info_with_plottable 
     
    4747        if os.path.isfile(filepath): 
    4848            basename, extension = os.path.splitext(os.path.basename(filepath)) 
     49            self.extension = extension.lower() 
    4950            # 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: 
    5152                # Try to load the file, but raise an error if unable to. 
    5253                try: 
    53                     self.unit_converter() 
     54                    self.load_unit_converter() 
    5455                    self.f_open = open(filepath, 'rb') 
    5556                    self.get_file_contents() 
    5657                    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) 
    6160                except OSError as e: 
    6261                    # If the file cannot be opened 
     
    6463                    msg += e.message 
    6564                    self.handle_error_message(msg) 
    66                 except Exception as e: 
    67                     # Handle any other generic error 
    68                     # TODO: raise or log? 
    69                     raise 
    7065                finally: 
     66                    # Close the file handle if it is open 
    7167                    if not self.f_open.closed: 
    7268                        self.f_open.close() 
     
    9894        self.output.append(data_obj) 
    9995 
    100     def unit_converter(self): 
     96    def load_unit_converter(self): 
    10197        """ 
    10298        Generic unit conversion import  
     
    134130        self.output = final_list 
    135131 
     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 
    136140    @staticmethod 
    137141    def splitline(line): 
Note: See TracChangeset for help on using the changeset viewer.