]> git.saurik.com Git - wxWidgets.git/blame - wxPython/samples/ide/activegrid/util/appdirs.py
DocView and ActiveGrid IDE updates from Morgan Hua:
[wxWidgets.git] / wxPython / samples / ide / activegrid / util / appdirs.py
CommitLineData
02b800ce
RD
1#----------------------------------------------------------------------------
2# Name: appdirs.py
3# Purpose: Utilities for retrieving special application dirs
4#
aca310e5 5# Author: Kevin Ollivier, Jeff Norton
02b800ce
RD
6#
7# Created: 8/27/05
8# CVS-ID: $Id$
9# Copyright: (c) 2004-2005 ActiveGrid, Inc.
10# License: wxWindows License
11#----------------------------------------------------------------------------
12
aca310e5 13from activegrid.util.lang import *
02b800ce
RD
14import sys
15import os
16import string
aca310e5
RD
17import activegrid.util.sysutils as sysutils
18
19def _getSystemDir(kind):
20 if (kind == AG_LOGS_DIR):
21 return os.path.join(getSystemDir(AG_SYSTEM_DIR) , "logs")
22 elif (kind == AG_DEMOS_DIR):
23 return os.path.join(getSystemDir(AG_SYSTEM_DIR), "demos")
24 else:
25 path = ""
26 if (sysutils.isServer()):
27 path = os.getenv("ACTIVEGRID_SERVER_HOME")
28 if ((path is None) or (len(path) < 1)):
29 path = sysutils.mainModuleDir
30 else:
31 path = os.getenv("AG_DOCUMENTS_DIR")
32 if ((path is None) or (len(path) < 1)):
33 if sysutils.isWindows():
34 ifDefPy()
35 try:
36 from win32com.shell import shell, shellcon
37 path = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
38 except:
39 pass
40 endIfDef()
41 if ((path is None) or (len(path) < 1)):
42 homedrive = asString(os.getenv("HOMEDRIVE"))
43 homepath = os.getenv("HOMEPATH")
44## if ((homedrive is not None) and (len(homedrive) > 0) and (homepath is not None) and (len(homepath) > 0)):
45 path = os.path.join(homedrive, homepath, "MYDOCU~1")
46 else:
47 ifDefPy()
48 if sys.platform == "darwin":
49 try:
50 import macfs
51 import MACFS
52 fsspec_disk, fsspec_desktop = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kDocumentsFolderType, 0)
53 path = macfs.FSSpec((fsspec_disk, fsspec_desktop, '')).as_pathname()
54 except:
55 pass
56 endIfDef()
57
58 ifDefPy()
59 if ((path is None) or (len(path) < 1)):
60 path = os.path.expanduser("~")
61 endIfDef()
62 if ((path is None) or (len(path) < 1)):
63 path = "/"
64 path = os.path.join(path, "ActiveGrid")
02b800ce 65
aca310e5
RD
66 return path
67
68
69AG_SYSTEM_DIR = 0
70AG_LOGS_DIR = 1
71AG_DEMOS_DIR = 2
72
73__systemDir = None
74__logsDir = None
75__demosDir = None
76
77def getSystemDir(kind=0):
78 if (kind == AG_SYSTEM_DIR):
79 global __systemDir
80 if (__systemDir is None):
81 __systemDir = _getSystemDir(kind)
82 return __systemDir
83 elif (kind == AG_LOGS_DIR):
84 global __logsDir
85 if (__logsDir is None):
86 __logsDir = _getSystemDir(kind)
87 return __logsDir
88 elif (kind == AG_DEMOS_DIR):
89 global __demosDir
90 if (__demosDir is None):
91 __demosDir = _getSystemDir(kind)
92 return __demosDir
93 return None
94
02b800ce
RD
95
96# NOTE: We don't set this at startup because wxStandardPaths needs a running
97# application object. This makes sure the wxApp will always be created when
98# we get the folder.
aca310e5 99ifDefPy()
02b800ce 100def getAppDataFolder():
aca310e5
RD
101 try:
102 # NOTE: cannot import wx from the server
103 import wx
104 # wxStandardPaths requires a running app
105 if wx.GetApp() and wx.Platform != "__WXGTK__":
106 data_folder = wx.StandardPaths.Get().GetUserDataDir()
107 if not os.path.exists(data_folder):
108 os.mkdir(data_folder)
109 return data_folder
110 except:
111 pass
112 # wxBug: on *nix, it wants to point to ~/.appname, but
113 # so does wxConfig... For now, redirect this to ~/.appbuilder
114 # when this is fixed, we'll migrate settings to the correct place
115 return os.path.join(os.path.expanduser("~"), ".appbuilder")
116endIfDef()
02b800ce 117
aca310e5
RD
118ifDefPy()
119def createSystemDirs():
120 if (not os.path.exists(getSystemDir())):
121 os.mkdir(getSystemDir())
122 if (not os.path.exists(getSystemDir(AG_LOGS_DIR))):
123 os.mkdir(getSystemDir(AG_LOGS_DIR))
124 if (not os.path.exists(getSystemDir(AG_DEMOS_DIR))):
125 os.mkdir(getSystemDir(AG_DEMOS_DIR))
126endIfDef()