Changeset f0f309d in sasview for src


Ignore:
Timestamp:
Jul 4, 2016 5:35:03 AM (8 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
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
Children:
e540cd2
Parents:
481ff26 (diff), 80c5d46 (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.
Message:

Merge branch 'master' into ESS_GUI

Location:
src/sas
Files:
124 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/readers/defaults.json

    rb699768 r80c5d46  
    99            "-extension":".ses", 
    1010            "-reader":"sesans_reader" 
     11         }, 
     12         { 
     13            "-extension":".h5", 
     14            "-reader":"cansas_reader_HDF5" 
    1115         }, 
    1216         { 
     
    3741            "-extension":".nxs", 
    3842            "-reader":"nexus_reader" 
     43         }, 
     44         { 
     45            "-extension":".pdh", 
     46            "-reader":"anton_paar_saxs_reader" 
    3947         } 
    4048      ] 
  • src/sas/sasgui/guiframe/data_panel.py

    rd85c194 r1941e6a  
    1313import wx 
    1414from wx.build import build_options 
     15 
    1516# Check version 
    1617toks = str(wx.__version__).split('.') 
     
    291292        Layout widgets related to buttons 
    292293        """ 
     294        #Load Data Button 
    293295        self.bt_add = wx.Button(self, wx.NewId(), "Load Data",  
    294296                                size=(BUTTON_WIDTH, -1)) 
    295297        self.bt_add.SetToolTipString("Load data files") 
    296298        wx.EVT_BUTTON(self, self.bt_add.GetId(), self._load_data) 
     299         
     300        #Delete Data Button 
    297301        self.bt_remove = wx.Button(self, wx.NewId(), "Delete Data", 
    298302         size=(BUTTON_WIDTH, -1)) 
    299303        self.bt_remove.SetToolTipString("Delete data from the application") 
    300304        wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove) 
     305         
     306        #Send data to perspective button 
    301307        self.bt_import = wx.Button(self, wx.NewId(), "Send To", 
    302308                                    size=(BUTTON_WIDTH, -1)) 
    303309        self.bt_import.SetToolTipString("Send Data set to active perspective") 
    304310        wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import) 
     311         
     312        #Choose perspective to be send data to combo box 
    305313        self.perspective_cbox = wx.ComboBox(self, -1, 
    306314                                style=wx.CB_READONLY) 
     
    310318                        self._on_perspective_selection) 
    311319     
     320        #Append data to current Graph Button 
    312321        self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To", 
    313322                                        size=(BUTTON_WIDTH, -1)) 
     
    316325        wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot) 
    317326         
     327        #Create a new graph and send data to that new graph button 
    318328        self.bt_plot = wx.Button(self, wx.NewId(), "New Plot",  
    319329                                 size=(BUTTON_WIDTH, -1)) 
     
    321331        wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot) 
    322332         
     333        #Freeze current theory button - becomes a data set and stays on graph 
    323334        self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory",  
    324335                                   size=(BUTTON_WIDTH, -1)) 
     
    329340        wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze) 
    330341        
     342        #select plot to send to combo box (blank if no data) 
    331343        if sys.platform == 'darwin': 
    332344            self.cb_plotpanel = wx.ComboBox(self, -1,  
     
    337349        wx.EVT_COMBOBOX(self.cb_plotpanel, -1, self._on_plot_selection) 
    338350        self.cb_plotpanel.Disable() 
     351         
     352        #Help button 
     353        self.bt_help = wx.Button(self, wx.NewId(), "HELP", 
     354                                 size=(BUTTON_WIDTH, -1)) 
     355        self.bt_help.SetToolTipString("Help for the Data Explorer.") 
     356        wx.EVT_BUTTON(self,self.bt_help.GetId(), self.on_help) 
    339357 
    340358        self.sizer3.AddMany([(self.bt_add), 
     
    356374                             ((10, 10)), 
    357375                             (self.sizer4), 
    358                              ((10, 40)), 
    359                              ((10, 40))]) 
     376                             ((10, 10)), 
     377                             (self.bt_help, 0, wx.EXPAND|wx.RIGHT, 5)]) 
    360378 
    361379        self.sizer3.AddGrowableCol(1, 1) 
     
    10691087        return self.frame  
    10701088     
     1089    def on_help(self, event): 
     1090        """ 
     1091        Bring up the data manager Documentation whenever 
     1092        the HELP button is clicked. 
     1093 
     1094        Calls DocumentationWindow with the path of the location within the 
     1095        documentation tree (after /doc/ ....".  Note that when using old 
     1096        versions of Wx (before 2.9) and thus not the release version of 
     1097        installers, the help comes up at the top level of the file as 
     1098        webbrowser does not pass anything past the # to the browser when it is 
     1099        running "file:///...." 
     1100 
     1101    :param evt: Triggers on clicking the help button 
     1102    """ 
     1103 
     1104        #import documentation window here to avoid circular imports 
     1105        #if put at top of file with rest of imports. 
     1106        from documentation_window import DocumentationWindow 
     1107 
     1108        _TreeLocation = "user/sasgui/guiframe/data_explorer_help.html" 
     1109        _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     1110                                          "Data Explorer Help") 
     1111 
    10711112    def on_close(self, event): 
    10721113        """ 
  • src/sas/sasgui/guiframe/report_dialog.py

    rd85c194 r6dd6e32  
    1515    FONT_VARIANT = 0 
    1616    ISPDF = True 
    17 elif sys.platform == "darwin": 
     17# For OSX and everything else 
     18else: 
    1819    _STATICBOX_WIDTH = 480 
    1920    PANEL_WIDTH = 530 
  • src/sas/sasgui/perspectives/calculator/model_editor.py

    rbb841ef r9501661  
    578578                    else: 
    579579                        out_f.write(line + "\n") 
    580                 elif line.count("P1 = make_class"): 
     580                elif line.count("P1 = find_model"): 
    581581                    out_f.write(line % (name1) + "\n") 
    582                 elif line.count("P2 = make_class"): 
     582                elif line.count("P2 = find_model"): 
    583583                    out_f.write(line % (name2) + "\n") 
    584584 
     
    719719        Do the layout for parameter related widgets 
    720720        """ 
    721         param_txt = wx.StaticText(self, -1, 'Fit Parameters (if any): ') 
    722  
    723         param_tip = "#Set the parameters and initial values.\n" 
     721        param_txt = wx.StaticText(self, -1, 'Fit Parameters NOT requiring' + \ 
     722                                  ' polydispersity (if any): ') 
     723 
     724        param_tip = "#Set the parameters NOT requiring polydispersity " + \ 
     725        "and their initial values.\n" 
    724726        param_tip += "#Example:\n" 
    725727        param_tip += "A = 1\nB = 1" 
     
    736738         
    737739        # Parameters with polydispersity 
    738         pd_param_txt = wx.StaticText(self, -1, 'Fit Parameters requiring polydispersity (if any): ') 
    739  
    740         pd_param_tip = "#Set the parameters and initial values.\n" 
     740        pd_param_txt = wx.StaticText(self, -1, 'Fit Parameters requiring ' + \ 
     741                                     'polydispersity (if any): ') 
     742 
     743        pd_param_tip = "#Set the parameters requiring polydispersity and " + \ 
     744        "their initial values.\n" 
    741745        pd_param_tip += "#Example:\n" 
    742746        pd_param_tip += "C = 2\nD = 2" 
     
    803807        self.bt_close.SetToolTipString("Close this panel.") 
    804808 
    805         self.button_sizer.AddMany([(self.bt_apply, 0, 
    806                                     wx.LEFT, EDITOR_WIDTH * 0.8), 
    807                                    (self.bt_help, 0, 
    808                                     wx.LEFT,15), 
    809                                    (self.bt_close, 0, 
    810                                     wx.LEFT | wx.BOTTOM, 15)]) 
     809        self.button_sizer.AddMany([(self.bt_apply, 0,0), 
     810                                   (self.bt_help, 0, wx.LEFT | wx.BOTTOM,15), 
     811                                   (self.bt_close, 0, wx.LEFT | wx.RIGHT, 15)]) 
    811812 
    812813    def _do_layout(self): 
     
    835836                                  wx.ALL | wx.EXPAND, 5), 
    836837                                 (self.msg_sizer, 0, wx.EXPAND | wx.ALL, 5), 
    837                                  (self.button_sizer, 0, wx.EXPAND | wx.ALL, 5)]) 
     838                                 (self.button_sizer, 0, wx.ALIGN_RIGHT)]) 
    838839        self.SetSizer(self.main_sizer) 
    839840        self.SetAutoLayout(True) 
     
    12371238##import scipy? 
    12381239#class Model(Model1DPlugin): 
    1239 #    name = "" 
     1240#    name = basename without extension of __file__ 
    12401241#    def __init__(self): 
    12411242#        Model1DPlugin.__init__(self, name=self.name) 
    12421243#        #set name same as file name 
    1243 #        self.name = self.get_fname() 
    12441244#        #self.params here 
    12451245#        self.description = "%s" 
     
    13031303""" 
    13041304TEST_TEMPLATE = """ 
    1305     def get_fname(self): 
    1306         path = sys._getframe().f_code.co_filename 
    1307         basename  = os.path.basename(path) 
    1308         name, _ = os.path.splitext(basename) 
    1309         return name 
    13101305###################################################################### 
    13111306## THIS IS FOR TEST. DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! 
     
    13301325import sys 
    13311326import copy 
     1327import collections 
    13321328 
    13331329import numpy 
    13341330 
    13351331from sas.sascalc.fit.pluginmodel import Model1DPlugin 
    1336 from sasmodels.sasview_model import make_class 
    1337 from sasmodels.core import load_model_info 
    1338 # User can change the name of the model (only with single functional model) 
    1339 #P1_model: 
    1340 #from %s import Model as P1 
    1341  
    1342 #P2_model: 
    1343 #from %s import Model as P2 
     1332from sasmodels.sasview_model import find_model 
    13441333 
    13451334class Model(Model1DPlugin): 
    1346     name = "" 
    1347     def __init__(self): 
     1335    name = os.path.splitext(os.path.basename(__file__))[0] 
     1336    is_multiplicity_model = False 
     1337    def __init__(self, multiplicity=1): 
    13481338        Model1DPlugin.__init__(self, name='') 
    1349         P1 = make_class('%s') 
    1350         P2 = make_class('%s') 
     1339        P1 = find_model('%s') 
     1340        P2 = find_model('%s') 
    13511341        p_model1 = P1() 
    13521342        p_model2 = P2() 
    13531343        ## Setting  model name model description 
    13541344        self.description = '%s' 
    1355         self.name = self.get_fname() 
    13561345        if self.name.rstrip().lstrip() == '': 
    13571346            self.name = self._get_name(p_model1.name, p_model2.name) 
     
    13621351 
    13631352        ## Define parameters 
    1364         self.params = {} 
     1353        self.params = collections.OrderedDict() 
    13651354 
    13661355        ## Parameter details [units, min, max] 
     
    13911380        #list of parameter that can be fitted 
    13921381        self._set_fixed_params() 
     1382 
    13931383        ## parameters with orientation 
     1384        self.orientation_params = [] 
    13941385        for item in self.p_model1.orientation_params: 
    13951386            new_item = "p1_" + item 
     
    14021393                self.orientation_params.append(new_item) 
    14031394        ## magnetic params 
     1395        self.magnetic_params = [] 
    14041396        for item in self.p_model1.magnetic_params: 
    14051397            new_item = "p1_" + item 
     
    14591451 
    14601452    def _set_dispersion(self): 
     1453        self.dispersion = collections.OrderedDict() 
    14611454        ##set dispersion only from p_model 
    14621455        for name , value in self.p_model1.dispersion.iteritems(): 
     
    15741567 
    15751568    def _set_fixed_params(self): 
     1569        self.fixed = [] 
    15761570        for item in self.p_model1.fixed: 
    15771571            new_item = "p1" + item 
     
    16241618        self.description += description 
    16251619 
    1626     def get_fname(self): 
    1627         path = sys._getframe().f_code.co_filename 
    1628         basename  = os.path.basename(path) 
    1629         name, _ = os.path.splitext(basename) 
    1630         return name 
    1631  
    16321620if __name__ == "__main__": 
    16331621    m1= Model() 
  • src/sas/sasgui/perspectives/calculator/pyconsole.py

    r26d6e045 r7673ecd  
    2727    """ 
    2828    # try running the model 
    29     from sasmodels.core import load_model, call_kernel 
    30     model = load_model(path) 
    31  
     29    from sasmodels.sasview_model import load_custom_model 
     30    Model = load_custom_model(path) 
     31    model = Model() 
    3232    q =  np.array([0.01, 0.1]) 
    33     kernel = model.make_kernel([q]) 
    34     Iq = call_kernel(kernel, {}) 
    35  
     33    Iq = model.evalDistribution(q) 
    3634    qx, qy =  np.array([0.01, 0.01]), np.array([0.1, 0.1]) 
    37     kernel = model.make_kernel([qx, qy]) 
    38     Iqxy = call_kernel(kernel, {}) 
     35    Iqxy = model.evalDistribution([qx, qy]) 
    3936 
    4037    result = """ 
     
    5653    except Exception: 
    5754        import traceback 
    58         result, errmsg = None, traceback.format_exc(limit=2) 
     55        result, errmsg = None, traceback.format_exc() 
    5956 
    6057    parts = ["Running model '%s'..." % os.path.basename(fname)] 
  • src/sas/sasgui/perspectives/fitting/basepage.py

    rcb4ef58 r6ed67db  
    1212import json 
    1313import logging 
     14import traceback 
     15 
    1416from collections import defaultdict 
    1517from wx.lib.scrolledpanel import ScrolledPanel 
     18 
     19import sasmodels.sasview_model 
    1620from sas.sasgui.guiframe.panel_base import PanelBase 
    1721from sas.sasgui.guiframe.utils import format_number, check_float, IdList 
     
    198202        self.state_change = False 
    199203        ## save customized array 
    200         self.values = [] 
    201         self.weights = [] 
     204        self.values = {}   # type: Dict[str, List[float, ...]] 
     205        self.weights = {}   # type: Dict[str, List[float, ...]] 
    202206        ## retrieve saved state 
    203207        self.number_saved_state = 0 
     
    852856                    angles.append(angle) 
    853857                    weights.append(weight) 
    854                 except: 
     858                except Exception: 
    855859                    # Skip non-data lines 
    856                     logging.error(sys.exc_info()[1]) 
     860                    logging.error(traceback.format_exc()) 
    857861            return numpy.array(angles), numpy.array(weights) 
    858862        except: 
     
    13931397                self.model._persistency_dict[key] = \ 
    13941398                                 [state.values, state.weights] 
    1395             except: 
    1396                 logging.error(sys.exc_info()[1]) 
     1399            except Exception: 
     1400                logging.error(traceback.format_exc()) 
    13971401            selection = self._find_polyfunc_selection(disp_model) 
    13981402            for list in self.fittable_param: 
     
    14101414                            list[5].Disable() 
    14111415                            list[6].Disable() 
    1412                         except: 
    1413                             logging.error(sys.exc_info()[1]) 
     1416                        except Exception: 
     1417                            logging.error(traceback.format_exc()) 
    14141418            # For array, disable all fixed params 
    14151419            if selection == 1: 
     
    14191423                        try: 
    14201424                            item[2].Disable() 
    1421                         except: 
    1422                             logging.error(sys.exc_info()[1]) 
     1425                        except Exception: 
     1426                            logging.error(traceback.format_exc()) 
    14231427 
    14241428        # Make sure the check box updated when all checked 
     
    15071511                is_modified = self._check_value_enter(self.parameters, 
    15081512                                                      is_modified) 
    1509             except: 
    1510                 logging.error(sys.exc_info()[1]) 
     1513            except Exception: 
     1514                logging.error(traceback.format_exc()) 
    15111515 
    15121516            # Here we should check whether the boundaries have been modified. 
     
    16511655        try: 
    16521656            self.save_current_state() 
    1653         except: 
    1654             logging.error(sys.exc_info()[1]) 
     1657        except Exception: 
     1658            logging.error(traceback.format_exc()) 
    16551659 
    16561660        return flag 
     
    18951899            if mod_cat == custom_model: 
    18961900                for model in self.model_list_box[mod_cat]: 
    1897                     if 'sasmodels.sasview_model.' in str(model): 
    1898                         str_m = model.id 
    1899                     else: 
    1900                         str_m = str(model).split(".")[0] 
    1901                     #self.model_box.Append(str_m) 
     1901                    str_m = model.id if hasattr(model, 'id') else model.name 
    19021902                    m_list.append(self.model_dict[str_m]) 
    19031903            else: 
     
    19101910                    #    wx.PostEvent(self.parent.parent, 
    19111911                    #                 StatusEvent(status=msg, info="error")) 
    1912         except: 
    1913             msg = "%s\n" % (sys.exc_info()[1]) 
     1912        except Exception: 
     1913            msg = traceback.format_exc() 
    19141914            wx.PostEvent(self._manager.parent, 
    19151915                         StatusEvent(status=msg, info="error")) 
     
    24742474                try: 
    24752475                    self.model.set_dispersion(p, disp_model) 
    2476                 except: 
    2477                     logging.error(sys.exc_info()[1]) 
     2476                except Exception: 
     2477                    logging.error(traceback.format_exc()) 
    24782478 
    24792479        ## save state into 
     
    25882588            self._draw_model() 
    25892589            self.Refresh() 
    2590         except: 
     2590        except Exception: 
     2591            logging.error(traceback.format_exc()) 
    25912592            # Error msg 
    25922593            msg = "Error occurred:" 
     
    26802681        # Try to delete values and weight of the names array dic if exists 
    26812682        try: 
    2682             del self.values[name] 
    2683             del self.weights[name] 
    2684             # delete all other dic 
    2685             del self.state.values[name] 
    2686             del self.state.weights[name] 
    2687             del self.model._persistency_dict[name.split('.')[0]] 
    2688             del self.state.model._persistency_dict[name.split('.')[0]] 
    2689         except: 
    2690             logging.error(sys.exc_info()[1]) 
     2683            if name in self.values: 
     2684                del self.values[name] 
     2685                del self.weights[name] 
     2686                # delete all other dic 
     2687                del self.state.values[name] 
     2688                del self.state.weights[name] 
     2689                del self.model._persistency_dict[name.split('.')[0]] 
     2690                del self.state.model._persistency_dict[name.split('.')[0]] 
     2691        except Exception: 
     2692            logging.error(traceback.format_exc()) 
    26912693 
    26922694    def _lay_out(self): 
     
    28322834                        graphs.append(item2.figure) 
    28332835                        canvases.append(item2.canvas) 
    2834             except: 
     2836            except Exception: 
    28352837                # Not for control panels 
    2836                 logging.error(sys.exc_info()[1]) 
     2838                logging.error(traceback.format_exc()) 
    28372839        # Make sure the resduals plot goes to the last 
    28382840        if res_item != None: 
     
    31673169                if item[7].__class__.__name__ == 'ComboBox': 
    31683170                    disfunc = str(item[7].GetValue()) 
    3169             except: 
    3170                 logging.error(sys.exc_info()[1]) 
     3171            except Exception: 
     3172                logging.error(traceback.format_exc()) 
    31713173 
    31723174            # 2D 
     
    31743176                try: 
    31753177                    check = item[0].GetValue() 
    3176                 except: 
     3178                except Exception: 
    31773179                    check = None 
    31783180                name = item[1] 
     
    32023204                    for weight in self.weights[name]: 
    32033205                        disfunc += ' ' + str(weight) 
    3204             except: 
    3205                 logging.error(sys.exc_info()[1]) 
     3206            except Exception: 
     3207                logging.error(traceback.format_exc()) 
    32063208            content += name + ',' + str(check) + ',' + value + disfunc + ':' 
    32073209 
     
    34033405                                                       weights=pd_weights) 
    34043406                            is_array = True 
    3405                 except: 
    3406                     logging.error(sys.exc_info()[1]) 
     3407                except Exception: 
     3408                    logging.error(traceback.format_exc()) 
    34073409                if not is_array: 
    34083410                    self._disp_obj_dict[name] = disp_model 
     
    34183420                                             self.state.weights] 
    34193421 
    3420             except: 
    3421                 logging.error(sys.exc_info()[1]) 
     3422            except Exception: 
     3423                logging.error(traceback.format_exc()) 
    34223424                print "Error in BasePage._paste_poly_help: %s" % \ 
    34233425                                        sys.exc_info()[1] 
  • src/sas/sasgui/perspectives/fitting/fitting.py

    r934ce649 r7673ecd  
    273273                        wx.PostEvent(self.parent, evt) 
    274274                        break 
    275         except: 
     275        except Exception: 
     276            import traceback; traceback.print_exc() 
    276277            msg = 'Delete Error: \nCould not delete the file; Check if in use.' 
    277278            wx.MessageBox(msg, 'Error') 
     
    579580                _, theory_state = item 
    580581                self.fit_panel.set_model_state(theory_state) 
    581             except: 
     582            except Exception: 
    582583                msg = "Fitting: cannot deal with the theory received" 
    583584                evt = StatusEvent(status=msg, info="error") 
  • src/sas/sasgui/perspectives/fitting/models.py

    rcb4ef58 r7673ecd  
    22    Utilities to manage models 
    33""" 
    4 import imp 
     4import traceback 
    55import os 
    66import sys 
     
    88# Time is needed by the log method 
    99import time 
     10import datetime 
    1011import logging 
    1112import py_compile 
     
    2021 
    2122PLUGIN_DIR = 'plugin_models' 
     23PLUGIN_LOG = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR, 
     24                          "plugins.log") 
    2225 
    2326def get_model_python_path(): 
     
    2831 
    2932 
    30 def log(message): 
     33def plugin_log(message): 
    3134    """ 
    3235    Log a message in a file located in the user's home directory 
    3336    """ 
    34     dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR) 
    35     out = open(os.path.join(dir, "plugins.log"), 'a') 
    36     out.write("%10g:  %s\n" % (time.clock(), message)) 
     37    out = open(PLUGIN_LOG, 'a') 
     38    now = time.time() 
     39    stamp = datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S') 
     40    out.write("%s: %s\n" % (stamp, message)) 
    3741    out.close() 
    3842 
     
    5155    if not issubclass(model, Model1DPlugin): 
    5256        msg = "Plugin %s must be of type Model1DPlugin \n" % str(name) 
    53         log(msg) 
     57        plugin_log(msg) 
    5458        return None 
    5559    if model.__name__ != "Model": 
    5660        msg = "Plugin %s class name must be Model \n" % str(name) 
    57         log(msg) 
     61        plugin_log(msg) 
    5862        return None 
    5963    try: 
     
    6367                                                             str(sys.exc_type), 
    6468                                                             sys.exc_info()[1]) 
    65         log(msg) 
     69        plugin_log(msg) 
    6670        return None 
    6771 
     
    7276            msg = "Plugin %s: error writing function \n\t :%s %s\n " % \ 
    7377                    (str(name), str(sys.exc_type), sys.exc_info()[1]) 
    74             log(msg) 
     78            plugin_log(msg) 
    7579            return None 
    7680    else: 
    7781        msg = "Plugin  %s needs a method called function \n" % str(name) 
    78         log(msg) 
     82        plugin_log(msg) 
    7983        return None 
    8084    return model 
     
    132136    """ 
    133137    def __nonzero__(self): 
    134         type, value, traceback = sys.exc_info() 
     138        type, value, tb = sys.exc_info() 
    135139        if type is not None and issubclass(type, py_compile.PyCompileError): 
    136140            print "Problem with", repr(value) 
    137             raise type, value, traceback 
     141            raise type, value, tb 
    138142        return 1 
    139143 
     
    155159 
    156160def _findModels(dir): 
     161    """ 
     162    Find custom models 
     163    """ 
    157164    # List of plugin objects 
    158     plugins = {} 
    159165    dir = find_plugins_dir() 
    160166    # Go through files in plug-in directory 
    161     #always recompile the folder plugin 
    162167    if not os.path.isdir(dir): 
    163         msg = "SasView couldn't locate Model plugin folder." 
    164         msg += """ "%s" does not exist""" % dir 
     168        msg = "SasView couldn't locate Model plugin folder %r." % dir 
    165169        logging.warning(msg) 
    166         return plugins 
    167     else: 
    168         log("looking for models in: %s" % str(dir)) 
    169         compile_file(dir) 
    170         logging.info("plugin model dir: %s" % str(dir)) 
    171     try: 
    172         list = os.listdir(dir) 
    173         for item in list: 
    174             toks = os.path.splitext(os.path.basename(item)) 
    175             if toks[1] == '.py' and not toks[0] == '__init__': 
    176                 name = toks[0] 
    177                 path = [os.path.abspath(dir)] 
    178                 file = None 
    179                 try: 
    180                     (file, path, info) = imp.find_module(name, path) 
    181                     module = imp.load_module(name, file, item, info) 
    182                     if hasattr(module, "Model"): 
    183                         try: 
    184                             if _check_plugin(module.Model, name) != None: 
    185                                 plugins[name] = module.Model 
    186                         except: 
    187                             msg = "Error accessing Model" 
    188                             msg += "in %s\n  %s %s\n" % (name, 
    189                                                          str(sys.exc_type), 
    190                                                          sys.exc_info()[1]) 
    191                             log(msg) 
    192                     else: 
    193                         filename = os.path.join(dir, item) 
    194                         plugins[name] = load_custom_model(filename) 
    195  
    196                 except: 
    197                     msg = "Error accessing Model" 
    198                     msg += " in %s\n  %s %s \n" % (name, 
    199                                                    str(sys.exc_type), 
    200                                                    sys.exc_info()[1]) 
    201                     log(msg) 
    202                 finally: 
    203  
    204                     if not file == None: 
    205                         file.close() 
    206     except: 
    207         # Don't deal with bad plug-in imports. Just skip. 
    208         msg = "Could not import model plugin: %s" % sys.exc_info()[1] 
    209         log(msg) 
     170        return {} 
     171 
     172    plugin_log("looking for models in: %s" % str(dir)) 
     173    #compile_file(dir)  #always recompile the folder plugin 
     174    logging.info("plugin model dir: %s" % str(dir)) 
     175 
     176    plugins = {} 
     177    for filename in os.listdir(dir): 
     178        name, ext = os.path.splitext(filename) 
     179        if ext == '.py' and not name == '__init__': 
     180            path = os.path.abspath(os.path.join(dir, filename)) 
     181            try: 
     182                model = load_custom_model(path) 
     183            except Exception: 
     184                msg = traceback.format_exc() 
     185                msg += "\nwhile accessing model in %r" % path 
     186                plugin_log(msg) 
     187                logging.warning("Failed to load plugin %r. See %s for details" 
     188                                % (path, PLUGIN_LOG)) 
     189            plugins[model.name] = model 
    210190 
    211191    return plugins 
  • src/sas/sasgui/perspectives/fitting/pagestate.py

    rc10d9d6c r7673ecd  
    1919import logging 
    2020import numpy 
    21 import string 
     21import traceback 
    2222 
    2323import xml.dom.minidom 
     
    473473            try: 
    474474                value = content[1] 
    475             except: 
    476                 logging.error(sys.exc_value) 
     475            except Exception: 
     476                logging.error(traceback.format_exc()) 
    477477            if name.count("State created"): 
    478478                repo_time = "" + value 
     
    515515                        title = content[2] + " [" + repo_time + "]" 
    516516                        title_name = HEADER % title 
    517                 except: 
    518                     logging.error(sys.exc_value) 
     517                except Exception: 
     518                    logging.error(traceback.format_exc()) 
    519519            if name == "model name ": 
    520520                try: 
     
    530530                    q_name = ("Q Range:    " + q_range) 
    531531                    q_range = CENTRE % q_name 
    532                 except: 
    533                     logging.error(sys.exc_value) 
     532                except Exception: 
     533                    logging.error(traceback.format_exc()) 
    534534        paramval = "" 
    535535        for lines in param_string.split(":"): 
     
    864864                            attribute = getattr(self, item[1]) 
    865865                            attribute[name] = com_name 
    866                         except: 
    867                             logging.error(sys.exc_value) 
     866                        except Exception: 
     867                            logging.error(traceback.format_exc()) 
    868868 
    869869                # get self.values and self.weights dic. if exists 
     
    880880                                val = float(line) 
    881881                                value_list.append(val) 
    882                             except: 
     882                            except Exception: 
    883883                                # pass if line is empty (it happens) 
    884                                 logging.error(sys.exc_value) 
     884                                logging.error(traceback.format_exc()) 
    885885                        dic[name] = numpy.array(value_list) 
    886886                    setattr(self, item[1], dic) 
     
    12931293                    if len(note_value) > 0: 
    12941294                        data_info.notes.append(note_value) 
    1295             except: 
     1295            except Exception: 
    12961296                err_mess = "cansas_reader.read: error processing entry notes\n  %s" % sys.exc_value 
    12971297                self.errors.append(err_mess) 
     
    13151315                    if len(detail_value) > 0: 
    13161316                        data_info.sample.details.append(detail_value) 
    1317             except: 
     1317            except Exception: 
    13181318                err_mess = "cansas_reader.read: error processing sample details\n  %s" % sys.exc_value 
    13191319                self.errors.append(err_mess) 
Note: See TracChangeset for help on using the changeset viewer.