Changeset 3147
- Timestamp:
- 05/31/2007 09:16:37 AM (2 years ago)
- Files:
-
- trunk/dabo/dPref.py (modified) (1 diff)
- trunk/dabo/lib/utils.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/dPref.py
r3145 r3147 65 65 datetime.datetime: "datetime", self._noneType: "none"} 66 66 if crs is None: 67 prefdir = utils.getUser DaboDirectory(appName)67 prefdir = utils.getUserAppDataDirectory(appName) 68 68 self._cxn = dabo.db.dConnection(connectInfo={"dbType": "SQLite", 69 69 "database": os.path.join(prefdir, "DaboPreferences.db")}) trunk/dabo/lib/utils.py
r3145 r3147 13 13 import sys 14 14 15 try: 16 from win32com.shell import shell, shellcon 17 except ImportError: 18 shell, shellcon = None, None 19 15 20 16 21 def reverseText(tx): … … 54 59 If the home directory cannot be determined, return None. 55 60 """ 61 hd = None 62 63 # If we are on Windows and win32com is available, get the user home 64 # directory using the Windows API: 65 if shell and shellcon: 66 return shell.SHGetFolderPath(0, shellcon.CSIDL_PROFILE, 0, 0) 67 56 68 # os.path.expanduser should work on all posix systems (*nix, Mac, and some 57 69 # Windows NT setups): 58 hd = None59 70 try: 60 71 hd = os.path.expanduser("~") … … 77 88 78 89 79 def getUser DaboDirectory(appName="Dabo"):90 def getUserAppDataDirectory(appName="Dabo"): 80 91 """Return the directory where Dabo can save user preference and setting information. 81 92 … … 93 104 """ 94 105 dd = None 95 if sys.platform in ("win32", ): 106 107 if sys.platform not in ("win32",): 108 # On Unix, change appname to lower, don't allow spaces, and prepend a ".": 109 appName = ".%s" % appNameappName.lower().replace(" ", "_") 110 111 # First, on Windows, try the Windows API function: 112 if shell and shellcon: 113 dd = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0) 114 print "!", dd 115 if dd is None and sys.platform == "win32": 116 # We are on Windows, but win32com wasn't installed. Look for the APPDATA 117 # environmental variable: 96 118 dd = os.environ.get("APPDATA") 97 if dd is not None: 98 dd = os.path.join(dd, appName) 119 99 120 100 121 if dd is None: 101 # On Unix, change appname to lower and don't allow spaces:102 appName = appName.lower().replace(" ", "_")122 # We are either not on Windows, or we couldn't locate the directory for 123 # whatever reason. Try going off the home directory: 103 124 dd = getUserHomeDirectory() 104 125 105 if dd is not None: 106 dd = os.path.join(dd, ".%s" % appName.lower()) 107 108 if not os.path.exists(dd): 109 # try to create the dabo directory: 110 try: 111 os.makedirs(dd) 112 except: 113 print "Couldn't create the user setting directory (%s)." % dd 114 dd = None 115 126 127 if dd is not None: 128 dd = os.path.join(dd, appName) 129 if not os.path.exists(dd): 130 # try to create the dabo directory: 131 try: 132 os.makedirs(dd) 133 except: 134 sys.stderr.write("Couldn't create the user setting directory (%s)." % dd) 135 dd = None 116 136 return dd 117 137
