Changes in run.py [168d359:f36e01f] in sasview


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • run.py

    r168d359 rf36e01f  
     1# -*- coding: utf-8 -*- 
    12#!/usr/bin/env python 
     3 
    24""" 
    35Run sasview in place.  This allows sasview to use the python 
     
    1416""" 
    1517 
     18import imp 
    1619import os 
    1720import sys 
    18 import imp 
    19 import logging 
    20 import logging.config 
    21  
    2221from contextlib import contextmanager 
    23 from os.path import abspath, dirname, join as joinpath 
     22from os.path import join as joinpath 
     23from os.path import abspath, dirname 
    2424 
    2525 
    26 LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'sasview/logging.ini') 
    27 logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=True) 
    28 logger = logging.getLogger(__name__) 
    29  
    30 def 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          
    3926def addpath(path): 
    4027    """ 
     
    5037    sys.path.insert(0, path) 
    5138 
     39 
    5240@contextmanager 
    5341def cd(path): 
     
    6048    os.chdir(old_dir) 
    6149 
     50 
    6251def import_package(modname, path): 
    6352    """Import a package into a particular point in the python namespace""" 
    64     logger.debug("Dynamicly importing: %s", path) 
    65     mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py'))) 
     53    mod = imp.load_source(modname, abspath(joinpath(path, '__init__.py'))) 
    6654    sys.modules[modname] = mod 
    6755    mod.__path__ = [abspath(path)] 
    6856    return mod 
     57 
    6958 
    7059def import_dll(modname, build_path): 
     
    7362    ext = sysconfig.get_config_var('SO') 
    7463    # build_path comes from context 
    75     path = joinpath(build_path, *modname.split('.'))+ext 
    76     #print "importing", modname, "from", path 
     64    path = joinpath(build_path, *modname.split('.')) + ext 
     65    # print "importing", modname, "from", path 
    7766    return imp.load_dynamic(modname, path) 
     67 
    7868 
    7969def prepare(): 
     
    8777    from distutils.util import get_platform 
    8878    root = abspath(dirname(__file__)) 
    89     platform = '%s-%s'%(get_platform(),sys.version[:3]) 
    90     build_path = joinpath(root, 'build','lib.'+platform) 
     79    platform = '%s-%s' % (get_platform(), sys.version[:3]) 
     80    build_path = joinpath(root, 'build', 'lib.' + platform) 
    9181 
    9282    # Notify the help menu that the Sphinx documentation is in a different 
     
    9989    #if not os.path.exists(mplconfig): os.mkdir(mplconfig) 
    10090    #import matplotlib 
    101     #matplotlib.use('Agg') 
    102     #print matplotlib.__file__ 
     91    # matplotlib.use('Agg') 
     92    # print matplotlib.__file__ 
    10393    #import pylab; pylab.hold(False) 
    10494    # add periodictable to the path 
    105     try: import periodictable 
    106     except: addpath(joinpath(root, '..','periodictable')) 
     95    try: 
     96        import periodictable 
     97    except: 
     98        addpath(joinpath(root, '..', 'periodictable')) 
    10799 
    108     try: import bumps 
    109     except: addpath(joinpath(root, '..','bumps')) 
     100    try: 
     101        import bumps 
     102    except: 
     103        addpath(joinpath(root, '..', 'bumps')) 
    110104 
    111105    # select wx version 
     
    127121    # be better to just store the package in src/sas/sasview. 
    128122    import sas 
    129     sas.sasview = import_package('sas.sasview', joinpath(root,'sasview')) 
     123    sas.sasview = import_package('sas.sasview', joinpath(root, 'sasview')) 
    130124 
    131125    # The sas.models package Compiled Model files should be pulled in from the build directory even though 
     
    136130    import sas.sascalc.pr 
    137131    sas.sascalc.pr.core = import_package('sas.sascalc.pr.core', 
    138                                   joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 
     132                                         joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 
    139133 
    140134    # Compiled modules need to be pulled from the build directory. 
     
    142136    import sas.sascalc.file_converter 
    143137    sas.sascalc.file_converter.core = import_package('sas.sascalc.file_converter.core', 
    144                                   joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core'))                     
     138                                                     joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core')) 
    145139 
    146140    # Compiled modules need to be pulled from the build directory. 
     
    148142    import sas.sascalc.calculator 
    149143    sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core', 
    150                                   joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 
     144                                                 joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 
    151145 
    152146    sys.path.append(build_path) 
    153147 
    154     #print "\n".join(sys.path) 
     148    # print "\n".join(sys.path) 
     149 
    155150 
    156151if __name__ == "__main__": 
    157     update_all_logs_to_debug(logger) 
     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.") 
    158160    prepare() 
    159161    from sas.sasview.sasview import run 
    160162    run() 
    161      
     163    logger.debug("Ending SASVIEW in debug mode.") 
Note: See TracChangeset for help on using the changeset viewer.