Changes in / [5552396:80c2c85] in sasview
- Files:
-
- 86 added
- 84 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
run.py
r832fea2 r899e084 107 107 addpath(joinpath(root, '../sasmodels/')) 108 108 109 # Import the sasview package from root/sasview as sas.sasview. It would110 # be better to just store the package in src/sas/sasview.111 import sas112 sas.sasview = import_package('sas.sasview', joinpath(root,'sasview'))113 114 109 # The sas.models package Compiled Model files should be pulled in from the build directory even though 115 110 # the source is stored in src/sas/models. … … 121 116 joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 122 117 123 # Compiled modules need to be pulled from the build directory.124 # Some packages are not where they are needed, so load them explicitly.125 118 import sas.sascalc.calculator 126 119 sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core', … … 133 126 if __name__ == "__main__": 134 127 prepare() 135 from sas.sasview.sasview import run 136 run ()128 from sas.sasview.sasview import run_gui 129 run_gui() -
sasview/installer_generator.py
r6a698c0 r899e084 4 4 exists in the current directory. Edit local_config.py according to your needs. 5 5 """ 6 import local_config7 import os6 import os 7 import sys 8 8 import string 9 10 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 11 sys.path.insert(0, os.path.join(root, 'sasview-install', 'Lib', 'site-packages')) 12 from sas.sasview import local_config 9 13 10 14 REG_PROGRAM = """{app}\MYPROG.EXE"" ""%1""" … … 13 17 AppVerName = str(local_config.__appname__ )+'-'+ str(local_config.__version__) 14 18 Dev = '' 15 if AppVerName.lower().count('dev') > 0:19 if 'dev' in AppVerName.lower(): 16 20 Dev = '-Dev' 17 21 AppPublisher = local_config._copyright … … 24 28 25 29 OutputBaseFilename = local_config.OutputBaseFilename 26 SetupIconFile = "images\\ball.ico"30 SetupIconFile = local_config.SetupIconFile_win 27 31 LicenseFile = 'license.txt' 28 32 DisableProgramGroupPage = 'yes' -
sasview/setup_exe.py
r5552396 r5552396 33 33 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 34 34 platform = '%s-%s'%(get_platform(), sys.version[:3]) 35 build_path = os.path.join(root, 'build', 'lib.'+platform) 36 #build_path = os.path.join(root, 'sasview-install', 'Lib', 'site-packages') 35 build_path = os.path.join(root, 'sasview-install', 'Lib', 'site-packages') 37 36 sys.path.insert(0, build_path) 38 39 import local_config 37 doc_path = os.path.join(root, 'build', 'lib.'+platform, 'doc') 38 39 from sas.sasview import local_config 40 40 from installer_generator import generate_installer 41 41 … … 174 174 path = os.getcwd() 175 175 176 media_dir = os.path.join(path, "media")177 images_dir = os.path.join(path, "images")178 test_dir = os.path.join(path, "test")179 test_1d_dir = os.path.join(path, "test\\1d_data")180 test_2d_dir = os.path.join(path, "test\\2d_data")181 test_save_dir = os.path.join(path, "test\\save_states")182 test_upcoming_dir = os.path.join(path, "test\\upcoming_formats")183 184 176 matplotlibdatadir = matplotlib.get_data_path() 185 177 matplotlibdata = findall(matplotlibdatadir) … … 188 180 opencl_include_dir = os.path.join(site_loc, "pyopencl", "cl") 189 181 190 data_files= []182 DATA_FILES = [] 191 183 192 184 if tinycc: 193 data_files+= tinycc.data_files()185 DATA_FILES += tinycc.data_files() 194 186 195 187 # Copying SLD data 196 188 import periodictable 197 data_files+= periodictable.data_files()198 199 import sas.sasgui.perspectives.fitting asfitting200 data_files+= fitting.data_files()201 202 import sas.sasgui.perspectives.calculator ascalculator203 data_files+= calculator.data_files()204 205 import sas.sasgui.perspectives.invariant asinvariant206 data_files+= invariant.data_files()207 208 import sas.sasgui.guiframe asguiframe209 data_files+= guiframe.data_files()189 DATA_FILES += periodictable.data_files() 190 191 from sas.sasgui.perspectives import fitting 192 DATA_FILES += fitting.data_files() 193 194 from sas.sasgui.perspectives import calculator 195 DATA_FILES += calculator.data_files() 196 197 from sas.sasgui.perspectives import invariant 198 DATA_FILES += invariant.data_files() 199 200 from sas.sasgui import guiframe 201 DATA_FILES += guiframe.data_files() 210 202 211 203 # precompile sas models into the sasview build path; doesn't matter too much … … 217 209 # include the compiled models as data; coordinate the target path for the 218 210 # data with installer_generator.py 219 data_files.append(('compiled_models', compiled_dlls))211 DATA_FILES.append(('compiled_models', compiled_dlls)) 220 212 221 213 import sasmodels 222 data_files+= sasmodels.data_files()214 DATA_FILES += sasmodels.data_files() 223 215 224 216 for f in matplotlibdata: 225 217 dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) 226 data_files.append((os.path.split(dirname)[0], [f]))218 DATA_FILES.append((os.path.split(dirname)[0], [f])) 227 219 228 220 # Copy the settings file for the sas.dataloader file extension associations 229 import sas.sascalc.dataloader.readers 230 f = os.path.join(sas.sascalc.dataloader.readers.get_data_path(), 'defaults.json') 231 if os.path.isfile(f): 232 data_files.append(('.', [f])) 233 f = 'custom_config.py' 234 if os.path.isfile(f): 235 data_files.append(('.', [f])) 236 data_files.append(('config', [f])) 237 f = 'local_config.py' 238 if os.path.isfile(f): 239 data_files.append(('.', [f])) 240 241 f = 'default_categories.json' 242 if os.path.isfile(f): 243 data_files.append(('.', [f])) 221 from sas.sascalc.dataloader import readers 222 reader_config = os.path.join(readers.get_data_path(), 'defaults.json') 223 if os.path.isfile(reader_config): 224 DATA_FILES.append(('.', [reader_config])) 225 226 # Copy the config files 227 sasview_path = os.path.join('..','src','sas','sasview') 228 custom_config_file = os.path.join(sasview_path, 'custom_config.py') 229 local_config_file = os.path.join(sasview_path, 'local_config.py') 230 DATA_FILES.append(('.', [custom_config_file])) 231 DATA_FILES.append(('config', [custom_config_file])) 232 DATA_FILES.append(('.', [local_config_file])) 233 234 # default_categories.json is beside the config files 235 category_config = os.path.join(os.path.dirname(local_config_file), 236 'default_categories.json') 237 if os.path.isfile(category_config): 238 DATA_FILES.append(('.', [category_config])) 244 239 245 240 if os.path.isfile("BUILD_NUMBER"): 246 data_files.append(('.', ["BUILD_NUMBER"])) 241 DATA_FILES.append(('.', ["BUILD_NUMBER"])) 242 243 images_dir = local_config.icon_path 244 media_dir = local_config.media_path 245 images_dir = local_config.icon_path 246 test_dir = local_config.test_path 247 test_1d_dir = os.path.join(test_dir, "1d_data") 248 test_2d_dir = os.path.join(test_dir, "2d_data") 249 test_save_dir = os.path.join(test_dir, "save_states") 250 test_upcoming_dir = os.path.join(test_dir, "upcoming_formats") 247 251 248 252 # Copying the images directory to the distribution directory. 249 253 for f in findall(images_dir): 250 if not ".svn" in f: 251 data_files.append(("images", [f])) 254 DATA_FILES.append(("images", [f])) 252 255 253 256 # Copying the HTML help docs 254 257 for f in findall(media_dir): 255 if not ".svn" in f: 256 data_files.append(("media", [f])) 258 DATA_FILES.append(("media", [f])) 257 259 258 260 # Copying the sample data user data 259 261 for f in findall(test_1d_dir): 260 if not ".svn" in f: 261 data_files.append(("test\\1d_data", [f])) 262 DATA_FILES.append(("test\\1d_data", [f])) 262 263 263 264 # Copying the sample data user data 264 265 for f in findall(test_2d_dir): 265 if not ".svn" in f: 266 data_files.append(("test\\2d_data", [f])) 266 DATA_FILES.append(("test\\2d_data", [f])) 267 267 268 268 # Copying the sample data user data 269 269 for f in findall(test_save_dir): 270 if not ".svn" in f: 271 data_files.append(("test\\save_states", [f])) 270 DATA_FILES.append(("test\\save_states", [f])) 272 271 273 272 # Copying the sample data user data 274 273 for f in findall(test_upcoming_dir): 275 if not ".svn" in f: 276 data_files.append(("test\\upcoming_formats", [f])) 274 DATA_FILES.append(("test\\upcoming_formats", [f])) 277 275 278 276 # Copying opencl include files 279 277 for f in findall(opencl_include_dir): 280 data_files.append(("includes\\pyopencl",[f]))278 DATA_FILES.append(("includes\\pyopencl", [f])) 281 279 282 280 # See if the documentation has been built, and if so include it. 283 doc_path = os.path.join(build_path, "doc")284 281 if os.path.exists(doc_path): 285 282 for dirpath, dirnames, filenames in os.walk(doc_path): 286 283 for filename in filenames: 287 284 sub_dir = os.path.join("doc", os.path.relpath(dirpath, doc_path)) 288 data_files.append((sub_dir, [os.path.join(dirpath, filename)]))285 DATA_FILES.append((sub_dir, [os.path.join(dirpath, filename)])) 289 286 else: 290 287 raise Exception("You must first build the documentation before creating an installer.") … … 292 289 if msvcrtdll_data_files is not None: 293 290 # install the MSVC 9 runtime dll's into the application folder 294 data_files.append(msvcrtdll_data_files)291 DATA_FILES.append(msvcrtdll_data_files) 295 292 296 293 # NOTE: … … 316 313 ]) 317 314 packages.append('periodictable.core') # not found automatically 318 #packages.append('IPython') 315 # For an interactive interpreter, SasViewCom 316 packages.extend(['IPython','pyreadline','pyreadline.unicode_helper']) 317 318 # individual models 319 319 includes = ['site', 'lxml._elementpath', 'lxml.etree'] 320 320 … … 331 331 'tcl84.dll', 'tk84.dll', 'QtGui4.dll', 'QtCore4.dll', 332 332 # numpy 1.8 openmp bindings (still seems to use all the cores without them) 333 # ... but we seem to need them when building from anaconda, so don't exclude ... 333 334 #'libiomp5md.dll', 'libifcoremd.dll', 'libmmd.dll', 'svml_dispmd.dll','libifportMD.dll', 334 335 # microsoft C runtime (not allowed to ship with the app; need to ship vcredist … … 342 343 ] 343 344 345 # extra dlls not found automatically 346 python_root = os.path.dirname(os.path.abspath(sys.executable)) 347 dll_path = os.path.join(python_root, 'Library', 'bin') 348 # the following are found already: 'mkl_intel_thread', 'libmmd', 'libifcoremd' 349 dll_includes = ['mkl_core', 'mkl_def', 'libiomp5md'] 350 dll_includes = [os.path.join(dll_path, dll+'.dll') for dll in dll_includes] 351 dll_includes = [dll for dll in dll_includes if os.path.exists(dll)] 352 if dll_includes: 353 DATA_FILES.append(('.', dll_includes)) 354 344 355 target_wx_client = Target( 345 356 description = 'SasView', 346 script = 'sasview .py',347 icon_resources = [(1, os.path.join(images_dir, "ball.ico"))],357 script = 'sasview_gui.py', 358 icon_resources = [(1, local_config.SetupIconFile_win)], 348 359 other_resources = [(24, 1, manifest)], 349 360 dest_base = "SasView" 350 361 ) 362 363 target_console_client = Target( 364 description = 'SasView console', 365 script = 'sasview_console.py', 366 icon_resources = [(1, local_config.SetupIconFile_win)], 367 other_resources = [(24, 1, manifest)], 368 dest_base = "SasViewCom" 369 ) 351 370 352 371 bundle_option = 2 … … 360 379 setup( 361 380 windows=[target_wx_client], 362 console=[ ],381 console=[target_console_client], 363 382 options={ 364 383 'py2exe': { … … 372 391 }, 373 392 }, 374 data_files= data_files,393 data_files=DATA_FILES, 375 394 ) -
sasview/setup_mac.py
r3d8e3c7 r899e084 12 12 """ 13 13 from setuptools import setup 14 import periodictable.xsf15 import sas.sascalc.dataloader.readers16 14 import os 17 15 import string 18 import local_config19 16 import pytz 20 17 import sys … … 29 26 sys.path.insert(0, build_path) 30 27 print "BUILDING PATH INSIDE", build_path 28 29 from sas.sasview import local_config 30 31 31 ICON = local_config.SetupIconFile_mac 32 32 EXTENSIONS_LIST = [] 33 RESOURCES_FILES = [] 33 34 DATA_FILES = [] 34 RESOURCES_FILES = []35 35 36 36 #Periodictable data file 37 DATA_FILES = periodictable.data_files() 37 import periodictable 38 DATA_FILES += periodictable.data_files() 38 39 #invariant and calculator help doc 39 import sas.sasgui.perspectives.fitting asfitting40 from sas.sasgui.perspectives import fitting 40 41 DATA_FILES += fitting.data_files() 41 import sas.sasgui.perspectives.calculator ascalculator42 from sas.sasgui.perspectives import calculator 42 43 DATA_FILES += calculator.data_files() 43 import sas.sasgui.perspectives.invariant asinvariant44 from sas.sasgui.perspectives import invariant 44 45 DATA_FILES += invariant.data_files() 45 import sasmodels as models46 DATA_FILES += models.data_files()47 import sas.sasgui.guiframe asguiframe46 import sasmodels 47 DATA_FILES += sasmodels.data_files() 48 from sas.sasgui import guiframe 48 49 DATA_FILES += guiframe.data_files() 49 50 50 51 #CANSAxml reader data files 51 RESOURCES_FILES.append(os.path.join(sas.sascalc.dataloader.readers.get_data_path(),'defaults.json')) 52 53 # Locate libxml2 library 54 lib_locs = ['/usr/local/lib', '/usr/lib'] 55 libxml_path = None 56 for item in lib_locs: 57 libxml_path_test = '%s/libxml2.2.dylib' % item 58 if os.path.isfile(libxml_path_test): 59 libxml_path = libxml_path_test 60 if libxml_path == None: 61 raise RuntimeError, "Could not find libxml2 on the system" 62 63 APP = ['sasview.py'] 64 DATA_FILES += ['images','test','media', 'custom_config.py', 'local_config.py', 65 'default_categories.json'] 52 from sas.sascalc.dataloader import readers 53 RESOURCES_FILES.append(os.path.join(readers.get_data_path(),'defaults.json')) 54 55 # Copy the config files 56 sasview_path = os.path.join('..','src','sas','sasview') 57 custom_config_file = os.path.join(sasview_path, 'custom_config.py') 58 local_config_file = os.path.join(sasview_path, 'local_config.py') 59 DATA_FILES.append(('.', [custom_config_file])) 60 DATA_FILES.append(('config', [custom_config_file])) 61 DATA_FILES.append(('.', [local_config_file])) 62 63 # default_categories.json is beside the config files 64 category_config = os.path.join(sasview_path, 'default_categories.json') 65 if os.path.isfile(category_config): 66 DATA_FILES.append(('.', [category_config])) 67 66 68 if os.path.isfile("BUILD_NUMBER"): 67 DATA_FILES.append("BUILD_NUMBER") 69 DATA_FILES.append(('.', ["BUILD_NUMBER"])) 70 71 images_dir = local_config.icon_path 72 media_dir = local_config.media_path 73 images_dir = local_config.icon_path 74 test_dir = local_config.test_path 75 test_1d_dir = os.path.join(test_dir, "1d_data") 76 test_2d_dir = os.path.join(test_dir, "2d_data") 77 test_save_dir = os.path.join(test_dir, "save_states") 78 test_upcoming_dir = os.path.join(test_dir, "upcoming_formats") 79 80 # Copying the images directory to the distribution directory. 81 for f in findall(images_dir): 82 DATA_FILES.append(("images", [f])) 83 84 # Copying the HTML help docs 85 for f in findall(media_dir): 86 DATA_FILES.append(("media", [f])) 87 88 # Copying the sample data user data 89 for f in findall(test_1d_dir): 90 DATA_FILES.append(("test\\1d_data", [f])) 91 92 # Copying the sample data user data 93 for f in findall(test_2d_dir): 94 DATA_FILES.append(("test\\2d_data", [f])) 95 96 # Copying the sample data user data 97 for f in findall(test_save_dir): 98 DATA_FILES.append(("test\\save_states", [f])) 99 100 # Copying the sample data user data 101 for f in findall(test_upcoming_dir): 102 DATA_FILES.append(("test\\upcoming_formats", [f])) 103 104 # Copying opencl include files 105 for f in findall(opencl_include_dir): 106 DATA_FILES.append(("includes\\pyopencl", [f])) 68 107 69 108 # See if the documentation has been built, and if so include it. … … 119 158 CFBundleTypeRole="Shell" )],) 120 159 160 # Locate libxml2 library 161 lib_locs = ['/usr/local/lib', '/usr/lib'] 162 libxml_path = None 163 for item in lib_locs: 164 libxml_path_test = '%s/libxml2.2.dylib' % item 165 if os.path.isfile(libxml_path_test): 166 libxml_path = libxml_path_test 167 if libxml_path == None: 168 raise RuntimeError, "Could not find libxml2 on the system" 169 121 170 #Get version - NB nasty hack. Need to find correct way to give path to installed sasview (AJJ) 122 171 #h5py has been added to packages. It requires hdf5 to be installed separetly 123 172 # 124 import __init__ as sasviewver 125 126 VERSION = sasviewver.__version__ 173 174 from sas.sasview import __version__ as VERSION 127 175 APPNAME = "SasView "+VERSION 128 176 DMGNAME = "SasView-"+VERSION+"-MacOSX" 129 130 APP = ['sasview.py'] 131 DATA_FILES += ['images','test','media'] 177 APP = ['sasview_gui.py'] 132 178 133 179 EXCLUDES = ['PyQt4', 'sip', 'QtGui'] -
setup.py
r785cc657 r899e084 11 11 12 12 # Manage version number ###################################### 13 import sasview 14 VERSION = sasview.__version__ 13 with open(os.path.join("src", "sas", "sasview", "__init__.py")) as fid: 14 for line in fid: 15 if line.startswith('__version__'): 16 VERSION = line.split('"')[1] 17 break 18 else: 19 raise ValueError("Could not find version in src/sas/sasview/__init__.py") 15 20 ############################################################## 16 21 … … 51 56 # file_path = os.path.join(f_path, f) 52 57 # os.remove(file_path) 53 if os.path.exists(SASVIEW_BUILD): 54 print "Removing existing build directory", SASVIEW_BUILD, "for a clean build" 55 shutil.rmtree(SASVIEW_BUILD) 58 59 if os.path.exists(SASVIEW_BUILD): 60 print "Removing existing build directory", SASVIEW_BUILD, "for a clean build" 61 shutil.rmtree(SASVIEW_BUILD) 56 62 57 63 # 'sys.maxsize' and 64bit: Not supported for python2.5 58 is_64bits = False 59 if sys.version_info >= (2, 6): 60 is_64bits = sys.maxsize > 2**32 61 64 is_64bits = sys.maxsize > 2**32 62 65 enable_openmp = False 63 66 … … 287 290 288 291 # SasView 289 package_dir["sas.sasview"] = "sasview"290 292 package_data['sas.sasview'] = ['images/*', 291 293 'media/*', … … 334 336 zip_safe = False, 335 337 entry_points = { 336 'console_scripts':[337 "sasview = sas.sasview.sasview:run",338 ]339 },340 cmdclass = {'build_ext': build_ext_subclass,341 'docs': BuildSphinxCommand,342 'disable_openmp': DisableOpenMPCommand}338 'console_scripts': ["sasview = sas.sasview.sasview:run_cli"] 339 }, 340 cmdclass = { 341 'build_ext': build_ext_subclass, 342 'docs': BuildSphinxCommand, 343 'disable_openmp': DisableOpenMPCommand, 344 } 343 345 ) -
src/sas/sasgui/__init__.py
rd7bb526 refe730d 1 import os 2 3 # Set up config directories 4 def make_user_folder(): 5 path = os.path.join(os.path.expanduser("~"),'.sasview') 6 if not os.path.exists(path): 7 os.mkdir(path) 8 return path 9 10 def find_app_folder(): 11 # If the directory containing sasview.py exists, then we are not running 12 # frozen and the current path is the app path. 13 root = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 14 path = os.path.join(root, 'sasview') 15 if os.path.exists(path): 16 return path 17 18 # If we are running frozen, then skip from: 19 # library.zip/sas/sasview 20 path = os.path.dirname(os.path.dirname(root)) 21 return path 22 23 USER_FOLDER = make_user_folder() 24 APP_FOLDER = find_app_folder() 25 26 27 28 def get_app_dir(): 29 if APP_FOLDER is None: 30 raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER") 31 return APP_FOLDER 32 33 def get_user_dir(): 34 if USER_FOLDER is None: 35 raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER") 36 return USER_FOLDER 37 38 _config_cache = None 39 def get_local_config(): 40 global _config_cache 41 if not _config_cache: 42 _config_cache = _load_config() 43 return _config_cache 44 45 def _load_config(): 46 import os 47 import sys 48 import imp 49 import logging 50 51 dirname = get_app_dir() 52 filename = 'local_config.py' 53 path = os.path.join(dirname, filename) 54 if os.path.exists(path): 55 try: 56 fObj = None 57 fObj, config_path, descr = imp.find_module('local_config', [APP_FOLDER]) 58 config = imp.load_module('local_config', fObj, config_path, descr) 59 logging.info("GuiManager loaded %s" % config_path) 60 return config 61 except Exception: 62 import traceback; logging.error(traceback.format_exc()) 63 logging.error("Error loading %s: %s" % (path, sys.exc_value)) 64 finally: 65 if fObj is not None: 66 fObj.close() 67 from sas.sasgui.guiframe import config 68 logging.info("GuiManager config defaults to sas.sasgui.guiframe") 69 return config -
src/sas/sasgui/guiframe/CategoryInstaller.py
r50008e3 refe730d 11 11 import os 12 12 import sys 13 import shutil14 13 import json 15 14 from collections import defaultdict 15 16 from sas.sasgui import get_user_dir 16 17 17 18 USER_FILE = 'categories.json' … … 68 69 69 70 @staticmethod 70 def _get_home_dir():71 """72 returns the users sasview config dir73 """74 return os.path.join(os.path.expanduser("~"), ".sasview")75 76 @staticmethod77 71 def _regenerate_model_dict(master_category_dict): 78 72 """ … … 113 107 returns the user data file, eg .sasview/categories.json.json 114 108 """ 115 return os.path.join(CategoryInstaller._get_home_dir(), 116 USER_FILE) 109 return os.path.join(get_user_dir(), USER_FILE) 117 110 118 111 @staticmethod -
src/sas/sasgui/guiframe/aboutbox.py
rd85c194 refe730d 24 24 import os.path 25 25 import os 26 try: 27 # Try to find a local config 28 import imp 29 path = os.getcwd() 30 if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ 31 (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): 32 fObj, path, descr = imp.find_module('local_config', [path]) 33 config = imp.load_module('local_config', fObj, path, descr) 34 else: 35 # Try simply importing local_config 36 import local_config as config 37 except: 38 # Didn't find local config, load the default 39 import config 26 27 from sas.sasgui import get_local_config 28 config = get_local_config() 40 29 41 30 def launchBrowser(url): -
src/sas/sasgui/guiframe/acknowledgebox.py
rd85c194 refe730d 8 8 __revision__ = "$Revision: 1193 $" 9 9 10 import os 11 10 12 import wx 11 13 import wx.richtext 12 14 import wx.lib.hyperlink 13 import random14 import os.path15 import os16 try:17 # Try to find a local config18 import imp19 path = os.getcwd()20 if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \21 (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))):22 fObj, path, descr = imp.find_module('local_config', [path])23 config = imp.load_module('local_config', fObj, path, descr)24 else:25 # Try simply importing local_config26 import local_config as config27 except:28 # Didn't find local config, load the default29 import config30 15 16 from sas.sasgui import get_local_config 17 config = get_local_config() 31 18 32 19 class DialogAcknowledge(wx.Dialog): -
src/sas/sasgui/guiframe/config.py
rd85c194 refe730d 125 125 (StatusBarEvent, EVT_STATUS) = wx.lib.newevent.NewEvent() 126 126 127 # Time out for updating sasview 128 UPDATE_TIMEOUT = 2 129 127 130 def printEVT(message): 128 131 """ -
src/sas/sasgui/guiframe/customdir.py
rd85c194 refe730d 1 1 # Setup and find Custom config dir 2 2 import sys 3 import imp 3 4 import os.path 5 import logging 4 6 import shutil 7 5 8 from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller 9 from sas.sasgui import get_user_dir, get_app_dir 6 10 7 CONF_DIR = 'config' 8 APPLICATION_NAME = 'sasview' 11 def get_custom_config_path(): 12 dirname = os.path.join(get_user_dir(), 'config') 13 # If the directory doesn't exist, create it 14 if not os.path.exists(dirname): 15 os.makedirs(dirname) 16 path = os.path.join(dirname, "custom_config.py") 17 return path 9 18 10 def _find_usersasview_dir():11 """12 Find and return user/.sasview dir13 """14 dir = os.path.join(os.path.expanduser("~"),15 ("." + APPLICATION_NAME))16 return dir17 19 18 def _find_customconf_dir(): 19 """ 20 Find path of the config directory. 21 The plugin directory is located in the user's home directory. 22 """ 23 u_dir = _find_usersasview_dir() 24 dir = os.path.join(u_dir, CONF_DIR) 25 26 return dir 27 28 def _setup_conf_dir(path): 20 _config_cache = None 21 def setup_custom_config(): 29 22 """ 30 23 Setup the custom config dir and cat file 31 24 """ 32 dir = _find_customconf_dir() 33 # If the plugin directory doesn't exist, create it 34 if not os.path.isdir(dir): 35 os.makedirs(dir) 36 file = os.path.join(dir, "custom_config.py") 25 global _config_cache 26 if not _config_cache: 27 _config_cache = _setup_custom_config() 28 return _config_cache 29 30 31 def _setup_custom_config(): 32 path = get_custom_config_path() 33 if not os.path.isfile(path): 34 # if the custom config file does not exist, copy the default from 35 # the app dir 36 try: 37 shutil.copyfile(os.path.join(get_app_dir(), "custom_config.py"), 38 path) 39 except Exception: 40 #import traceback; logging.error(traceback.format_exc()) 41 logging.error("Could not copy default custom config.") 42 43 custom_config = _load_config(path) 44 37 45 cat_file = CategoryInstaller.get_user_file() 38 46 # If the user category file doesn't exist copy the default to … … 44 52 shutil.copyfile(default_cat_file, cat_file) 45 53 else: 46 print "Unable to find/copy default cat file"47 except :48 print "Unable to copy default cat file to the user dir."54 logging.error("Unable to find/copy default cat file") 55 except Exception: 56 logging.error("Unable to copy default cat file to the user dir.") 49 57 50 # Place example user models as needed 51 try: 52 if not os.path.isfile(file): 53 shutil.copyfile(os.path.join(path, "custom_config.py"), file) 54 except: 55 # Check for data path next to exe/zip file. 56 #Look for maximum n_dir up of the current dir to find plugins dir 57 n_dir = 12 58 is_dir = False 59 f_dir = path 60 for i in range(n_dir): 61 if i > 1: 62 f_dir, _ = os.path.split(f_dir) 63 temp_path = os.path.join(f_dir, "custom_config.py") 64 if os.path.isfile(temp_path): 65 shutil.copyfile(temp_path, file) 66 is_dir = True 67 break 68 if not is_dir: 69 raise 70 71 return dir 72 73 74 class SetupCustom(object): 75 """ 76 implement custom config dir 77 """ 78 def find_dir(self): 79 return _find_customconf_dir() 80 81 def setup_dir(self, path): 82 return _setup_conf_dir(path) 83 58 return custom_config 84 59 85 86 87 60 61 def _load_config(path): 62 if os.path.exists(path): 63 try: 64 fObj = None 65 fObj, config_path, descr = imp.find_module('custom_config', [os.path.dirname(path)]) 66 custom_config = imp.load_module('custom_config', fObj, config_path, descr) 67 logging.info("GuiManager loaded %s" % config_path) 68 return custom_config 69 except Exception: 70 logging.error("Error loading %s: %s" % (path, sys.exc_value)) 71 finally: 72 if fObj is not None: 73 fObj.close() 74 from sas.sasview import custom_config 75 logging.info("GuiManager custom_config defaults to sas.sasview.custom_config") 76 return custom_config -
src/sas/sasgui/guiframe/documentation_window.py
rd85c194 refe730d 16 16 import os 17 17 import logging 18 import urllib 19 20 import webbrowser 18 21 import wx 19 import webbrowser 20 import urllib 21 import sys 22 23 from sas.sasgui import get_app_dir 22 24 23 25 SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" … … 27 29 except: 28 30 WX_SUPPORTS_HTML2 = False 29 30 31 from gui_manager import get_app_dir32 31 33 32 -
src/sas/sasgui/guiframe/gui_manager.py
rc8a641e8 refe730d 23 23 warnings.simplefilter("ignore") 24 24 import logging 25 import httplib26 25 import traceback 27 26 import urllib 28 import urllib229 27 import json 30 28 29 from matplotlib import _pylab_helpers 30 31 from sas.sasgui import get_local_config, get_app_dir, get_user_dir 31 32 from sas.sasgui.guiframe.events import EVT_CATEGORY 32 33 from sas.sasgui.guiframe.events import EVT_STATUS … … 47 48 from sas.sascalc.dataloader.loader import Loader 48 49 from sas.sasgui.guiframe.proxy import Connection 49 from matplotlib import _pylab_helpers 50 51 52 def get_app_dir(): 53 """ 54 The application directory is the one where the default custom_config.py 55 file resides. 56 57 :returns: app_path - the path to the applicatin directory 58 """ 59 # First, try the directory of the executable we are running 60 app_path = sys.path[0] 61 if os.path.isfile(app_path): 62 app_path = os.path.dirname(app_path) 63 if os.path.isfile(os.path.join(app_path, "custom_config.py")): 64 app_path = os.path.abspath(app_path) 65 logging.info("Using application path: %s", app_path) 66 return app_path 67 68 # Next, try the current working directory 69 if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")): 70 logging.info("Using application path: %s", os.getcwd()) 71 return os.path.abspath(os.getcwd()) 72 73 # Finally, try the directory of the sasview module 74 # TODO: gui_manager will have to know about sasview until we 75 # clean all these module variables and put them into a config class 76 # that can be passed by sasview.py. 77 logging.info(sys.executable) 78 logging.info(str(sys.argv)) 79 from sas import sasview as sasview 80 app_path = os.path.dirname(sasview.__file__) 81 logging.info("Using application path: %s", app_path) 82 return app_path 83 84 def get_user_directory(): 85 """ 86 Returns the user's home directory 87 """ 88 userdir = os.path.join(os.path.expanduser("~"), ".sasview") 89 if not os.path.isdir(userdir): 90 os.makedirs(userdir) 91 return userdir 92 93 def _find_local_config(file, path): 94 """ 95 Find configuration file for the current application 96 """ 97 config_module = None 98 fObj = None 99 try: 100 fObj, path_config, descr = imp.find_module(file, [path]) 101 config_module = imp.load_module(file, fObj, path_config, descr) 102 except: 103 logging.error("Error loading %s/%s: %s" % (path, file, sys.exc_value)) 104 finally: 105 if fObj is not None: 106 fObj.close() 107 logging.info("GuiManager loaded %s/%s" % (path, file)) 108 return config_module 109 110 # Get APP folder 111 PATH_APP = get_app_dir() 112 DATAPATH = PATH_APP 113 114 # GUI always starts from the App folder 115 #os.chdir(PATH_APP) 116 # Read in the local config, which can either be with the main 117 # application or in the installation directory 118 config = _find_local_config('local_config', PATH_APP) 119 if config is None: 120 config = _find_local_config('local_config', os.getcwd()) 121 if config is None: 122 # Didn't find local config, load the default 123 import sas.sasgui.guiframe.config as config 124 logging.info("using default local_config") 125 else: 126 logging.info("found local_config in %s" % os.getcwd()) 127 else: 128 logging.info("found local_config in %s" % PATH_APP) 129 130 from sas.sasgui.guiframe.customdir import SetupCustom 131 c_conf_dir = SetupCustom().setup_dir(PATH_APP) 132 custom_config = _find_local_config('custom_config', c_conf_dir) 133 if custom_config is None: 134 custom_config = _find_local_config('custom_config', os.getcwd()) 135 if custom_config is None: 136 msgConfig = "Custom_config file was not imported" 137 logging.info(msgConfig) 138 else: 139 logging.info("using custom_config in %s" % os.getcwd()) 140 else: 141 logging.info("using custom_config from %s" % c_conf_dir) 50 from sas.sasgui.guiframe.customdir import setup_custom_config 51 52 config = get_local_config() 53 custom_config = setup_custom_config() 142 54 143 55 #read some constants from config … … 172 84 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 173 85 else: 174 DEFAULT_OPEN_FOLDER = PATH_APP86 DEFAULT_OPEN_FOLDER = get_app_dir() 175 87 except: 176 88 DATALOADER_SHOW = True … … 186 98 DEFAULT_PERSPECTIVE = None 187 99 CLEANUP_PLOT = False 188 DEFAULT_OPEN_FOLDER = PATH_APP100 DEFAULT_OPEN_FOLDER = get_app_dir() 189 101 190 102 DEFAULT_STYLE = config.DEFAULT_STYLE … … 254 166 if os.path.isfile(ico_file): 255 167 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 256 self.path = PATH_APP168 self.path = get_app_dir() 257 169 self.application_name = APPLICATION_NAME 258 170 ## Application manager … … 525 437 try: 526 438 fd = open(file_name, 'w') 527 except :439 except Exception: 528 440 # On Permission denied: IOError 529 temp_dir = get_user_dir ectory()441 temp_dir = get_user_dir() 530 442 temp_file_name = os.path.join(temp_dir, name) 531 443 fd = open(temp_file_name, 'w') … … 2061 1973 2062 1974 2063 # 1975 # import urllib2 2064 1976 # try: 2065 1977 # req = urllib2.Request(config.__update_URL__) … … 3253 3165 if basename.lower() in [app_py, app_exe, app_app, app_base]: 3254 3166 data_base = sys.argv[1] 3255 input_file = os.path.normpath(os.path.join( DATAPATH,3167 input_file = os.path.normpath(os.path.join(get_app_dir(), 3256 3168 data_base)) 3257 3169 if input_file is None: … … 3268 3180 # do it only the first time app loaded 3269 3181 # delete unused model folder 3270 model_folder = os.path.join( PATH_APP, path)3182 model_folder = os.path.join(get_app_dir(), path) 3271 3183 if os.path.exists(model_folder) and os.path.isdir(model_folder): 3272 3184 if len(os.listdir(model_folder)) > 0: -
src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
rfaa3ae7 refe730d 9 9 10 10 from sas.sascalc.dataloader.loader import Loader 11 12 from sas.sasgui import get_local_config 11 13 from sas.sasgui.guiframe.plugin_base import PluginBase 12 14 from sas.sasgui.guiframe.events import StatusEvent 13 15 from sas.sasgui.guiframe.gui_style import GUIFRAME 14 16 from sas.sasgui.guiframe.gui_manager import DEFAULT_OPEN_FOLDER 15 try: 16 # Try to find a local config 17 import imp 18 path = os.getcwd() 19 if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ 20 (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): 21 fObj, path, descr = imp.find_module('local_config', [path]) 22 config = imp.load_module('local_config', fObj, path, descr) 23 else: 24 # Try simply importing local_config 25 import local_config as config 26 except: 27 # Didn't find local config, load the default 28 import sas.sasgui.guiframe.config as config 29 30 if config is None: 31 import sas.sasgui.guiframe.config as config 32 33 17 18 config = get_local_config() 34 19 extension_list = [] 35 20 if config.APPLICATION_STATE_EXTENSION is not None: -
src/sas/sasgui/guiframe/startup_configuration.py
rd85c194 refe730d 9 9 #copyright 2009, University of Tennessee 10 10 ################################################################################ 11 import os 12 import copy 13 11 14 import wx 12 import os 13 import sys 14 import copy 15 #import sas.sasgui.guiframe.gui_manager as gui 16 from sas.sasgui.guiframe.events import StatusEvent 15 16 from sas.sasgui.customdir import get_custom_config_path 17 17 from sas.sasgui.guiframe.gui_style import GUIFRAME 18 18 from sas.sasgui.guiframe import gui_manager as CURRENT 19 from sas.sasgui.guiframe.customdir import SetupCustom 19 20 20 21 # default configuration 21 22 DEFAULT_STRINGS = {'GUIFRAME_WIDTH':-1, … … 64 65 # parent 65 66 self.parent = parent 66 self.path = SetupCustom().find_dir()67 67 self._gui = gui 68 68 # font size … … 189 189 def write_custom_config(self): 190 190 """ 191 Write custom configuration 192 """ 193 fname = os.path.join(self.path, 'custom_config.py') 194 self.write_string(fname, self.return_string) 195 196 def write_string(self, fname, strings): 197 """ 198 Write and Save file 199 """ 200 201 try: 202 out_f = open(fname,'w') 203 except : 204 raise #RuntimeError, "Error: Can not change the configuration..." 205 out_f.write("#Application appearance custom configuration\n" ) 206 for key, item in strings.iteritems(): 207 if (key == 'DEFAULT_PERSPECTIVE') or \ 208 (key == 'DEFAULT_OPEN_FOLDER' and item != None): 209 out_f.write("%s = \"%s\"\n" % (key,str(item))) 210 else: 211 out_f.write("%s = %s\n" % (key,str(item))) 212 213 out_f.close() 214 191 Write custom configuration 192 """ 193 path = get_custom_config_path() 194 with open(path, 'w') as out_f: 195 out_f.write("#Application appearance custom configuration\n" ) 196 for key, item in self.return_string.iteritems(): 197 if (key == 'DEFAULT_PERSPECTIVE') or \ 198 (key == 'DEFAULT_OPEN_FOLDER' and item != None): 199 out_f.write("%s = \"%s\"\n" % (key,str(item))) 200 else: 201 out_f.write("%s = %s\n" % (key,str(item))) -
src/sas/sasgui/perspectives/fitting/models.py
r7673ecd refe730d 12 12 import py_compile 13 13 import shutil 14 from sasmodels.sasview_model import load_custom_model, load_standard_models 14 15 # Explicitly import from the pluginmodel module so that py2exe 15 16 # places it in the distribution. The Model1DPlugin class is used 16 17 # as the base class of plug-in models. 18 from sas.sasgui import get_user_dir 17 19 from sas.sascalc.fit.pluginmodel import Model1DPlugin 18 20 from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller 19 from sasmodels.sasview_model import load_custom_model, load_standard_models20 21 21 22 22 23 PLUGIN_DIR = 'plugin_models' 23 PLUGIN_LOG = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR, 24 "plugins.log") 24 PLUGIN_LOG = os.path.join(get_user_dir(), PLUGIN_DIR, "plugins.log") 25 25 26 26 def get_model_python_path(): -
src/sas/sasgui/plottools/__init__.py
rd7bb526 refe730d 1 import config2 1 from PlotPanel import PlotPanel 3 2 from plottables import Data1D, Theory1D
Note: See TracChangeset
for help on using the changeset viewer.