Index: src/sas/sasgui/__init__.py
===================================================================
--- src/sas/sasgui/__init__.py	(revision d7bb5267934b5676c90b1655346a3793a8022965)
+++ src/sas/sasgui/__init__.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -0,0 +1,69 @@
+import os
+
+# Set up config directories
+def make_user_folder():
+    path = os.path.join(os.path.expanduser("~"),'.sasview')
+    if not os.path.exists(path):
+        os.mkdir(path)
+    return path
+
+def find_app_folder():
+    # If the directory containing sasview.py exists, then we are not running
+    # frozen and the current path is the app path.
+    root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+    path = os.path.join(root, 'sasview')
+    if os.path.exists(path):
+        return path
+
+    # If we are running frozen, then skip from:
+    #    library.zip/sas/sasview
+    path = os.path.dirname(os.path.dirname(root))
+    return path
+
+USER_FOLDER = make_user_folder()
+APP_FOLDER = find_app_folder()
+
+
+
+def get_app_dir():
+    if APP_FOLDER is None:
+        raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER")
+    return APP_FOLDER
+
+def get_user_dir():
+    if USER_FOLDER is None:
+        raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER")
+    return USER_FOLDER
+
+_config_cache = None
+def get_local_config():
+    global _config_cache
+    if not _config_cache:
+        _config_cache = _load_config()
+    return _config_cache
+
+def _load_config():
+    import os
+    import sys
+    import imp
+    import logging
+
+    dirname = get_app_dir()
+    filename = 'local_config.py'
+    path = os.path.join(dirname, filename)
+    if os.path.exists(path):
+        try:
+            fObj = None
+            fObj, config_path, descr = imp.find_module('local_config', [APP_FOLDER])
+            config = imp.load_module('local_config', fObj, config_path, descr)
+            logging.info("GuiManager loaded %s" % config_path)
+            return config
+        except Exception:
+            import traceback; logging.error(traceback.format_exc())
+            logging.error("Error loading %s: %s" % (path, sys.exc_value))
+        finally:
+            if fObj is not None:
+                fObj.close()
+    from sas.sasgui.guiframe import config
+    logging.info("GuiManager config defaults to sas.sasgui.guiframe")
+    return config
Index: src/sas/sasgui/guiframe/CategoryInstaller.py
===================================================================
--- src/sas/sasgui/guiframe/CategoryInstaller.py	(revision 50008e349254372d579f42bb3ad653d593d7a40b)
+++ src/sas/sasgui/guiframe/CategoryInstaller.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -11,7 +11,8 @@
 import os
 import sys
-import shutil
 import json
 from collections import defaultdict
+
+from sas.sasgui import get_user_dir
 
 USER_FILE = 'categories.json'
@@ -68,11 +69,4 @@
 
     @staticmethod
-    def _get_home_dir():
-        """
-        returns the users sasview config dir
-        """
-        return os.path.join(os.path.expanduser("~"), ".sasview")
-
-    @staticmethod
     def _regenerate_model_dict(master_category_dict):
         """
@@ -113,6 +107,5 @@
         returns the user data file, eg .sasview/categories.json.json
         """
-        return os.path.join(CategoryInstaller._get_home_dir(),
-                            USER_FILE)
+        return os.path.join(get_user_dir(), USER_FILE)
 
     @staticmethod
Index: src/sas/sasgui/guiframe/aboutbox.py
===================================================================
--- src/sas/sasgui/guiframe/aboutbox.py	(revision d85c194ea2f78cb2b9b3de9c969e1b8ebea6b6d2)
+++ src/sas/sasgui/guiframe/aboutbox.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -24,18 +24,7 @@
 import os.path
 import os
-try:
-    # Try to find a local config
-    import imp
-    path = os.getcwd()
-    if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \
-      (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))):
-        fObj, path, descr = imp.find_module('local_config', [path])
-        config = imp.load_module('local_config', fObj, path, descr)  
-    else:
-        # Try simply importing local_config
-        import local_config as config
-except:
-    # Didn't find local config, load the default 
-    import config
+
+from sas.sasgui import get_local_config
+config = get_local_config()
 
 def launchBrowser(url):
Index: src/sas/sasgui/guiframe/acknowledgebox.py
===================================================================
--- src/sas/sasgui/guiframe/acknowledgebox.py	(revision d85c194ea2f78cb2b9b3de9c969e1b8ebea6b6d2)
+++ src/sas/sasgui/guiframe/acknowledgebox.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -8,25 +8,12 @@
 __revision__ = "$Revision: 1193 $"
 
