Changes in run.py [f36e01f:64ca561] in sasview
Legend:
- Unmodified
- Added
- Removed
-
run.py
rf36e01f r64ca561 1 # -*- coding: utf-8 -*-2 1 #!/usr/bin/env python 3 4 2 """ 5 3 Run sasview in place. This allows sasview to use the python … … 16 14 """ 17 15 18 import imp19 16 import os 20 17 import sys 18 import imp 19 import logging 20 import logging.config 21 21 22 from contextlib import contextmanager 22 from os.path import join as joinpath 23 from os.path import abspath, dirname 23 from os.path import abspath, dirname, join as joinpath 24 24 25 25 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 26 39 def addpath(path): 27 40 """ … … 37 50 sys.path.insert(0, path) 38 51 39 40 52 @contextmanager 41 53 def cd(path): … … 48 60 os.chdir(old_dir) 49 61 50 51 62 def import_package(modname, path): 52 63 """Import a package into a particular point in the python namespace""" 53 mod = imp.load_source(modname, abspath(joinpath(path, 64 mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py'))) 54 65 sys.modules[modname] = mod 55 66 mod.__path__ = [abspath(path)] 56 67 return mod 57 58 68 59 69 def import_dll(modname, build_path): … … 62 72 ext = sysconfig.get_config_var('SO') 63 73 # build_path comes from context 64 path = joinpath(build_path, *modname.split('.')) +ext65 # 74 path = joinpath(build_path, *modname.split('.'))+ext 75 #print "importing", modname, "from", path 66 76 return imp.load_dynamic(modname, path) 67 68 77 69 78 def prepare(): … … 77 86 from distutils.util import get_platform 78 87 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) 81 90 82 91 # Notify the help menu that the Sphinx documentation is in a different … … 89 98 #if not os.path.exists(mplconfig): os.mkdir(mplconfig) 90 99 #import matplotlib 91 # 92 # 100 #matplotlib.use('Agg') 101 #print matplotlib.__file__ 93 102 #import pylab; pylab.hold(False) 94 103 # 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')) 99 106 100 try: 101 import bumps 102 except: 103 addpath(joinpath(root, '..', 'bumps')) 107 try: import bumps 108 except: addpath(joinpath(root, '..','bumps')) 104 109 105 110 # select wx version … … 121 126 # be better to just store the package in src/sas/sasview. 122 127 import sas 123 sas.sasview = import_package('sas.sasview', joinpath(root, 128 sas.sasview = import_package('sas.sasview', joinpath(root,'sasview')) 124 129 125 130 # The sas.models package Compiled Model files should be pulled in from the build directory even though … … 130 135 import sas.sascalc.pr 131 136 sas.sascalc.pr.core = import_package('sas.sascalc.pr.core', 132 137 joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 133 138 134 139 # Compiled modules need to be pulled from the build directory. … … 136 141 import sas.sascalc.file_converter 137 142 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')) 139 144 140 145 # Compiled modules need to be pulled from the build directory. … … 142 147 import sas.sascalc.calculator 143 148 sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core', 144 149 joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 145 150 146 151 sys.path.append(build_path) 147 152 148 # print "\n".join(sys.path) 149 153 #print "\n".join(sys.path) 150 154 151 155 if __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) 160 157 prepare() 161 158 from sas.sasview.sasview import run 162 159 run() 163 logger.debug("Ending SASVIEW in debug mode.")160
Note: See TracChangeset
for help on using the changeset viewer.