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