Ignore:
Timestamp:
Dec 7, 2011 2:56:35 PM (12 years ago)
Author:
Jae Cho <jhjcho@…>
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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
8bac371
Parents:
a41034c
Message:

added compile, run and help in pyeditor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fittingview/src/sans/perspectives/fitting/models.py

    r4ad076b r5d1c1f4  
    1010import time 
    1111import logging 
    12  
     12import py_compile 
    1313from sans.guiframe.events import StatusEvent   
    1414# Explicitly import from the pluginmodel module so that py2exe 
     
    6969    return model 
    7070   
    71    
    72 def _findModels(dir): 
    73     """ 
    74     """ 
    75     # List of plugin objects 
    76     plugins = {} 
    77     # Go through files in plug-in directory 
    78     #always recompile the folder plugin 
    79     import compileall 
     71def find_plugins_dir(): 
     72    """ 
     73    Find path of the plugins dir 
     74    """ 
    8075    dir = os.path.abspath(PLUGIN_DIR) 
    8176    if not os.path.isdir(dir): 
     
    8580    if not os.path.isdir(dir): 
    8681        dir = os.path.join(os.path.dirname(os.path.sys.path[0]), PLUGIN_DIR) 
     82    return dir 
     83 
     84class ReportProblem: 
     85    def __nonzero__(self): 
     86        type, value, traceback = sys.exc_info() 
     87        if type is not None and issubclass(type, py_compile.PyCompileError): 
     88            print "Problem with", repr(value) 
     89            raise type, value, traceback 
     90        return 1 
     91     
     92report_problem = ReportProblem() 
     93 
     94def compile_file(dir): 
     95    """ 
     96    Compile a py file 
     97    """ 
     98    try: 
     99        import compileall 
     100        compileall.compile_dir(dir=dir, ddir=dir, force=1, quiet=report_problem) 
     101    except: 
     102        type, value, traceback = sys.exc_info() 
     103        return value 
     104    return None 
     105 
     106def _findModels(dir): 
     107    """ 
     108    """ 
     109    # List of plugin objects 
     110    plugins = {} 
     111    # Go through files in plug-in directory 
     112    #always recompile the folder plugin 
     113    import compileall 
     114    dir = find_plugins_dir() 
    87115    if not os.path.isdir(dir): 
    88116        msg = "SansView couldn't locate Model plugin folder." 
     
    92120    else: 
    93121        log("looking for models in: %s" % str(dir)) 
    94         compileall.compile_dir(dir=dir, ddir=dir, force=1, quiet=True) 
     122        compile_file(dir) 
    95123        logging.info("pluging model dir: %s\n" % str(dir)) 
    96124    try: 
     
    438466        is_modified = False 
    439467        if os.path.isdir(PLUGIN_DIR): 
    440             temp =  os.path.getmtime(PLUGIN_DIR) 
     468            # getmtime doesn't seem to work well: use getatime 
     469            temp =  os.path.getatime(PLUGIN_DIR) 
    441470            if  self.last_time_dir_modified != temp: 
    442471                is_modified = True 
     
    460489        else: 
    461490            return {} 
    462          
     491     
     492              
    463493    def populate_menu(self, modelmenu, event_owner): 
    464494        """ 
Note: See TracChangeset for help on using the changeset viewer.