| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
import ConfigParser |
|---|
| 36 |
import os |
|---|
| 37 |
import re |
|---|
| 38 |
import socket |
|---|
| 39 |
import sys |
|---|
| 40 |
import tempfile |
|---|
| 41 |
import time |
|---|
| 42 |
import traceback |
|---|
| 43 |
import urllib |
|---|
| 44 |
import xmlrpclib |
|---|
| 45 |
|
|---|
| 46 |
import pywintypes |
|---|
| 47 |
import win32api |
|---|
| 48 |
import win32con |
|---|
| 49 |
|
|---|
| 50 |
def main(): |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
if sys.argv[0] != __file__: |
|---|
| 55 |
raise RuntimeError('This function is only intended to be invoked by the GeoEco setup program. The setup program uses it to report a successful or failed installation to the server that tracks installation statistics. Please do not invoke this function yourself. Doing so will corrupt our statistics. Thank you.') |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
logFileHandle, logFilePath = tempfile.mkstemp('.txt', 'GeoEcoSetupFailure_') |
|---|
| 60 |
logFile = os.fdopen(logFileHandle, 'wb') |
|---|
| 61 |
try: |
|---|
| 62 |
try: |
|---|
| 63 |
logFile.write('Installation completed at %s GMT.\n' % time.asctime(time.gmtime(time.time()))) |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
logFile.write('Parsing command line arguments.\n') |
|---|
| 68 |
|
|---|
| 69 |
try: |
|---|
| 70 |
if len(sys.argv) != 4: |
|---|
| 71 |
raise RuntimeError('Invalid number of arguments.') |
|---|
| 72 |
|
|---|
| 73 |
if sys.argv[1] not in ['False', 'True']: |
|---|
| 74 |
raise RuntimeError('Invalid arguments.') |
|---|
| 75 |
shortcuts = sys.argv[1] == 'True' |
|---|
| 76 |
logFile.write('shortcuts = %s\n' % str(shortcuts)) |
|---|
| 77 |
|
|---|
| 78 |
if sys.argv[2] not in ['False', 'True']: |
|---|
| 79 |
raise RuntimeError('Invalid arguments.') |
|---|
| 80 |
arcToolbox = sys.argv[2] == 'True' |
|---|
| 81 |
logFile.write('arcToolbox = %s\n' % str(arcToolbox)) |
|---|
| 82 |
|
|---|
| 83 |
if sys.argv[3] not in ['False', 'True']: |
|---|
| 84 |
raise RuntimeError('Invalid arguments.') |
|---|
| 85 |
comClasses = sys.argv[3] == 'True' |
|---|
| 86 |
logFile.write('comClasses = %s\n' % str(comClasses)) |
|---|
| 87 |
|
|---|
| 88 |
except Exception, e: |
|---|
| 89 |
sys.stderr.write('%s: %s\n' % (str(e.__class__.__name__), str(e))) |
|---|
| 90 |
print('') |
|---|
| 91 |
print('ReportInstallation.py - reports an MGET installation to the MGET statistics server') |
|---|
| 92 |
print('') |
|---|
| 93 |
print('This program is only intended to be invoked by the GeoEco setup program. The') |
|---|
| 94 |
print('setup program uses it to report a successful or failed installation to the') |
|---|
| 95 |
print('server that tracks installation statistics. Please do not invoke this program') |
|---|
| 96 |
print('yourself. Doing so will corrupt the statistics. We use these statistics to') |
|---|
| 97 |
print('assess the software quality of the setup program, identify common installation') |
|---|
| 98 |
print('problems encountered by MGET users, and justify our requests for additional') |
|---|
| 99 |
print('funding.') |
|---|
| 100 |
print('') |
|---|
| 101 |
print('For more information about this program, including a discussion of what data are') |
|---|
| 102 |
print('reported, what we do with the data, and how to disable the reporting, please see') |
|---|
| 103 |
print('the MGET web site. You are also welcome to examine the program source code. If') |
|---|
| 104 |
print('you have any questions, please contact Jason Roberts (jason.roberts@duke.edu).') |
|---|
| 105 |
print('') |
|---|
| 106 |
print('Thanks for your support,') |
|---|
| 107 |
print('') |
|---|
| 108 |
print(' - The MGET Development Team') |
|---|
| 109 |
sys.exit(1) |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
logFile.write('Creating/opening registry key HLKM\\SOFTWARE\\GeoEco.\n') |
|---|
| 117 |
hKey = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\GeoEco') |
|---|
| 118 |
try: |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
try: |
|---|
| 125 |
logFile.write('Querying for the DisableInstallationReporting value.\n') |
|---|
| 126 |
win32api.RegQueryValueEx(hKey, 'DisableInstallationReporting') |
|---|
| 127 |
except: |
|---|
| 128 |
logFile.write('The DisableInstallationReporting value could not be queried. Installation reporting is not disabled.\n') |
|---|
| 129 |
else: |
|---|
| 130 |
logFile.write('The DisableInstallationReporting was successfully queried. Installation reporting is disabled. Exiting without sending a report.\n') |
|---|
| 131 |
print('Installation reporting has been disabled. Exiting without sending a report.') |
|---|
| 132 |
return |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
clientID = None |
|---|
| 137 |
|
|---|
| 138 |
try: |
|---|
| 139 |
logFile.write('Querying for the ClientID value.\n') |
|---|
| 140 |
clientID = win32api.RegQueryValueEx(hKey, 'ClientID')[0] |
|---|
| 141 |
except: |
|---|
| 142 |
logFile.write('Failed to query the ClientID value.\n') |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
if not isinstance(clientID, basestring) or re.match('\{[0123456789AaBbCcDdEeFf]{8}-[0123456789AaBbCcDdEeFf]{4}-[0123456789AaBbCcDdEeFf]{4}-[0123456789AaBbCcDdEeFf]{4}-[0123456789AaBbCcDdEeFf]{12}\}', clientID) is None: |
|---|
| 148 |
clientID = str(pywintypes.CreateGuid()) |
|---|
| 149 |
logFile.write('Writing ClientID value "%s".\n' % clientID) |
|---|
| 150 |
win32api.RegSetValueEx(hKey, 'ClientID', 0, win32con.REG_SZ, clientID) |
|---|
| 151 |
else: |
|---|
| 152 |
clientID = clientID.upper() |
|---|
| 153 |
logFile.write('clientID = %s.\n' % clientID) |
|---|
| 154 |
|
|---|
| 155 |
finally: |
|---|
| 156 |
logFile.write('Closing the registry key.\n') |
|---|
| 157 |
win32api.RegCloseKey(hKey) |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
mgetVer = None |
|---|
| 165 |
try: |
|---|
| 166 |
logFile.write('Importing GeoEco.\n') |
|---|
| 167 |
import GeoEco |
|---|
| 168 |
mgetVer = GeoEco.__version__ |
|---|
| 169 |
except Exception, e: |
|---|
| 170 |
logFile.write('Failed to import GeoEco: %s: %s\n' % (str(e.__class__.__name__), str(e))) |
|---|
| 171 |
else: |
|---|
| 172 |
logFile.write('mgetVer = %s\n' % mgetVer) |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
arcVer = None |
|---|
| 179 |
try: |
|---|
| 180 |
logFile.write('Opening registry key HLKM\\SOFTWARE\\ESRI\\ArcInfo\\Desktop\\8.0.\n') |
|---|
| 181 |
hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\ESRI\\ArcInfo\\Desktop\\8.0') |
|---|
| 182 |
try: |
|---|
| 183 |
logFile.write('Querying for the RealVersion value.\n') |
|---|
| 184 |
realVersion = win32api.RegQueryValueEx(hkey, 'RealVersion')[0].strip() |
|---|
| 185 |
try: |
|---|
| 186 |
logFile.write('Querying for the SPNumber value.\n') |
|---|
| 187 |
spNumber = win32api.RegQueryValueEx(hkey, 'SPNumber')[0].strip() |
|---|
| 188 |
except: |
|---|
| 189 |
spNumber = None |
|---|
| 190 |
finally: |
|---|
| 191 |
logFile.write('Closing the registry key.\n') |
|---|
| 192 |
win32api.RegCloseKey(hkey) |
|---|
| 193 |
|
|---|
| 194 |
if spNumber is None or spNumber == '0': |
|---|
| 195 |
arcVer = realVersion |
|---|
| 196 |
elif realVersion == '9.3' and spNumber == '2': |
|---|
| 197 |
arcVer = '9.3.1' |
|---|
| 198 |
elif realVersion == '9.3' and spNumber > '2': |
|---|
| 199 |
arcVer = '9.3.1 SP%i' % (int(spNumber) - 2) |
|---|
| 200 |
else: |
|---|
| 201 |
arcVer = '%s SP%s' % (realVersion, spNumber) |
|---|
| 202 |
|
|---|
| 203 |
except Exception, e: |
|---|
| 204 |
logFile.write('Failed to get ArcGIS version number: %s: %s\n' % (str(e.__class__.__name__), str(e))) |
|---|
| 205 |
else: |
|---|
| 206 |
logFile.write('arcVer = %s\n' % arcVer) |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
rVer = None |
|---|
| 214 |
try: |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
try: |
|---|
| 219 |
logFile.write('Opening registry key HLKM\\SOFTWARE\\R-core\\R.\n') |
|---|
| 220 |
hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\R-core\\R') |
|---|
| 221 |
try: |
|---|
| 222 |
logFile.write('Querying for the Current Version value.\n') |
|---|
| 223 |
rVer = win32api.RegQueryValueEx(hkey, 'Current Version')[0] |
|---|
| 224 |
finally: |
|---|
| 225 |
logFile.write('Closing the registry key.\n') |
|---|
| 226 |
win32api.RegCloseKey(hkey) |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
except: |
|---|
| 232 |
logFile.write('Failed. Trying the R_HOME environment variable instead.\n') |
|---|
| 233 |
if os.environ.has_key('R_HOME'): |
|---|
| 234 |
rHome = os.environ['R_HOME'] |
|---|
| 235 |
if re.match('^[Rr]-\d+\.\d+\.\d+$', os.path.basename(rHome)): |
|---|
| 236 |
rVer = os.path.basename(rHome)[2:] |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
else: |
|---|
| 243 |
import glob |
|---|
| 244 |
files = glob.glob(os.path.join(rHome, 'README.R-[0123456789].*.*')) |
|---|
| 245 |
if len(files) > 0 and re.match('^\d+\.\d+\.\d+$', os.path.basename(files[0])[9:]) is not None: |
|---|
| 246 |
rVer = os.path.basename(files[0])[9:] |
|---|
| 247 |
|
|---|
| 248 |
except Exception, e: |
|---|
| 249 |
logFile.write('Failed to get R version number: %s: %s\n' % (str(e.__class__.__name__), str(e))) |
|---|
| 250 |
else: |
|---|
| 251 |
logFile.write('rVer = %s\n' % rVer) |
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
logFile.write('Setting the socket default timeout to 60.\n') |
|---|
| 266 |
|
|---|
| 267 |
socket.setdefaulttimeout(60) |
|---|
| 268 |
|
|---|
| 269 |
if sys.version_info[0] == 2 and sys.version_info[1] == 4: |
|---|
| 270 |
clientINIURL = 'http://code.env.duke.edu/projects/mget/statistics/client.ini' |
|---|
| 271 |
else: |
|---|
| 272 |
clientINIURL = 'https://code.env.duke.edu/projects/mget/statistics/client.ini' |
|---|
| 273 |
|
|---|
| 274 |
logFile.write('clientINIURL = %s\n' % clientINIURL) |
|---|
| 275 |
|
|---|
| 276 |
try: |
|---|
| 277 |
iniFileError = 'Step 1: ' |
|---|
| 278 |
config = ConfigParser.ConfigParser() |
|---|
| 279 |
logFile.write('Opening the clientINIURL.\n') |
|---|
| 280 |
iniFileError = 'Step 2: ' |
|---|
| 281 |
f = urllib.urlopen(clientINIURL) |
|---|
| 282 |
try: |
|---|
| 283 |
logFile.write('Parsing the INI file.\n') |
|---|
| 284 |
iniFileError = 'Step 3: ' |
|---|
| 285 |
config.readfp(f) |
|---|
| 286 |
finally: |
|---|
| 287 |
iniFileError = 'Step 4: ' |
|---|
| 288 |
f.close() |
|---|
| 289 |
logFile.write('Getting the URL from the parsed INI file.\n') |
|---|
| 290 |
iniFileError = 'Step 5: ' |
|---|
| 291 |
serverURL = config.get('V1', 'URL') |
|---|
| 292 |
except Exception, e: |
|---|
| 293 |
logFile.write('Failed to get the MGET server URL: %s: %s. The default URL will be used.\n' % (str(e.__class__.__name__), str(e))) |
|---|
| 294 |
serverURL = 'http://mgetstats.nicholas.duke.edu:8001' |
|---|
| 295 |
iniFileError = '%s%s: %s' % (iniFileError, str(e.__class__.__name__), str(e)) |
|---|
| 296 |
else: |
|---|
| 297 |
iniFileError = None |
|---|
| 298 |
|
|---|
| 299 |
logFile.write('serverURL = %s\n' % serverURL) |
|---|
| 300 |
|
|---|
| 301 |
if sys.version_info[0] == 2 and sys.version_info[1] == 4 and serverURL.startswith('https:'): |
|---|
| 302 |
logFile.write('Changing serverURL to http from https because we\'re running on Python 2.4.\n') |
|---|
| 303 |
serverURL = 'http:' + serverURL[6:] |
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
logFile.write('Instantiating the xmlrpclib.Server object.\n') |
|---|
| 309 |
s = xmlrpclib.Server(serverURL, allow_none=True) |
|---|
| 310 |
|
|---|
| 311 |
logFile.write('Calling ReportMGETInstallationV2 on the server.\n') |
|---|
| 312 |
s.ReportMGETInstallationV2(clientID, shortcuts, arcToolbox, comClasses, mgetVer, '.'.join(map(str, sys.version_info[0:3])), arcVer, rVer, iniFileError) |
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
except: |
|---|
| 317 |
try: |
|---|
| 318 |
logFile.write('Caught an exception:\n') |
|---|
| 319 |
logFile.write('\n') |
|---|
| 320 |
logFile.write(traceback.format_exc()) |
|---|
| 321 |
except: |
|---|
| 322 |
pass |
|---|
| 323 |
raise |
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
finally: |
|---|
| 328 |
try: |
|---|
| 329 |
logFile.close() |
|---|
| 330 |
except: |
|---|
| 331 |
pass |
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
os.remove(logFilePath) |
|---|
| 337 |
|
|---|
| 338 |
if __name__ == '__main__': |
|---|
| 339 |
main() |
|---|