-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstaller.py
727 lines (644 loc) · 30.1 KB
/
installer.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
"""
***************************************************************************
Installer.py
-------------------------------------
Copyright (C) 2014 TIGER-NET (www.tiger-net.org)
***************************************************************************
* This installer is part of the Water Observation Information System (WOIS) *
* developed under the TIGER-NET project funded by the European Space *
* Agency as part of the long-term TIGER initiative aiming at promoting *
* the use of Earth Observation (EO) for improved Integrated Water *
* Resources Management (IWRM) in Africa. *
* *
* WOIS is a free software i.e. you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation, either version 3 of the License, *
* or (at your option) any later version. *
* *
* WOIS is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
* for more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************
"""
from PyQt4 import QtCore, QtGui
from installerGUI import installerWelcomeWindow, beamInstallWindow, beamPostInstallWindow, snapInstallWindow, snapPostInstallWindow
from installerGUI import osgeo4wInstallWindow, osgeo4wPostInstallWindow, rInstallWindow, postgreInstallWindow, postgisInstallWindow
from installerGUI import mapwindowInstallWindow, mwswatInstallWindow, mwswatPostInstallWindow, swateditorInstallWindow, finishWindow
from installerGUI import extractingWaitWindow, copyingWaitWindow, cmdWaitWindow, uninstallInstructionsWindow, rPostInstallWindow
from installerGUI import CANCEL, SKIP, NEXT
import os
import sys
import re
import glob
import errno
import shutil
import subprocess
import traceback
import tempfile
import time
from tempfile import NamedTemporaryFile
from zipfile import ZipFile
from distutils import dir_util
import installer_utils
class Installer():
def __init__(self):
self.util = Utilities()
def runInstaller(self):
########################################################################
# welcome window with license
self.dialog = installerWelcomeWindow()
res = self.showDialog()
if res == NEXT:
# select installation files for 32 or 64 bit install
installationsDirs = ['Installations_x32', 'Installations_x64']
if os.path.isdir(installationsDirs[0]):
is32bit = True
installationsDir = installationsDirs[0]
osgeo4wInstall = os.path.join(installationsDir, "osgeo4w-setup.bat")
beamInstall = os.path.join(installationsDir, "beam_5.0_win32_installer.exe")
snapInstall = os.path.join(installationsDir, "esa-snap_sentinel_windows_5_0.exe")
rInstall = os.path.join(installationsDir, "R-3.3.2-win.exe")
postgreInstall = os.path.join(installationsDir, "postgresql-9.3.6-2-windows.exe")
postgisInstall = os.path.join(installationsDir, "postgis-bundle-pg93x32-setup-2.1.5-1.exe")
mapwindowInstall = os.path.join(installationsDir, "MapWindowx86Full-v488SR-installer.exe")
mwswatInstall = os.path.join(installationsDir, "MWSWAT2009.exe")
swateditorInstall = "MWSWAT additional software\\SwatEditor_Install\\Setup.exe"
elif os.path.isdir(installationsDirs[1]):
is32bit = False
installationsDir = installationsDirs[1]
osgeo4wInstall = os.path.join(installationsDir, "osgeo4w-setup.bat")
beamInstall = os.path.join(installationsDir, "beam_5.0_win64_installer.exe")
snapInstall = os.path.join(installationsDir, "esa-snap_sentinel_windows-x64_5_0.exe")
rInstall = os.path.join(installationsDir, "R-3.3.2-win.exe")
postgreInstall = os.path.join(installationsDir, "postgresql-9.3.6-2-windows-x64.exe")
postgisInstall = os.path.join(installationsDir, "postgis-bundle-pg93x64-setup-2.1.5-2.exe")
mapwindowInstall = os.path.join(installationsDir, "MapWindowx86Full-v488SR-installer.exe")
mwswatInstall = os.path.join(installationsDir, "MWSWAT2009.exe")
swateditorInstall = "MWSWAT additional software\\SwatEditor_Install\\Setup.exe"
else:
self.util.error_exit('Neither 32 bit nor 64 bit instalations directory exists. Package incomplete.')
return
# select default installation directories for 32 or 64 bit install
if is32bit:
osgeo4wDefaultDir = "C:\\OSGeo4W"
snapDefaultDir = "C:\\Program Files\\snap"
beamDefaultDir = "C:\\Program Files\\beam-5.0"
mapwindowDefaultDir = "C:\\Program Files\\MapWindow"
rDefaultDir = "C:\\Program Files\\R\\R-3.3.2"
else:
osgeo4wDefaultDir = "C:\\OSGeo4W64"
snapDefaultDir = "C:\\Program Files\\snap"
beamDefaultDir = "C:\\Program Files\\beam-5.0"
mapwindowDefaultDir = "C:\\Program Files (x86)\\MapWindow"
rDefaultDir = "C:\\Program Files\\R\\R-3.3.2"
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
########################################################################
# Information about uninstalling old version
self.dialog = uninstallInstructionsWindow()
res = self.showDialog()
if res == CANCEL:
del self.dialog
return
########################################################################
# Install OSGeo4W (QGIS, OTB, SAGA, GRASS)
self.dialog = osgeo4wInstallWindow()
res = self.showDialog()
# run the OSGeo4W installation here as an outside process
if res == NEXT:
self.util.execSubprocess(osgeo4wInstall)
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
# ask for post-installation even if user has skipped installation
self.dialog = osgeo4wPostInstallWindow(osgeo4wDefaultDir)
res = self.showDialog()
# copy plugins, scripts, and models and activate processing providers
if res == NEXT:
# pip installations
dirPath = str(self.dialog.dirPathText.toPlainText())
# copy the plugins
dstPath = os.path.join(os.path.expanduser("~"), ".qgis2", "python", 'plugins')
srcPath = os.path.join("QGIS additional software", "plugins.zip")
# try to delete old plugins before copying the new ones to avoid conflicts
plugins_to_delete = [
'mikecprovider',
'processing',
'processing_gpf',
'photo2shape',
'processing_workflow',
'processing_SWAT',
'openlayers_plugin',
'pointsamplingtool',
'temporalprofiletool',
'valuetool']
for plugin in plugins_to_delete:
self.util.deleteDir(
os.path.join(dstPath, plugin))
# show dialog because it might take some time on slower computers
self.dialog = extractingWaitWindow(self.util, srcPath, dstPath)
self.showDialog()
# copy scripts and models
QGIS_extras_dir = os.path.abspath("QGIS additional software")
dstPath = os.path.join(os.path.expanduser("~"), ".qgis2", "processing")
for zipfname in [
'WOIS_scripts.zip', 'WOIS_models_and_workflows.zip']:
srcPath = os.path.join(QGIS_extras_dir, zipfname)
# show dialog because it might take some time on slower computers
self.dialog = extractingWaitWindow(self.util, srcPath, dstPath)
self.showDialog()
# additional python modules
site_packages = os.path.join(dirPath, 'apps', 'Python27', 'Lib', 'site-packages')
# install fmask and rios
srcPath = os.path.join(QGIS_extras_dir, 'fmask-rios.zip')
self.dialog = extractingWaitWindow(self.util, srcPath, site_packages)
self.showDialog()
# install cv2
srcPath = os.path.join(QGIS_extras_dir, 'cv2.zip')
self.dialog = extractingWaitWindow(self.util, srcPath, site_packages)
self.showDialog()
# activate plugins and processing providers
self.util.activatePlugins()
self.util.activateProcessingProviders(osgeo4wDefaultDir)
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
# #######################################################################
# Install BEAM
self.dialog = beamInstallWindow()
res = self.showDialog()
# run the BEAM installation here as an outside process
if res == NEXT:
self.util.execSubprocess(beamInstall)
# self.dialog = beamPostInstallWindow(beamDefaultDir);
# res = self.showDialog()
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
# ask for post-installation even if user has skipped installation
self.dialog = beamPostInstallWindow(beamDefaultDir)
res = self.showDialog()
# copy the additional BEAM modules and set the amount of memory to be used with GPT
if res == NEXT:
dirPath = str(self.dialog.dirPathText.toPlainText())
dstPath = os.path.join(dirPath,"modules")
srcPath = "BEAM additional modules"
self.dialog = copyingWaitWindow(self.util, srcPath, dstPath) # show dialog because it might take some time on slower computers
self.showDialog()
# 32 bit systems usually have less RAM so assign less to BEAM
ram_fraction = 0.4 if is32bit else 0.6
installer_utils.modifyRamInBatFiles(os.path.join(dirPath, "bin", 'gpt.bat'), ram_fraction)
self.util.activateBEAMplugin(dirPath)
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
########################################################################
# Install Snap Toolbox
self.dialog = snapInstallWindow()
res = self.showDialog()
# run the Snap installation here as an outside process
if res == NEXT:
self.util.execSubprocess(snapInstall)
#self.dialog = snapPostInstallWindow(snapDefaultDir);
#res = self.showDialog()
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
# ask for post-installation even if user has skipped installation
self.dialog = snapPostInstallWindow(snapDefaultDir)
res = self.showDialog()
# Set the amount of memory to be used with NEST GPT
if res == NEXT:
dirPath = str(self.dialog.dirPathText.toPlainText())
confbat = os.path.join(dirPath, 'bin', 'snappy-conf.bat')
osgeopython = os.path.join(osgeo4wDefaultDir, 'bin', 'python.exe')
cmd = [confbat, osgeopython]
# show dialog because it might take some time on slower computers
self.dialog = cmdWaitWindow(self.util, cmd)
self.showDialog()
dstPath = os.path.join(os.path.expanduser("~"), ".snap")
srcPath = "SNAP additional modules"
self.util.copyFiles(srcPath, dstPath)
#self.dialog = copyingWaitWindow(self.util, srcPath, dstPath) # show dialog because it might take some time on slower computers
#self.showDialog()
# 32 bit systems usually have less RAM so assign less to S1 Toolbox
ram_fraction = 0.4 if is32bit else 0.6
settingsfile = os.path.join(dirPath, 'bin', 'gpt.vmoptions')
installer_utils.modifyRamInBatFiles(settingsfile, ram_fraction)
# There is a bug in snap installer so the gpt file has to be
# modified for 32 bit installation
if is32bit:
self.util.removeIncompatibleJavaOptions(settingsfile)
self.util.activateSNAPplugin(dirPath)
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
# #######################################################################
# Install R
self.dialog = rInstallWindow()
res = self.showDialog()
# run the R installation here as an outside process
if res == NEXT:
self.util.execSubprocess(rInstall)
# self.dialog = rPostInstallWindow(rDefaultDir)
# res = self.showDialog()
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
# ask for post-installation even if user has skipped installation
self.dialog = rPostInstallWindow(rDefaultDir)
res = self.showDialog()
# Copy the R additional libraries
if res == NEXT:
dirPath = str(self.dialog.dirPathText.toPlainText())
dstPath = os.path.join(dirPath, "library")
srcPath = "R additional libraries"
# show dialog because it might take some time on slower computers
self.dialog = extractingWaitWindow(self.util, os.path.join(srcPath, "libraries.zip"), dstPath)
self.showDialog()
if is32bit:
self.util.activateRplugin(dirPath, "false")
else:
self.util.activateRplugin(dirPath, "true")
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
########################################################################
# Install PostGIS
postgres_installed = False
self.dialog = postgreInstallWindow()
res = self.showDialog()
# install Postgres
if res == NEXT:
self.util.execSubprocess(postgreInstall)
postgres_installed = True
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
if postgres_installed:
# install PostGIS
self.dialog = postgisInstallWindow()
res = self.showDialog()
if res == NEXT:
self.util.execSubprocess(postgisInstall)
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
########################################################################
# Install MapWindow, SWAT and PEST
mapwindow_installed = False
mswat_installed = False
swateditor_installed = False
# install MapWindow
self.dialog = mapwindowInstallWindow()
res = self.showDialog()
if res == NEXT:
self.util.execSubprocess(mapwindowInstall)
mapwindow_installed = True
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
if mapwindow_installed:
# install MS SWAT
self.dialog = mwswatInstallWindow()
res = self.showDialog()
if res == NEXT:
self.util.execSubprocess(mwswatInstall)
mswat_installed = True
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
if mswat_installed:
# install SWAT editor
self.dialog = swateditorInstallWindow()
res = self.showDialog()
if res == NEXT:
self.util.execSubprocess(swateditorInstall)
time.sleep(5)
swateditor_installed = True
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
if swateditor_installed:
# install SWAT post-installation stuff
self.dialog = mwswatPostInstallWindow(mapwindowDefaultDir)
res = self.showDialog()
if res == NEXT:
# copy the DTU customised MWSWAT 2009 installation
dirPath = str(self.dialog.dirPathText.toPlainText())
mwswatPath = os.path.join(dirPath,"Plugins","MWSWAT2009")
dstPath = os.path.join(mwswatPath,'swat2009DtuEnvVers0.2')
srcPath = "MWSWAT additional software\\swat2009DtuEnvVers0.2"
# show dialog because it might take some time on slower computers
self.dialog = copyingWaitWindow(self.util, srcPath, dstPath)
self.showDialog()
# copy and rename the customised MWSWAT exe
if os.path.isfile(os.path.join(mwswatPath,"swat2009rev481.exe_old")):
os.remove(os.path.join(mwswatPath,"swat2009rev481.exe_old"))
os.rename(os.path.join(mwswatPath,"swat2009rev481.exe"), os.path.join(mwswatPath,"swat2009rev481.exe_old"))
self.util.copyFiles(os.path.join(dstPath, "swat2009DtuEnv.exe"), mwswatPath)
if os.path.isfile(os.path.join(mwswatPath,"swat2009rev481.exe")):
os.remove(os.path.join(mwswatPath,"swat2009rev481.exe"))
os.rename(os.path.join(mwswatPath,"swat2009DtuEnv.exe"), os.path.join(mwswatPath, "swat2009rev481.exe"))
# copy the modified database file
self.util.copyFiles("MWSWAT additional software\\mwswat2009.mdb", mwswatPath)
# copy PEST
self.dialog = copyingWaitWindow(self.util, "MWSWAT additional software\\PEST", os.path.join(mwswatPath,"PEST"))
# show dialog because it might take some time on slower computers
self.showDialog()
# activate the plugin
self.util.activateSWATplugin(dirPath)
elif res == SKIP:
pass
elif res == CANCEL:
del self.dialog
return
else:
self.unknownActionPopup()
# Finish
self.dialog = finishWindow()
self.showDialog()
del self.dialog
def showDialog(self):
return(self.dialog.exec_())
def unknownActionPopup(self):
msgBox = QtGui.QMessageBox()
msgBox.setText("Unknown action chosen in the previous installation step. Ask the developer to check the installation script!\n\n Quitting installation")
msgBox.exec_()
##########################################
# helper functions
class Utilities(QtCore.QObject):
finished = QtCore.pyqtSignal()
def __init__(self):
QtCore.QObject.__init__(self)
# QGIS and processing settings
self.qsettings = QtCore.QSettings("QGIS", "QGIS2")
def execSubprocess(self, command):
# command should be a path to an exe file so check if it exists
if not os.path.isfile(command):
msgBox = QtGui.QMessageBox()
msgBox.setText("Could not find the installation file for this component!\n\n Skipping to next component")
msgBox.exec_()
# self.dialog.action = SKIP
return
proc = subprocess.Popen(
command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True).stdout
for line in iter(proc.readline, ""):
pass
def execute_cmd(self, cmd):
"""Execute cmd and save output to log file"""
with tempfile.NamedTemporaryFile(prefix='wois_installer_', suffix='.log', delete=False) as f:
output = ''
try:
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
output = subprocess.check_output(cmd,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
startupinfo=si)
except:
trace = traceback.format_exc()
msgBox = QtGui.QMessageBox()
msgBox.setText("An error occurred: {}. Log written to \'{}\'.".format(trace, f.name))
msgBox.exec_()
f.write(trace)
if output:
f.write(output)
# debugging only
if False:
msgBox = QtGui.QMessageBox()
msgBox.setText("Output was\n{}".format(output))
msgBox.exec_()
self.finished.emit()
def deleteFile(self, filePath):
try:
os.remove(filePath)
except:
pass
def deleteDir(self, dirPath):
try:
shutil.rmtree(dirPath, ignore_errors=True)
except:
pass
def error_exit(self, msg):
msgBox = QtGui.QMessageBox()
msgBox.setText(msg)
msgBox.exec_()
self.finished.emit()
def copyFiles(self, srcPath, dstPath, checkDstParentExists=True):
# a simple check to see if we are copying to the right directory by making sure that
# its parent exists
if checkDstParentExists:
if not os.path.isdir(os.path.dirname(dstPath)):
self.error_exit("Could not find the destination directory!\n\n No files were copied.")
return
# checkWritePremissions alsoe creates the directory if it doesn't exist yet
if not self.checkWritePermissions(dstPath):
self.error_exit("You do not have permissions to write to destination directory!\n\n No files were copied.\n\n" +
"Re-run the installer with administrator privileges or manually copy files from "+srcPath +
" to "+dstPath+" after the installation process is over.")
return
# for directories copy the whole directory recursively
if os.path.isdir(srcPath):
dir_util.copy_tree(srcPath, dstPath)
# for files create destination directory is necessary and copy the file
elif os.path.isfile(srcPath):
shutil.copy(srcPath, dstPath)
else:
msgBox = QtGui.QMessageBox()
msgBox.setText("Cannot find the source directory!\n\n No files were copied.")
msgBox.exec_()
self.finished.emit()
def unzipArchive(self, archivePath, dstPath):
if not os.path.isfile(archivePath):
self.error_exit("Could not find the archive!\n\n No files were extracted.")
return
# checkWritePremissions also creates the directory if it doesn't exist yet
if not self.checkWritePermissions(dstPath):
self.error_exit("You do not have permissions to write to destination directory!\n\n No files were copied.\n\n" +
"Re-run the installer with administrator privileges or manually unzip files from " + archivePath +
" to "+dstPath+" after the installation process is over.")
return
archive = ZipFile(archivePath)
archive.extractall(dstPath)
archive.close()
self.finished.emit()
def checkWritePermissions(self, dstPath):
try:
if not os.path.isdir(dstPath):
os.makedirs(dstPath)
fp = open(os.path.join(dstPath,"test"), 'w')
except IOError as e:
if e.errno == errno.EACCES:
return False
else:
return False
else:
fp.close()
try:
os.remove(os.path.join(dstPath,"test"))
except:
pass
return True
def removeIncompatibleJavaOptions(self, batFilePath):
# Make sure the snap batch file exists in the given directory
if not os.path.isfile(batFilePath):
msgBox = QtGui.QMessageBox()
msgBox.setText("Could not find the batch file!\n\n Could not modify Java VM options.")
msgBox.exec_()
return
# In the batch file remove the "-XX:+UseLoopPredicate" option which doesn't work with 32 bit installation.
# First do this in a temp file and then copy the temp file to the correct dir
tempFile = NamedTemporaryFile(delete=False)
tempFilePath = tempFile.name
tempFile.close()
with open(tempFilePath, 'w') as outfile, open(batFilePath, 'r') as infile:
for line in infile:
line = re.sub(r"-XX:\+UseLoopPredicate ", "", line)
outfile.write(line)
tempDir = os.path.dirname(tempFilePath)
tempgpt = os.path.join(tempDir, "gpt.bat")
if os.path.isfile(tempgpt):
os.remove(tempgpt)
os.rename(tempFilePath, tempgpt)
shutil.copy(tempgpt, batFilePath)
def setQGISSettings(self, name, value):
self.qsettings.setValue(name, value)
def activateThis(self, *names):
# sets the requested option(s) to 'true'
for name in names:
self.setQGISSettings(name, 'true')
def activatePlugins(self):
self.activateThis(
"PythonPlugins/atmospheric_correction",
"PythonPlugins/processing_workflow",
"PythonPlugins/openlayers_plugin",
"PythonPlugins/photo2shape",
"PythonPlugins/pointsamplingtool",
"PythonPlugins/processing",
"PythonPlugins/temporalprofiletool",
"PythonPlugins/valuetool",
"plugins/zonalstatisticsplugin")
def activateProcessingProviders(self, osgeo4wDefaultDir):
self.setQGISSettings("Processing/configuration/ACTIVATE_GRASS70", "true")
self.setQGISSettings("Processing/configuration/ACTIVATE_GRASS", "true")
self.activateThis(
"Processing/configuration/ACTIVATE_GRASS",
"Processing/configuration/ACTIVATE_MODEL",
"Processing/configuration/ACTIVATE_OTB",
"Processing/configuration/ACTIVATE_QGIS",
"Processing/configuration/ACTIVATE_SAGA",
"Processing/configuration/ACTIVATE_DHIGRAS",
"Processing/configuration/ACTIVATE_SCRIPT",
"Processing/configuration/ACTIVATE_WORKFLOW",
"Processing/configuration/ACTIVATE_WOIS_TOOLBOX",
"Processing/configuration/GRASS_LOG_COMMANDS",
"Processing/configuration/GRASS_LOG_CONSOLE",
"Processing/configuration/SAGA_LOG_COMMANDS",
"Processing/configuration/SAGA_LOG_CONSOLE",
"Processing/configuration/USE_FILENAME_AS_LAYER_NAME",
"Processing/configuration/TASKBAR_BUTTON_WOIS_TOOLBOX")
self.setQGISSettings("Processing/configuration/TASKBAR_BUTTON_WORKFLOW", "false")
# GRASS_FOLDER depends on GRASS version and must be set explicitly here
try:
grass_root = os.path.join(osgeo4wDefaultDir, 'apps', 'grass')
grass_folders = sorted([d for d in glob.glob(os.path.join(grass_root, 'grass-*')) if os.path.isdir(d)])
grassFolder = grass_folders[-1]
self.setQGISSettings("Processing/configuration/GRASS_FOLDER", grassFolder)
except (IndexError, OSError):
pass
def activateBEAMplugin(self, dirPath):
self.activateThis(
"PythonPlugins/processing_gpf",
"Processing/configuration/ACTIVATE_BEAM")
self.setQGISSettings("Processing/configuration/BEAM_FOLDER", dirPath)
def activateSNAPplugin(self, dirPath):
self.activateThis(
"PythonPlugins/processing_gpf",
"Processing/configuration/ACTIVATE_SNAP")
self.activateThis(
"Processing/configuration/S1TBX_ACTIVATE",
"Processing/configuration/S2TBX_ACTIVATE")
self.setQGISSettings("Processing/configuration/SNAP_FOLDER", dirPath)
def activateRplugin(self, dirPath, use64):
self.activateThis(
"Processing/configuration/ACTIVATE_R")
self.setQGISSettings("Processing/configuration/R_FOLDER", dirPath)
self.setQGISSettings("Processing/configuration/R_USE64", use64)
def activateSWATplugin(self, dirPath):
self.activateThis(
"PythonPlugins/processing_SWAT",
"Processing/configuration/ACTIVATE_WG9HM")
self.setQGISSettings("Processing/configuration/MAPWINDOW_FOLDER", dirPath)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
installer = Installer()
# Fix to make sure that runInstaller is executed in the app event loop
def _slot_installer():
QtCore.SLOT(installer.runInstaller())
QtCore.QTimer.singleShot(200, _slot_installer)
app.exec_()