+import os
+
 import wx
 import wx.richtext
 import wx.lib.hyperlink
-import random
-import os.path
-import os
-try:
-    # Try to find a local config
-    import imp
-    path = os.getcwd()
-    if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \
-      (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))):
-        fObj, path, descr = imp.find_module('local_config', [path])
-        config = imp.load_module('local_config', fObj, path, descr)
-    else:
-        # Try simply importing local_config
-        import local_config as config
-except:
-    # Didn't find local config, load the default
-    import config
 
+from sas.sasgui import get_local_config
+config = get_local_config()
 
 class DialogAcknowledge(wx.Dialog):
Index: src/sas/sasgui/guiframe/config.py
===================================================================
--- src/sas/sasgui/guiframe/config.py	(revision d85c194ea2f78cb2b9b3de9c969e1b8ebea6b6d2)
+++ src/sas/sasgui/guiframe/config.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -125,4 +125,7 @@
 (StatusBarEvent, EVT_STATUS) = wx.lib.newevent.NewEvent()
 
+# Time out for updating sasview
+UPDATE_TIMEOUT = 2
+
 def printEVT(message):
     """
Index: src/sas/sasgui/guiframe/customdir.py
===================================================================
--- src/sas/sasgui/guiframe/customdir.py	(revision d85c194ea2f78cb2b9b3de9c969e1b8ebea6b6d2)
+++ src/sas/sasgui/guiframe/customdir.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -1,38 +1,46 @@
 # Setup and find Custom config dir
 import sys
+import imp
 import os.path
+import logging
 import shutil
+
 from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller
+from sas.sasgui import get_user_dir, get_app_dir
 
-CONF_DIR = 'config' 
-APPLICATION_NAME = 'sasview'
+def get_custom_config_path():
+    dirname = os.path.join(get_user_dir(), 'config')
+    # If the directory doesn't exist, create it
+    if not os.path.exists(dirname):
+        os.makedirs(dirname)
+    path = os.path.join(dirname, "custom_config.py")
+    return path
 
-def _find_usersasview_dir():
-    """
-    Find and return user/.sasview dir
-    """
-    dir = os.path.join(os.path.expanduser("~"), 
-                       ("." + APPLICATION_NAME))
-    return dir
 
-def _find_customconf_dir():
-    """
-    Find path of the config directory.
-    The plugin directory is located in the user's home directory.
-    """
-    u_dir = _find_usersasview_dir()
-    dir = os.path.join(u_dir, CONF_DIR)
-    
-    return dir
-
-def _setup_conf_dir(path):
+_config_cache = None
+def setup_custom_config():
     """
     Setup the custom config dir and cat file
     """
-    dir = _find_customconf_dir()
-    # If the plugin directory doesn't exist, create it
-    if not os.path.isdir(dir):
-        os.makedirs(dir)
-    file = os.path.join(dir, "custom_config.py")
+    global _config_cache
+    if not _config_cache:
+        _config_cache = _setup_custom_config()
+    return _config_cache
+
+
+def _setup_custom_config():
+    path = get_custom_config_path()
+    if not os.path.isfile(path):
+        # if the custom config file does not exist, copy the default from
+        # the app dir
+        try:
+            shutil.copyfile(os.path.join(get_app_dir(), "custom_config.py"),
+                            path)
+        except Exception:
+            #import traceback; logging.error(traceback.format_exc())
+            logging.error("Could not copy default custom config.")
+
+    custom_config = _load_config(path)
+
     cat_file = CategoryInstaller.get_user_file()
     # If the user category file doesn't exist copy the default to
@@ -44,44 +52,25 @@
                 shutil.copyfile(default_cat_file, cat_file)
             else:
-                print "Unable to find/copy default cat file"
-        except:
-            print "Unable to copy default cat file to the user dir."
+                logging.error("Unable to find/copy default cat file")
+        except Exception:
+            logging.error("Unable to copy default cat file to the user dir.")
 
-    # Place example user models as needed
-    try:
-        if not os.path.isfile(file):
-         shutil.copyfile(os.path.join(path, "custom_config.py"), file)
-    except:
-        # Check for data path next to exe/zip file.
-        #Look for maximum n_dir up of the current dir to find plugins dir
-        n_dir = 12
-        is_dir = False
-        f_dir = path
-        for i in range(n_dir):
-            if i > 1:
-                f_dir, _ = os.path.split(f_dir)
-            temp_path = os.path.join(f_dir, "custom_config.py")
-            if os.path.isfile(temp_path):
-                shutil.copyfile(temp_path, file)
-                is_dir = True
-                break
-        if not is_dir:
-            raise
-        
-    return dir
-  
-        
-class SetupCustom(object):
-    """
-    implement custom config dir
-    """
-    def find_dir(self):
-        return _find_customconf_dir()
-    
-    def setup_dir(self, path):
-        return _setup_conf_dir(path)
-    
+    return custom_config
 
-    
-    
-  
+
+def _load_config(path):
+    if os.path.exists(path):
+        try:
+            fObj = None
+            fObj, config_path, descr = imp.find_module('custom_config', [os.path.dirname(path)])
+            custom_config = imp.load_module('custom_config', fObj, config_path, descr)
+            logging.info("GuiManager loaded %s" % config_path)
+            return custom_config
+        except Exception:
+            logging.error("Error loading %s: %s" % (path, sys.exc_value))
+        finally:
+            if fObj is not None:
+                fObj.close()
+    from sas.sasview import custom_config
+    logging.info("GuiManager custom_config defaults to sas.sasview.custom_config")
+    return custom_config
Index: src/sas/sasgui/guiframe/documentation_window.py
===================================================================
--- src/sas/sasgui/guiframe/documentation_window.py	(revision d85c194ea2f78cb2b9b3de9c969e1b8ebea6b6d2)
+++ src/sas/sasgui/guiframe/documentation_window.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -16,8 +16,10 @@
 import os
 import logging
+import urllib
+
+import webbrowser
 import wx
-import webbrowser
-import urllib
-import sys
+
+from sas.sasgui import get_app_dir
 
 SPHINX_DOC_ENV = "SASVIEW_DOC_PATH"
@@ -27,7 +29,4 @@
 except:
     WX_SUPPORTS_HTML2 = False
-
-
-from gui_manager import get_app_dir
 
 
Index: src/sas/sasgui/guiframe/gui_manager.py
===================================================================
--- src/sas/sasgui/guiframe/gui_manager.py	(revision c8a641e878a6209ec6a298efe68269f170645bed)
+++ src/sas/sasgui/guiframe/gui_manager.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -23,10 +23,11 @@
 warnings.simplefilter("ignore")
 import logging
-import httplib
 import traceback
 import urllib
-import urllib2
 import json
 
+from matplotlib import _pylab_helpers
+
+from sas.sasgui import get_local_config, get_app_dir, get_user_dir
 from sas.sasgui.guiframe.events import EVT_CATEGORY
 from sas.sasgui.guiframe.events import EVT_STATUS
@@ -47,97 +48,8 @@
 from sas.sascalc.dataloader.loader import Loader
 from sas.sasgui.guiframe.proxy import Connection
-from matplotlib import _pylab_helpers
-
-
-def get_app_dir():
-    """
-        The application directory is the one where the default custom_config.py
-        file resides.
-
-        :returns: app_path - the path to the applicatin directory
-    """
-    # First, try the directory of the executable we are running
-    app_path = sys.path[0]
-    if os.path.isfile(app_path):
-        app_path = os.path.dirname(app_path)
-    if os.path.isfile(os.path.join(app_path, "custom_config.py")):
-        app_path = os.path.abspath(app_path)
-        logging.info("Using application path: %s", app_path)
-        return app_path
-
-    # Next, try the current working directory
-    if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")):
-        logging.info("Using application path: %s", os.getcwd())
-        return os.path.abspath(os.getcwd())
-
-    # Finally, try the directory of the sasview module
-    # TODO: gui_manager will have to know about sasview until we
-    # clean all these module variables and put them into a config class
-    # that can be passed by sasview.py.
-    logging.info(sys.executable)
-    logging.info(str(sys.argv))
-    from sas import sasview as sasview
-    app_path = os.path.dirname(sasview.__file__)
-    logging.info("Using application path: %s", app_path)
-    return app_path
-
-def get_user_directory():
-    """
-        Returns the user's home directory
-    """
-    userdir = os.path.join(os.path.expanduser("~"), ".sasview")
-    if not os.path.isdir(userdir):
-        os.makedirs(userdir)
-    return userdir
-
-def _find_local_config(file, path):
-    """
-        Find configuration file for the current application
-    """
-    config_module = None
-    fObj = None
-    try:
-        fObj, path_config, descr = imp.find_module(file, [path])
-        config_module = imp.load_module(file, fObj, path_config, descr)
-    except:
-        logging.error("Error loading %s/%s: %s" % (path, file, sys.exc_value))
-    finally:
-        if fObj is not None:
-            fObj.close()
-    logging.info("GuiManager loaded %s/%s" % (path, file))
-    return config_module
-
-# Get APP folder
-PATH_APP = get_app_dir()
-DATAPATH = PATH_APP
-
-# GUI always starts from the App folder
-#os.chdir(PATH_APP)
-# Read in the local config, which can either be with the main
-# application or in the installation directory
-config = _find_local_config('local_config', PATH_APP)
-if config is None:
-    config = _find_local_config('local_config', os.getcwd())
-    if config is None:
-        # Didn't find local config, load the default
-        import sas.sasgui.guiframe.config as config
-        logging.info("using default local_config")
-    else:
-        logging.info("found local_config in %s" % os.getcwd())
-else:
-    logging.info("found local_config in %s" % PATH_APP)
-
-from sas.sasgui.guiframe.customdir  import SetupCustom
-c_conf_dir = SetupCustom().setup_dir(PATH_APP)
-custom_config = _find_local_config('custom_config', c_conf_dir)
-if custom_config is None:
-    custom_config = _find_local_config('custom_config', os.getcwd())
-    if custom_config is None:
-        msgConfig = "Custom_config file was not imported"
-        logging.info(msgConfig)
-    else:
-        logging.info("using custom_config in %s" % os.getcwd())
-else:
-    logging.info("using custom_config from %s" % c_conf_dir)
+from sas.sasgui.guiframe.customdir import setup_custom_config
+
+config = get_local_config()
+custom_config = setup_custom_config()
 
 #read some constants from config
@@ -172,5 +84,5 @@
         DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder)
     else:
-        DEFAULT_OPEN_FOLDER = PATH_APP
+        DEFAULT_OPEN_FOLDER = get_app_dir()
 except:
     DATALOADER_SHOW = True
@@ -186,5 +98,5 @@
     DEFAULT_PERSPECTIVE = None
     CLEANUP_PLOT = False
-    DEFAULT_OPEN_FOLDER = PATH_APP
+    DEFAULT_OPEN_FOLDER = get_app_dir()
 
 DEFAULT_STYLE = config.DEFAULT_STYLE
@@ -254,5 +166,5 @@
                 if os.path.isfile(ico_file):
                     self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO))
-        self.path = PATH_APP
+        self.path = get_app_dir()
         self.application_name = APPLICATION_NAME
         ## Application manager
@@ -525,7 +437,7 @@
         try:
             fd = open(file_name, 'w')
-        except:
+        except Exception:
             # On Permission denied: IOError
-            temp_dir = get_user_directory()
+            temp_dir = get_user_dir()
             temp_file_name = os.path.join(temp_dir, name)
             fd = open(temp_file_name, 'w')
@@ -2061,5 +1973,5 @@
         
         
-#         
+#         import urllib2
 #         try:
 #             req = urllib2.Request(config.__update_URL__)
@@ -3253,5 +3165,5 @@
                 if basename.lower() in [app_py, app_exe, app_app, app_base]:
                     data_base = sys.argv[1]
-                    input_file = os.path.normpath(os.path.join(DATAPATH,
+                    input_file = os.path.normpath(os.path.join(get_app_dir(),
                                                                data_base))
         if input_file is None:
@@ -3268,5 +3180,5 @@
         # do it only the first time app loaded
         # delete unused model folder
-        model_folder = os.path.join(PATH_APP, path)
+        model_folder = os.path.join(get_app_dir(), path)
         if os.path.exists(model_folder) and os.path.isdir(model_folder):
             if len(os.listdir(model_folder)) > 0:
Index: src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
===================================================================
--- src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py	(revision faa3ae7bb2790a5fa3ceae0690d20ed2c371b3af)
+++ src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -9,27 +9,12 @@
 
 from sas.sascalc.dataloader.loader import Loader
+
+from sas.sasgui import get_local_config
 from sas.sasgui.guiframe.plugin_base import PluginBase
 from sas.sasgui.guiframe.events import StatusEvent
 from sas.sasgui.guiframe.gui_style import GUIFRAME
 from sas.sasgui.guiframe.gui_manager import DEFAULT_OPEN_FOLDER
-try:
-    # Try to find a local config
-    import imp
-    path = os.getcwd()
-    if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \
-        (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))):
-        fObj, path, descr = imp.find_module('local_config', [path])
-        config = imp.load_module('local_config', fObj, path, descr)
-    else:
-        # Try simply importing local_config
-        import local_config as config
-except:
-    # Didn't find local config, load the default
-    import sas.sasgui.guiframe.config as config
-
-if config is None:
-    import sas.sasgui.guiframe.config as config
-
-
+
+config = get_local_config()
 extension_list = []
 if config.APPLICATION_STATE_EXTENSION is not None:
Index: src/sas/sasgui/guiframe/startup_configuration.py
===================================================================
--- src/sas/sasgui/guiframe/startup_configuration.py	(revision d85c194ea2f78cb2b9b3de9c969e1b8ebea6b6d2)
+++ src/sas/sasgui/guiframe/startup_configuration.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -9,13 +9,14 @@
 #copyright 2009, University of Tennessee
 ################################################################################
+import os
+import copy
+
 import wx
-import os
-import sys
-import copy
-#import sas.sasgui.guiframe.gui_manager as gui
-from sas.sasgui.guiframe.events import StatusEvent  
+
+from sas.sasgui.customdir import get_custom_config_path
 from sas.sasgui.guiframe.gui_style import GUIFRAME
 from sas.sasgui.guiframe import gui_manager as CURRENT
-from sas.sasgui.guiframe.customdir  import SetupCustom
+
+
 # default configuration
 DEFAULT_STRINGS = {'GUIFRAME_WIDTH':-1,
@@ -64,5 +65,4 @@
         # parent
         self.parent = parent
-        self.path = SetupCustom().find_dir()
         self._gui = gui
         # font size 
@@ -189,26 +189,13 @@
     def write_custom_config(self):
         """
