source: sasview/src/sas/sasgui/guiframe/customdir.py @ d3bce8c

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since d3bce8c was 73cbeec, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Opencl dialog (#29)

Merged OpenCL dialog prototype branch

  • Support to read available OpenCL infrastructure
  • Added support for SAS_OPENCL in sasview
  • Calling CL devices from get_devices rather than create some context
  • Calling more than on platform
  • Changing clinfo setup
  • Code cleanup
  • lint fixes
  • Added better exception handling
  • Fixed help button accidently disabled with the previous commit
  • Setting dialog to unmodal
  • Setting 0 values at setup
  • Switched to checkbox, beacuase all of them can be unset during initialization
  • Switiching to more appropriate HELP button
  • Code clean-up after review by PR
  • Interactive response to SAS_OPENCL enviroment
  • Added handling for platform names
  • Corrected warning
  • Handling for PYOPENCL_CTX for multiple platforms added
  • Bug fixed
  • Support for more than one platform and one device
  • Minor code cleanup
  • Added test button - currently outputs to console
  • Towards saving in comnfig file
  • Added settings reading from custom config file
  • Writting to settings file
  • Added message dialog for testing results
  • Writting to configuration file at the end of session
  • Setting NoOpenCL as defult
  • Setting proper CL env even when initiated from None
  • Adding back-compatibility support if SAS_OPENCL is not set in config_file
  • Added warning about lenght of tests
  • Return more reasonable test messages
  • Font changed so it looks better on Windows
  • Minor code cleanup
  • Code cleanup
  • Added focus om text box to make Windows working
  • and fixing line
  • making conditional check for kernelcl module
  • Minor code changes to make pylint happy
  • Changes to code after code review by PR
  • Removing panel wx element that prevented mouse scrolling
  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[493c90c]1# Setup and find Custom config dir
2import os.path
3import shutil
[74b5523]4
[493c90c]5CONF_DIR = 'config' 
[94d6752]6APPLICATION_NAME = 'sasview'
[493c90c]7
[ea5fa58]8def _find_usersasview_dir():
9    """
10    Find and return user/.sasview dir
11    """
[212bfc2]12    return os.path.join(os.path.expanduser("~"), ("." + APPLICATION_NAME))
[ea5fa58]13
[493c90c]14def _find_customconf_dir():
15    """
16    Find path of the config directory.
17    The plugin directory is located in the user's home directory.
18    """
[ea5fa58]19    u_dir = _find_usersasview_dir()
[212bfc2]20    return os.path.join(u_dir, CONF_DIR)
[493c90c]21
22def _setup_conf_dir(path):
23    """
[ea5fa58]24    Setup the custom config dir and cat file
[493c90c]25    """
[212bfc2]26    conf_dir = _find_customconf_dir()
[493c90c]27    # If the plugin directory doesn't exist, create it
[212bfc2]28    if not os.path.isdir(conf_dir):
29        os.makedirs(conf_dir)
30    config_file = os.path.join(conf_dir, "custom_config.py")
[ea5fa58]31
[493c90c]32    # Place example user models as needed
[8ab3302]33    try:
[212bfc2]34        if not os.path.isfile(config_file):
35            shutil.copyfile(os.path.join(path, "custom_config.py"), config_file)
[73cbeec]36
37        #Adding SAS_OPENCL if it doesn't exist in the config file
38        # - to support backcompability
39        if not "SAS_OPENCL" in open(config_file).read():
40            open(config_file,"a+").write("SAS_OPENCL = \"None\"\n")
[8ab3302]41    except:
42        # Check for data path next to exe/zip file.
43        #Look for maximum n_dir up of the current dir to find plugins dir
44        n_dir = 12
45        is_dir = False
46        f_dir = path
47        for i in range(n_dir):
48            if i > 1:
49                f_dir, _ = os.path.split(f_dir)
50            temp_path = os.path.join(f_dir, "custom_config.py")
51            if os.path.isfile(temp_path):
[212bfc2]52                shutil.copyfile(temp_path, config_file)
[8ab3302]53                is_dir = True
54                break
55        if not is_dir:
56            raise
[212bfc2]57    return conf_dir
58
59
[493c90c]60class SetupCustom(object):
61    """
62    implement custom config dir
63    """
64    def find_dir(self):
65        return _find_customconf_dir()
66   
67    def setup_dir(self, path):
68        return _setup_conf_dir(path)
Note: See TracBrowser for help on using the repository browser.