]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/sysutils.py
Merged modifications from the 2.6 branch
[wxWidgets.git] / wxPython / samples / ide / activegrid / util / sysutils.py
1 #----------------------------------------------------------------------------
2 # Name: sysutils.py
3 # Purpose: System Utilities
4 #
5 # Author: Joel Hare
6 #
7 # Created: 7/28/04
8 # CVS-ID: $Id$
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
12
13 import sys
14 import os
15
16 # this will be set to true in IDE.py when we are running release builds.
17 isRelease = False
18
19 # Commented out for now.....
20 # Required for Unicode support with python
21 # Put over here because of py2exe problems
22 # Python suggests modifying site.py
23 #if hasattr(sys,"setdefaultencoding"):
24 # sys.setdefaultencoding("UTF-8")
25
26
27 MAINMODULE_DIR = "AG_MAINMODULE_DIR"
28 IS_RELEASE = "AG_IS_RELEASE"
29
30 def isRelease():
31 return 'true' == (str(os.getenv(IS_RELEASE)).lower())
32
33 def setRelease(value):
34 if value:
35 os.environ[IS_RELEASE]= "TRUE"
36 else:
37 os.environ[IS_RELEASE]= "FALSE"
38
39 def isWindows():
40 return os.name == 'nt'
41
42
43 def _generateMainModuleDir():
44 mainModuleDir = os.getenv(MAINMODULE_DIR)
45 if mainModuleDir: # if environment variable set, return it
46 return mainModuleDir
47
48 # On Mac, the python executable sometimes has a capital "P" so we need to
49 # lower the string first
50 sysExecLower = sys.executable.lower()
51 if sysExecLower == "/" or sysExecLower.find('python') != -1 or sysExecLower.find('apache') != -1:
52 utilModuleDir = os.path.dirname(__file__)
53 if not os.path.isabs(utilModuleDir):
54 utilModuleDir = os.path.join(os.getcwd(), utilModuleDir)
55 mainModuleDir = os.path.normpath(os.path.join(utilModuleDir, os.path.join(os.path.pardir, os.path.pardir)))
56 if mainModuleDir.endswith('.zip'):
57 mainModuleDir = os.path.dirname(mainModuleDir) # Get rid of library.zip
58 else:
59 mainModuleDir = os.path.dirname(sys.executable)
60
61 os.environ[MAINMODULE_DIR] = mainModuleDir # pythonBug: os.putenv doesn't work, set environment variable
62
63 return mainModuleDir
64
65 mainModuleDir = _generateMainModuleDir()
66
67 def _generatePythonExecPath():
68 # On Mac, the python executable sometimes has a capital "P" so we need to
69 # lower the string first
70 sysExecLower = sys.executable.lower()
71 if sysExecLower.find('python') != -1 or sysExecLower.find('apache') != -1:
72 pythonExecPath = sys.executable
73 else:
74 # this is where py2app puts the Python executable
75 if sys.platform == "darwin":
76 pythonExecPath = os.path.join(os.path.dirname(sys.executable), "../Frameworks/Python.Framework/Versions/2.4/Python/bin")
77 else:
78 pythonExecPath = os.path.join(os.path.dirname(sys.executable), '3rdparty\python2.4\python')
79 return pythonExecPath
80
81 pythonExecPath = _generatePythonExecPath()
82
83 def getCommandNameForExecPath(execPath):
84 if isWindows():
85 return '"%s"' % execPath
86 return execPath
87