]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/appdirs.py
DocView and ActiveGrid IDE updates from Morgan Hua:
[wxWidgets.git] / wxPython / samples / ide / activegrid / util / appdirs.py
1 #----------------------------------------------------------------------------
2 # Name: appdirs.py
3 # Purpose: Utilities for retrieving special application dirs
4 #
5 # Author: Kevin Ollivier, Jeff Norton
6 #
7 # Created: 8/27/05
8 # CVS-ID: $Id$
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
12
13 from activegrid.util.lang import *
14 import sys
15 import os
16 import string
17 import activegrid.util.sysutils as sysutils
18
19 def _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")
65
66 return path
67
68
69 AG_SYSTEM_DIR = 0
70 AG_LOGS_DIR = 1
71 AG_DEMOS_DIR = 2
72
73 __systemDir = None
74 __logsDir = None
75 __demosDir = None
76
77 def 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
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.
99 ifDefPy()
100 def getAppDataFolder():
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")
116 endIfDef()
117
118 ifDefPy()
119 def 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))
126 endIfDef()