]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/sysutils.py
remove some problem commas
[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 import time
16
17 # this will be set to true in IDE.py when we are running release builds.
18 isRelease = False
19
20 # Commented out for now.....
21 # Required for Unicode support with python
22 # Put over here because of py2exe problems
23 # Python suggests modifying site.py
24 #if hasattr(sys,"setdefaultencoding"):
25 # sys.setdefaultencoding("UTF-8")
26
27
28 MAINMODULE_DIR = "AG_MAINMODULE_DIR"
29 IS_RELEASE = "AG_IS_RELEASE"
30 IS_COMMERCIAL = "AG_IS_COMMERCIAL"
31 AG_SYSTEM_START_TIME_ENV_NAME = "AG_SYSTEM_START_TIME"
32
33 def isCommercial():
34
35 return os.path.exists(os.path.join(mainModuleDir,"commercial.txt")) or 'true' == (str(os.getenv(IS_COMMERCIAL)).lower())
36
37 def isRelease():
38 return 'true' == (str(os.getenv(IS_RELEASE)).lower())
39
40 def setRelease(value):
41 if value:
42 os.environ[IS_RELEASE]= "TRUE"
43 else:
44 os.environ[IS_RELEASE]= "FALSE"
45
46 def isWindows():
47 return os.name == 'nt'
48
49 __isServer = False
50
51 def setServerMode(isServer):
52 global __isServer
53 __isServer = isServer
54
55 def isServer():
56 global __isServer
57 return __isServer
58
59 def _generateMainModuleDir():
60 mainModuleDir = os.getenv(MAINMODULE_DIR)
61 if mainModuleDir: # if environment variable set, return it
62 return mainModuleDir
63
64 # On Mac, the python executable sometimes has a capital "P" so we need to
65 # lower the string first
66 sysExecLower = sys.executable.lower()
67 if sysExecLower == "/" or sysExecLower.find('python') != -1 or sysExecLower.find('apache') != -1:
68 utilModuleDir = os.path.dirname(__file__)
69 if not os.path.isabs(utilModuleDir):
70 utilModuleDir = os.path.join(os.getcwd(), utilModuleDir)
71 mainModuleDir = os.path.normpath(os.path.join(utilModuleDir, os.path.join(os.path.pardir, os.path.pardir)))
72 if mainModuleDir.endswith('.zip'):
73 mainModuleDir = os.path.dirname(mainModuleDir) # Get rid of library.zip
74 else:
75 mainModuleDir = os.path.dirname(sys.executable)
76
77 os.environ[MAINMODULE_DIR] = mainModuleDir # pythonBug: os.putenv doesn't work, set environment variable
78
79 return mainModuleDir
80
81 mainModuleDir = _generateMainModuleDir()
82
83 def _generatePythonExecPath():
84 # On Mac, the python executable sometimes has a capital "P" so we need to
85 # lower the string first
86 sysExecLower = sys.executable.lower()
87 if sysExecLower.find('python') != -1 or sysExecLower.find('apache') != -1:
88 pythonExecPath = sys.executable
89 else:
90 # this is where py2app puts the Python executable
91 if sys.platform == "darwin":
92 pythonExecPath = os.path.join(os.path.dirname(sys.executable), "../Frameworks/Python.Framework/Versions/2.4/Python/bin")
93 else:
94 pythonExecPath = os.path.join(os.path.dirname(sys.executable), '3rdparty\python2.4\python')
95 return pythonExecPath
96
97 pythonExecPath = _generatePythonExecPath()
98
99 def getCommandNameForExecPath(execPath):
100 if isWindows():
101 return '"%s"' % execPath
102 return execPath
103
104 def getUserName():
105 if isWindows():
106 return os.getenv('USERNAME')
107 else:
108 # 06-Feb-06 stoens@activegrid.com --
109 # this blows up the linux cc runs with "Inappropriate ioctl for device"
110 #return os.getlogin()
111 return os.getenv('USER')
112
113 def getCurrentTimeAsFloat():
114 return time.time()
115
116 systemStartTime = getCurrentTimeAsFloat()