Changeset 914ba0a in sasview for src/sas/sasgui/guiframe/local_perspectives/data_loader
- Timestamp:
- May 2, 2017 3:58:01 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d66dbcc
- Parents:
- 74d9780 (diff), 658dd57 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
refe730d r914ba0a 7 7 import wx 8 8 import logging 9 10 logger = logging.getLogger(__name__) 9 11 10 12 from sas.sascalc.dataloader.loader import Loader … … 58 60 path = None 59 61 self._default_save_location = self.parent._default_save_location 60 if self._default_save_location ==None:62 if self._default_save_location is None: 61 63 self._default_save_location = os.getcwd() 62 64 … … 75 77 if dlg.ShowModal() == wx.ID_OK: 76 78 file_list = dlg.GetPaths() 77 if len(file_list) >= 0 and not file_list[0] isNone:79 if len(file_list) >= 0 and file_list[0] is not None: 78 80 self._default_save_location = os.path.dirname(file_list[0]) 79 81 path = self._default_save_location … … 99 101 path = None 100 102 self._default_save_location = self.parent._default_save_location 101 if self._default_save_location ==None:103 if self._default_save_location is None: 102 104 self._default_save_location = os.getcwd() 103 105 dlg = wx.DirDialog(self.parent, "Choose a directory", … … 145 147 message += "\tError: {0}\n".format(error_data) 146 148 else: 147 logg ing.error("Loader returned an invalid object:\n %s" % str(item))149 logger.error("Loader returned an invalid object:\n %s" % str(item)) 148 150 data_error = True 149 151 150 152 data = self.parent.create_gui_data(item, p_file) 151 153 output[data.id] = data … … 155 157 """ 156 158 """ 157 message = "" 158 log_msg = '' 159 file_errors = {} 159 160 output = {} 160 any_error = False 161 data_error = False 162 error_message = "" 161 exception_occurred = False 162 163 163 for p_file in path: 164 info = "info"165 164 basename = os.path.basename(p_file) 166 165 _, extension = os.path.splitext(basename) 167 166 if extension.lower() in EXTENSIONS: 168 any_error = True169 167 log_msg = "Data Loader cannot " 170 log_msg += "load: %s\n" % str(p_file)171 log_msg += " ""Please try to open that file from "open project" """172 log_msg += " ""or "open analysis" menu\n"""173 error_message = log_msg + "\n"174 logging.info(log_msg)168 log_msg += "load: {}\n".format(str(p_file)) 169 log_msg += "Please try to open that file from \"open project\"" 170 log_msg += "or \"open analysis\" menu." 171 logger.info(log_msg) 172 file_errors[basename] = [log_msg] 175 173 continue 176 174 177 175 try: 178 message = "Loading Data... " + str(p_file) + "\n"179 self.load_update(output=output, message=message, info= info)176 message = "Loading {}...\n".format(p_file) 177 self.load_update(output=output, message=message, info="info") 180 178 temp = self.loader.load(p_file, format) 181 if temp.__class__.__name__ == "list": 182 for item in temp: 183 output, error_message, data_error = \ 184 self._process_data_and_errors(item, 185 p_file, 186 output, 187 error_message) 188 else: 179 if not isinstance(temp, list): 180 temp = [temp] 181 for item in temp: 182 error_message = "" 189 183 output, error_message, data_error = \ 190 self._process_data_and_errors(temp, 191 p_file, 192 output, 193 error_message) 184 self._process_data_and_errors(item, 185 p_file, 186 output, 187 error_message) 188 if data_error: 189 if basename in file_errors.keys(): 190 file_errors[basename] += [error_message] 191 else: 192 file_errors[basename] = [error_message] 193 self.load_update(output=output, 194 message=error_message, info="warning") 195 196 self.load_update(output=output, 197 message="Loaded {}\n".format(p_file), 198 info="info") 199 194 200 except: 195 logging.error(sys.exc_value) 196 any_error = True 197 if any_error or error_message != "": 198 if error_message == "": 199 error = "Error: " + str(sys.exc_info()[1]) + "\n" 200 error += "while loading Data: \n%s\n" % str(basename) 201 error_message += "The data file you selected could not be loaded.\n" 202 error_message += "Make sure the content of your file" 203 error_message += " is properly formatted.\n\n" 204 error_message += "When contacting the SasView team, mention the" 205 error_message += " following:\n%s" % str(error) 206 elif data_error: 207 base_message = "Errors occurred while loading " 208 base_message += "{0}\n".format(basename) 209 base_message += "The data file loaded but with errors.\n" 210 error_message = base_message + error_message 211 else: 212 error_message += "%s\n" % str(p_file) 213 info = "error" 214 215 if any_error or error_message: 216 self.load_update(output=output, message=error_message, info=info) 217 else: 218 message = "Loading Data Complete! " 219 message += log_msg 220 self.load_complete(output=output, error_message=error_message, 221 message=message, path=path, info='info') 201 logger.error(sys.exc_value) 202 203 error_message = "The Data file you selected could not be loaded.\n" 204 error_message += "Make sure the content of your file" 205 error_message += " is properly formatted.\n" 206 error_message += "When contacting the SasView team, mention the" 207 error_message += " following:\n" 208 error_message += "Error: " + str(sys.exc_info()[1]) 209 file_errors[basename] = [error_message] 210 self.load_update(output=output, message=error_message, info="warning") 211 212 if len(file_errors) > 0: 213 error_message = "" 214 for filename, error_array in file_errors.iteritems(): 215 error_message += "The following errors occured whilst " 216 error_message += "loading {}:\n".format(filename) 217 for message in error_array: 218 error_message += message + "\n" 219 error_message += "\n" 220 self.load_update(output=output, message=error_message, info="error") 221 222 self.load_complete(output=output, message="Loading data complete!", 223 info="info") 222 224 223 225 def load_update(self, output=None, message="", info="warning"): … … 239 241 # self.load_error(error_message) 240 242 self.parent.add_data(data_list=output) 241 242 243
Note: See TracChangeset
for help on using the changeset viewer.