-            Write custom configuration
-        """
-        fname = os.path.join(self.path, 'custom_config.py')
-        self.write_string(fname, self.return_string)
-
-    def write_string(self, fname, strings):
-        """
-        Write and Save file
-        """
-        
-        try:
-            out_f =  open(fname,'w')
-        except :
-            raise  #RuntimeError, "Error: Can not change the configuration..."
-        out_f.write("#Application appearance custom configuration\n" )
-        for key, item in strings.iteritems():
-            if (key == 'DEFAULT_PERSPECTIVE') or \
-                (key == 'DEFAULT_OPEN_FOLDER' and item != None):
-                out_f.write("%s = \"%s\"\n" % (key,str(item)))
-            else:
-                out_f.write("%s = %s\n" % (key,str(item)))
-    
-        out_f.close() 
-        
+        Write custom configuration
+        """
+        path = get_custom_config_path()
+        with open(path, 'w') as out_f:
+            out_f.write("#Application appearance custom configuration\n" )
+            for key, item in self.return_string.iteritems():
+                if (key == 'DEFAULT_PERSPECTIVE') or \
+                    (key == 'DEFAULT_OPEN_FOLDER' and item != None):
+                    out_f.write("%s = \"%s\"\n" % (key,str(item)))
+                else:
+                    out_f.write("%s = %s\n" % (key,str(item)))
Index: src/sas/sasgui/perspectives/fitting/models.py
===================================================================
--- src/sas/sasgui/perspectives/fitting/models.py	(revision 7673ecd9d5adcefdfa1fc6a6d1ff0649f8e63bc8)
+++ src/sas/sasgui/perspectives/fitting/models.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -12,15 +12,15 @@
 import py_compile
 import shutil
+from sasmodels.sasview_model import load_custom_model, load_standard_models
 # Explicitly import from the pluginmodel module so that py2exe
 # places it in the distribution. The Model1DPlugin class is used
 # as the base class of plug-in models.
+from sas.sasgui import get_user_dir
 from sas.sascalc.fit.pluginmodel import Model1DPlugin
 from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller
-from sasmodels.sasview_model import load_custom_model, load_standard_models
 
 
 PLUGIN_DIR = 'plugin_models'
-PLUGIN_LOG = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR,
-                          "plugins.log")
+PLUGIN_LOG = os.path.join(get_user_dir(), PLUGIN_DIR, "plugins.log")
 
 def get_model_python_path():
Index: src/sas/sasgui/plottools/__init__.py
===================================================================
--- src/sas/sasgui/plottools/__init__.py	(revision d7bb5267934b5676c90b1655346a3793a8022965)
+++ src/sas/sasgui/plottools/__init__.py	(revision efe730d4bba7a05c203957e4495eece8359fcd77)
@@ -1,3 +1,2 @@
-import config
 from PlotPanel import PlotPanel
 from plottables import Data1D, Theory1D
