1 #----------------------------------------------------------------------------
3 # Purpose: System Utilities
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
17 # this will be set to true in IDE.py when we are running release builds.
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")
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"
35 return os
.path
.exists(os
.path
.join(mainModuleDir
,"commercial.txt")) or 'true' == (str(os
.getenv(IS_COMMERCIAL
)).lower())
38 return 'true' == (str(os
.getenv(IS_RELEASE
)).lower())
40 def setRelease(value
):
42 os
.environ
[IS_RELEASE
]= "TRUE"
44 os
.environ
[IS_RELEASE
]= "FALSE"
47 return os
.name
== 'nt'
51 def setServerMode(isServer
):
59 def _generateMainModuleDir():
60 mainModuleDir
= os
.getenv(MAINMODULE_DIR
)
61 if mainModuleDir
: # if environment variable set, return it
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
75 mainModuleDir
= os
.path
.dirname(sys
.executable
)
77 os
.environ
[MAINMODULE_DIR
] = mainModuleDir
# pythonBug: os.putenv doesn't work, set environment variable
81 mainModuleDir
= _generateMainModuleDir()
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
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")
94 pythonExecPath
= os
.path
.join(os
.path
.dirname(sys
.executable
), '3rdparty\python2.4\python')
97 pythonExecPath
= _generatePythonExecPath()
99 def getCommandNameForExecPath(execPath
):
101 return '"%s"' % execPath
106 return os
.getenv('USERNAME')
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')
113 def getCurrentTimeAsFloat():
116 systemStartTime
= getCurrentTimeAsFloat()