Changes in run.py [f36e01f:64ca561] in sasview


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • run.py

    rf36e01f r64ca561  
    1 # -*- coding: utf-8 -*- 
    21#!/usr/bin/env python 
    3  
    42""" 
    53Run sasview in place.  This allows sasview to use the python 
     
    1614""" 
    1715 
    18 import imp 
    1916import os 
    2017import sys 
     18import imp 
     19import logging 
     20import logging.config 
     21 
    2122from contextlib import contextmanager 
    22 from os.path import join as joinpath 
    23 from os.path import abspath, dirname 
     23from os.path import abspath, dirname, join as joinpath 
    2424 
    2525 
     26LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'sasview/logging.ini') 
     27logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=True) 
     28logger = logging.getLogger(__name__) 
     29 
     30def update_all_logs_to_debug(logger): 
     31    ''' 
     32    This updates all loggers and respective handlers to DEBUG 
     33    ''' 
     34    for handler in logger.handlers or logger.parent.handlers: 
     35        handler.setLevel(logging.DEBUG) 
     36    for name,_ in logging.Logger.manager.loggerDict.items(): 
     37        logging.getLogger(name).setLevel(logging.DEBUG) 
     38         
    2639def addpath(path): 
    2740    """ 
     
    3750    sys.path.insert(0, path) 
    3851 
    39  
    4052@contextmanager 
    4153def cd(path): 
     
    4860    os.chdir(old_dir) 
    4961 
    50  
    5162def import_package(modname, path): 
    5263    """Import a package into a particular point in the python namespace""" 
    53     mod = imp.load_source(modname, abspath(joinpath(path, '__init__.py'))) 
     64    mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py'))) 
    5465    sys.modules[modname] = mod 
    5566    mod.__path__ = [abspath(path)] 
    5667    return mod 
    57  
    5868 
    5969def import_dll(modname, build_path): 
     
    6272    ext = sysconfig.get_config_var('SO') 
    6373    # build_path comes from context 
    64     path = joinpath(build_path, *modname.split('.')) + ext 
    65     # print "importing", modname, "from", path 
     74    path = joinpath(build_path, *modname.split('.'))+ext 
     75    #print "importing", modname, "from", path 
    6676    return imp.load_dynamic(modname, path) 
    67  
    6877 
    6978def prepare(): 
     
    7786    from distutils.util import get_platform 
    7887    root = abspath(dirname(__file__)) 
    79     platform = '%s-%s' % (get_platform(), sys.version[:3]) 
    80     build_path = joinpath(root, 'build', 'lib.' + platform) 
     88    platform = '%s-%s'%(get_platform(),sys.version[:3]) 
     89    build_path = joinpath(root, 'build','lib.'+platform) 
    8190 
    8291    # Notify the help menu that the Sphinx documentation is in a different 
     
    8998    #if not os.path.exists(mplconfig): os.mkdir(mplconfig) 
    9099    #import matplotlib 
    91     # matplotlib.use('Agg') 
    92     # print matplotlib.__file__ 
     100    #matplotlib.use('Agg') 
     101    #print matplotlib.__file__ 
    93102    #import pylab; pylab.hold(False) 
    94103    # add periodictable to the path 
    95     try: 
    96         import periodictable 
    97     except: 
    98         addpath(joinpath(root, '..', 'periodictable')) 
     104    try: import periodictable 
     105    except: addpath(joinpath(root, '..','periodictable')) 
    99106 
    100     try: 
    101         import bumps 
    102     except: 
    103         addpath(joinpath(root, '..', 'bumps')) 
     107    try: import bumps 
     108    except: addpath(joinpath(root, '..','bumps')) 
    104109 
    105110    # select wx version 
     
    121126    # be better to just store the package in src/sas/sasview. 
    122127    import sas 
    123     sas.sasview = import_package('sas.sasview', joinpath(root, 'sasview')) 
     128    sas.sasview = import_package('sas.sasview', joinpath(root,'sasview')) 
    124129 
    125130    # The sas.models package Compiled Model files should be pulled in from the build directory even though 
     
    130135    import sas.sascalc.pr 
    131136    sas.sascalc.pr.core = import_package('sas.sascalc.pr.core', 
    132                                          joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 
     137                                  joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 
    133138 
    134139    # Compiled modules need to be pulled from the build directory. 
     
    136141    import sas.sascalc.file_converter 
    137142    sas.sascalc.file_converter.core = import_package('sas.sascalc.file_converter.core', 
    138                                                      joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core')) 
     143                                  joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core'))                     
    139144 
    140145    # Compiled modules need to be pulled from the build directory. 
     
    142147    import sas.sascalc.calculator 
    143148    sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core', 
    144                                                  joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 
     149                                  joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 
    145150 
    146151    sys.path.append(build_path) 
    147152 
    148     # print "\n".join(sys.path) 
    149  
     153    #print "\n".join(sys.path) 
    150154 
    151155if __name__ == "__main__": 
    152     # Need to add absolute path before actual prepare call, 
    153     # so logging can be done during initialization process too 
    154     root = abspath(dirname(__file__)) 
    155     addpath(joinpath(root, 'sasview')) 
    156     from logger_config import SetupLogger 
    157     logger = SetupLogger(__name__).config_development() 
    158  
    159     logger.debug("Starting SASVIEW in debug mode.") 
     156    update_all_logs_to_debug(logger) 
    160157    prepare() 
    161158    from sas.sasview.sasview import run 
    162159    run() 
    163     logger.debug("Ending SASVIEW in debug mode.") 
     160     
Note: See TracChangeset for help on using the changeset viewer.