]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/appdirs.py
   1 #---------------------------------------------------------------------------- 
   3 # Purpose:      Utilities for retrieving special application dirs 
   5 # Author:       Kevin Ollivier, Jeff Norton 
   9 # Copyright:    (c) 2004-2005 ActiveGrid, Inc. 
  10 # License:      wxWindows License 
  11 #---------------------------------------------------------------------------- 
  13 from activegrid
.util
.lang 
import * 
  17 import activegrid
.util
.sysutils 
as sysutils
 
  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") 
  26         if (sysutils
.isServer()): 
  27             path 
= os
.getenv("ACTIVEGRID_SERVER_HOME") 
  28             if ((path 
is None) or (len(path
) < 1)): 
  29                 path 
= sysutils
.mainModuleDir
 
  31             path 
= os
.getenv("AG_DOCUMENTS_DIR") 
  32             if ((path 
is None) or (len(path
) < 1)): 
  33                 if sysutils
.isWindows(): 
  36                         from win32com
.shell 
import shell
, shellcon
 
  37                         path 
= shell
.SHGetFolderPath(0, shellcon
.CSIDL_PERSONAL
, None, 0) 
  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") 
  48                     if sys
.platform 
== "darwin": 
  52                             fsspec_disk
, fsspec_desktop 
= macfs
.FindFolder(MACFS
.kOnSystemDisk
, MACFS
.kDocumentsFolderType
, 0) 
  53                             path 
= macfs
.FSSpec((fsspec_disk
, fsspec_desktop
, '')).as_pathname() 
  59                 if ((path 
is None) or (len(path
) < 1)): 
  60                     path 
= os
.path
.expanduser("~") 
  62                 if ((path 
is None) or (len(path
) < 1)): 
  64                 path 
= os
.path
.join(path
, "ActiveGrid") 
  77 def getSystemDir(kind
=0): 
  78     if (kind 
== AG_SYSTEM_DIR
): 
  80         if (__systemDir 
is None): 
  81             __systemDir 
= _getSystemDir(kind
) 
  83     elif (kind 
== AG_LOGS_DIR
): 
  85         if (__logsDir 
is None): 
  86             __logsDir 
= _getSystemDir(kind
) 
  88     elif (kind 
== AG_DEMOS_DIR
): 
  90         if (__demosDir 
is None): 
  91             __demosDir 
= _getSystemDir(kind
) 
  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 
 100 def getAppDataFolder(): 
 102         # NOTE: cannot import wx from the server 
 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
) 
 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") 
 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
))