forked from CVL-dev/cvl-fabric-launcher
-
Notifications
You must be signed in to change notification settings - Fork 6
/
launcher.py
executable file
·1853 lines (1610 loc) · 83.3 KB
/
launcher.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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# MASSIVE/CVL Launcher - easy secure login for the MASSIVE Desktop and the CVL
#
# Copyright (c) 2012-2013, Monash e-Research Centre (Monash University, Australia)
# All rights reserved.
#
# This program is free software: 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
# any later version.
#
# In addition, redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of the Monash University nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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/>.
#
# Enquiries: help@massive.org.au
# launcher.py
"""
A wxPython GUI to provide easy login to the MASSIVE Desktop.
It can be run using "python launcher.py", assuming that you
have an appropriate (32-bit or 64-bit) version of Python
installed (*), wxPython, and the dependent Python modules
listed in the DEPENDENCIES file.
(*) wxPython 2.8.x on Mac OS X doesn't support 64-bit mode.
The py2app module is required to build the "MASSIVE Launcher.app"
application bundle on Mac OS X, which can be built as follows:
python create_mac_bundle.py py2app
To build a DMG containing the app bundle and a symbolic link to
Applications, you can run:
python package_mac_version.py <version_number>
See: https://confluence-vre.its.monash.edu.au/display/CVL/MASSIVE+Launcher+Mac+OS+X+build+instructions
The PyInstaller module, bundled with the Launcher code is used
to build the Windows and Linux executables. The Windows setup wizard
(created with InnoSetup) can be built using:
package_windows_version.bat C:\path\to\code\signing\certificate.pfx <certificate_password>
assuming that you have InnoSetup installed and that you have signtool.exe installed for
code signing.
See: https://confluence-vre.its.monash.edu.au/display/CVL/MASSIVE+Launcher+Windows+build+instructions
If you want to build a stand-alone Launcher binary for Mac or Windows
without using a code-signing certificate, you can do so by commenting
out the code-signing functionality in package_mac_version.py and in
package_windows_version.bat. In other words, sorry, this is not
possible at present without modifying the packaging scripts.
A self-contained Linux binary distribution can be built using
PyInstaller, as described on the following wiki page.
See: https://confluence-vre.its.monash.edu.au/display/CVL/MASSIVE+Launcher+Linux+build+instructions
"""
# Make sure that the Launcher doesn't attempt to write to
# "MASSIVE Launcher.exe.log", because it might not have
# permission to do so.
import sys
if sys.platform.startswith("win"):
sys.stderr = sys.stdout
if sys.platform.startswith("win"):
import _winreg
import subprocess
import wx
import time
import traceback
import threading
import os
import HTMLParser
import urllib2
import launcher_version_number
import xmlrpclib
import appdirs
import ConfigParser
import datetime
import shlex
import inspect
import requests
from StringIO import StringIO
import logging
import LoginTasks
from utilityFunctions import *
import cvlsshutils.sshKeyDist
import cvlsshutils
import launcher_progress_dialog
from menus.IdentityMenu import IdentityMenu
import tempfile
from cvlsshutils.KeyModel import KeyModel
import siteConfig
import Queue
if sys.platform.startswith("darwin"):
from MacMessageDialog import LauncherMessageDialog
elif sys.platform.startswith("win"):
from WindowsMessageDialog import LauncherMessageDialog
elif sys.platform.startswith("linux"):
from LinuxMessageDialog import LauncherMessageDialog
from logger.Logger import logger
import collections
import optionsDialog
import LauncherOptionsDialog
from utilityFunctions import LAUNCHER_URL
import dialogtext
dialogs=dialogtext.default()
class FileDrop(wx.FileDropTarget):
def __init__(self, window):
super(FileDrop,self).__init__()
self.window = window
def OnDropFiles(self, x, y, filenames):
if len(filenames)!=1:
pass
else:
self.window.loadSession(None,filenames[0])
class LauncherMainFrame(wx.Frame):
PERM_SSH_KEY=0
TEMP_SSH_KEY=1
def shouldSave(self,item):
# I should be able to use a python iterator here
shouldSave=False
for ctrl in self.savedControls:
if isinstance(item,ctrl) and 'jobParams' in item.GetName():
shouldSave=True
return shouldSave
# Use this method to read a specifig section of the preferences file
def loadConfig(self):
assert self.prefs == None
try:
self.prefs=ConfigParser.SafeConfigParser(allow_no_value=True)
except:
# For compatibility with older ConfigParser on Centos6
self.prefs=ConfigParser.SafeConfigParser()
if (os.path.exists(launcherPreferencesFilePath)):
with open(launcherPreferencesFilePath,'r') as o:
self.prefs.readfp(o)
def getPrefsSection(self,section):
assert self.prefs != None
options = {}
if self.prefs.has_section(section):
optionsList = self.prefs.items(section)
for option in optionsList:
key = option[0]
value = option[1]
if value=='True':
value = True
if value=='False':
value = False
options[key] = value
return options
def setPrefsSection(self,section,options):
assert self.prefs != None
if not self.prefs.has_section(section):
self.prefs.add_section(section)
for key in options.keys():
self.prefs.set(section,key,"%s"%options[key])
pass
def loadSiteDefaults(self,configName):
try:
site=self.sites[configName]
for key in site.defaults:
logger.debug("setting default value for %s"%key)
try:
self.FindWindowByName(key).SetValue(int(site.defaults[key]))
except ValueError as e:
try:
self.FindWindowByName(key).SetValue(site.defaults[key])
except Exception as e:
raise e
except Exception as e:
logger.debug("unable to set the default values for the site: %s"%e)
# Use this method to a) Figure out if we have a default site b) load the parameters for that site.
def loadPrefs(self,window=None,site=None):
assert self.prefs != None
if window==None:
window=self
if (site==None):
siteConfigComboBox=self.FindWindowByName('jobParams_configName')
try:
site=siteConfigComboBox.GetValue()
except:
pass
if (site != None):
if self.prefs.has_section(site):
for item in window.GetChildren():
if self.shouldSave(item):
name=item.GetName()
if self.prefs.has_option(site,name):
val=self.prefs.get(site,name)
try: # Most wx Controls expect a string in SetValue, but at least SpinCtrl expects an int.
item.SetValue(val)
except TypeError:
item.SetValue(int(val))
except AttributeError:
item.SetSelection(int(val))
else:
self.loadPrefs(window=item,site=site)
def savePrefsEventHandler(self,event):
threading.Thread(target=self.savePrefs).start()
event.Skip()
def savePrefs(self,window=None,section=None):
assert self.prefs!=None
specialSections=['Global Preferences','configured_sites']
write=False
# If we called savePrefs without a window specified, its the root of recussion
if (window==None and not section in specialSections):
write=True
window=self
if (section in specialSections):
write=True
window=None
if (section==None):
try:
configName=self.FindWindowByName('jobParams_configName').GetValue()
if (configName!=None):
if (not self.prefs.has_section("Launcher Config")):
self.prefs.add_section("Launcher Config")
self.prefs.set("Launcher Config","siteConfigDefault",'%s'%configName)
self.savePrefs(section=configName)
except:
pass
elif (section!=None):
if (not self.prefs.has_section(section)):
self.prefs.add_section(section)
try:
for item in window.GetChildren():
if self.shouldSave(item):
try:
self.prefs.set(section,item.GetName(),'%s'%item.GetValue())
except AttributeError:
self.prefs.set(section,item.GetName(),'%s'%item.GetSelection())
else:
self.savePrefs(section=section,window=item)
except:
pass
if (write):
with open(launcherPreferencesFilePath,'w') as o:
self.prefs.write(o)
def __init__(self, parent, id, title):
super(LauncherMainFrame,self).__init__(parent, id, title, style=wx.DEFAULT_FRAME_STYLE^wx.RESIZE_BORDER )
dt=FileDrop(self)
self.SetDropTarget(dt)
self.programName=title
self.SetSizer(wx.BoxSizer(wx.VERTICAL))
self.SetAutoLayout(0)
self.savedControls=[]
self.savedControls.append(wx.TextCtrl)
self.savedControls.append(wx.ComboBox)
self.savedControls.append(wx.SpinCtrl)
self.savedControls.append(wx.RadioBox)
self.prefs=None
self.loginProcess=[]
import collections
self.networkLog = collections.deque()
self.networkLogThread = None
self.networkLogStopEvent = threading.Event()
self.hiddenWindow = None
self.progressDialog = None
if sys.platform.startswith("win"):
_icon = wx.Icon('MASSIVE.ico', wx.BITMAP_TYPE_ICO)
self.SetIcon(_icon)
if sys.platform.startswith("linux"):
import MASSIVE_icon
self.SetIcon(MASSIVE_icon.getMASSIVElogoTransparent128x128Icon())
self.loadConfig()
self.menu_bar = wx.MenuBar()
self.file_menu = wx.Menu()
self.menu_bar.Append(self.file_menu, "&File")
transferFiles=wx.MenuItem(self.file_menu,wx.ID_ANY,"&Transfer Files")
self.file_menu.AppendItem(transferFiles)
self.Bind(wx.EVT_MENU, self.transferFilesEvent, id=transferFiles.GetId())
shareDesktop=wx.MenuItem(self.file_menu,wx.ID_ANY,"&Share my desktop")
self.file_menu.AppendItem(shareDesktop)
self.Bind(wx.EVT_MENU, self.saveSessionEvent, id=shareDesktop.GetId())
loadSession=wx.MenuItem(self.file_menu,wx.ID_ANY,"&Connect to a collaborator")
self.file_menu.AppendItem(loadSession)
self.Bind(wx.EVT_MENU, self.loadSessionEvent, id=loadSession.GetId())
loadDefaultSessions=wx.MenuItem(self.file_menu,wx.ID_ANY,"&Load defaults")
self.file_menu.AppendItem(loadDefaultSessions)
self.loadDefaultSessionsId=loadDefaultSessions.GetId()
self.Bind(wx.EVT_MENU, self.loadDefaultSessionsEvent, id=loadDefaultSessions.GetId())
manageSites=wx.MenuItem(self.file_menu,wx.ID_ANY,"&Manage sites")
self.file_menu.AppendItem(manageSites)
self.Bind(wx.EVT_MENU,self.manageSitesEventHandler,id=manageSites.GetId())
if sys.platform.startswith("win") or sys.platform.startswith("linux"):
self.file_menu.Append(wx.ID_EXIT, "E&xit", "Close window and exit program.")
self.Bind(wx.EVT_MENU, self.onExit, id=wx.ID_EXIT)
#if sys.platform.startswith("darwin"):
## Only do this for Mac OS X, because other platforms have
## a right-click pop-up menu for wx.TextCtrl with Copy,
## Select All etc. Plus, the menu doesn't look that good on
## the MASSIVE Launcher main dialog, and doesn't work for
## non Mac platforms, because FindFocus() will always
## find the window/dialog which contains the menu.
#self.edit_menu = wx.Menu()
#self.edit_menu.Append(wx.ID_CUT, "Cut", "Cut the selected text")
#self.Bind(wx.EVT_MENU, self.onCut, id=wx.ID_CUT)
#self.edit_menu.Append(wx.ID_COPY, "Copy", "Copy the selected text")
#self.Bind(wx.EVT_MENU, self.onCopy, id=wx.ID_COPY)
#self.edit_menu.Append(wx.ID_PASTE, "Paste", "Paste text from the clipboard")
#self.Bind(wx.EVT_MENU, self.onPaste, id=wx.ID_PASTE)
#self.edit_menu.Append(wx.ID_SELECTALL, "Select All")
#self.Bind(wx.EVT_MENU, self.onSelectAll, id=wx.ID_SELECTALL)
#self.menu_bar.Append(self.edit_menu, "&Edit")
self.edit_menu = wx.Menu()
self.edit_menu.Append(wx.ID_CUT, "Cu&t", "Cut the selected text")
self.Bind(wx.EVT_MENU, self.onCut, id=wx.ID_CUT)
self.edit_menu.Append(wx.ID_COPY, "&Copy", "Copy the selected text")
self.Bind(wx.EVT_MENU, self.onCopy, id=wx.ID_COPY)
self.edit_menu.Append(wx.ID_PASTE, "&Paste", "Paste text from the clipboard")
self.Bind(wx.EVT_MENU, self.onPaste, id=wx.ID_PASTE)
self.edit_menu.Append(wx.ID_SELECTALL, "Select &All")
self.Bind(wx.EVT_MENU, self.onSelectAll, id=wx.ID_SELECTALL)
self.edit_menu.AppendSeparator()
id_preferences=wx.NewId()
if sys.platform.startswith("win") or sys.platform.startswith("linux"):
self.edit_menu.Append(id_preferences, "P&references\tCtrl-P")
else:
self.edit_menu.Append(id_preferences, "&Preferences")
self.Bind(wx.EVT_MENU, self.onOptions, id=id_preferences)
self.menu_bar.Append(self.edit_menu, "&Edit")
self.identity_menu = IdentityMenu()
options=self.getPrefsSection('Global Preferences')
if options.has_key('auth_mode'):
auth_mode = int(options['auth_mode'])
else:
auth_mode = 0
self.identity_menu.initialize(self,auth_mode=auth_mode)
self.menu_bar.Append(self.identity_menu, "&Identity")
self.help_menu = wx.Menu()
helpContentsMenuItemID = wx.NewId()
self.help_menu.Append(helpContentsMenuItemID, "&%s Help"%self.programName)
self.Bind(wx.EVT_MENU, self.onHelpContents, id=helpContentsMenuItemID)
self.help_menu.AppendSeparator()
emailHelpAtMassiveMenuItemID = wx.NewId()
self.help_menu.Append(emailHelpAtMassiveMenuItemID, "Email &help@massive.org.au")
self.Bind(wx.EVT_MENU, self.onEmailHelpAtMassive, id=emailHelpAtMassiveMenuItemID)
submitDebugLogMenuItemID = wx.NewId()
self.help_menu.Append(submitDebugLogMenuItemID, "&Submit debug log")
self.Bind(wx.EVT_MENU, self.onSubmitDebugLog, id=submitDebugLogMenuItemID)
# On Mac, the About menu item will automatically be moved from
# the Help menu to the "MASSIVE Launcher" menu, so we don't
# need a separator.
if not sys.platform.startswith("darwin"):
self.help_menu.AppendSeparator()
self.help_menu.Append(wx.ID_ABOUT, "&About %s"%self.programName)
self.Bind(wx.EVT_MENU, self.onAbout, id=wx.ID_ABOUT)
self.menu_bar.Append(self.help_menu, "&Help")
self.SetTitle(self.programName)
self.loginDialogPanel = wx.Panel(self, wx.ID_ANY)
self.loginDialogPanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
self.GetSizer().Add(self.loginDialogPanel)
self.loginFieldsPanel = wx.Panel(self.loginDialogPanel, wx.ID_ANY)
self.loginFieldsPanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
self.loginDialogPanel.GetSizer().Add(self.loginFieldsPanel, flag=wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT, border=10)
widgetWidth1 = 180
widgetWidth2 = 180
if not sys.platform.startswith("win"):
widgetWidth2 = widgetWidth2 + 25
# widgetWidth3 = 75
widgetWidth3 = 125 # on Fedora 23 (XFCE4) the theme of the SpinCtrl will set "+" and "-" button side-by-side - this requires more space
self.noneVisible={}
self.noneVisible['usernamePanel']=False
self.noneVisible['projectPanel']=False
self.noneVisible['execHostPanel']=False
self.noneVisible['resourcePanel']=False
self.noneVisible['resolutionPanel']=False
self.noneVisible['cipherPanel']=False
self.noneVisible['debugCheckBoxPanel']=False
self.noneVisible['advancedCheckBoxPanel']=False
self.noneVisible['optionsDialog']=False
self.noneVisible['argsPanel']=False
self.sites={}
self.siteConfigPanel = wx.Panel(self.loginFieldsPanel, wx.ID_ANY)
self.siteConfigPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.configLabel = wx.StaticText(self.siteConfigPanel, wx.ID_ANY, 'Site',name='label_config')
self.siteConfigPanel.GetSizer().Add(self.configLabel, proportion=0, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER, border=5)
self.siteConfigComboBox = wx.ComboBox(self.siteConfigPanel, wx.ID_ANY, choices=self.sites.keys(), style=wx.CB_READONLY,name='jobParams_configName')
self.siteConfigComboBox.Bind(wx.EVT_COMBOBOX, self.onSiteConfigChanged)
self.siteConfigPanel.GetSizer().Add(self.siteConfigComboBox, proportion=1,flag=wx.EXPAND|wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=5)
self.loginFieldsPanel.GetSizer().Add(self.siteConfigPanel,proportion=0,flag=wx.EXPAND)
self.loginHostPanel=wx.Panel(self.loginFieldsPanel,name='loginHostPanel')
self.loginHostPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.loginHostLabel = wx.StaticText(self.loginHostPanel, wx.ID_ANY, 'Server name or IP',name='label_loginHost')
self.loginHostPanel.GetSizer().Add(self.loginHostLabel, proportion=1,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=5)
self.loginHostTextField = wx.TextCtrl(self.loginHostPanel, wx.ID_ANY, size=(widgetWidth2, -1),name='jobParams_loginHost')
self.loginHostPanel.GetSizer().Add(self.loginHostTextField, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=5)
self.loginFieldsPanel.GetSizer().Add(self.loginHostPanel,proportion=0,flag=wx.EXPAND)
self.usernamePanel=wx.Panel(self.loginFieldsPanel,name='usernamePanel')
self.usernamePanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.usernameLabel = wx.StaticText(self.usernamePanel, wx.ID_ANY, 'Username',name='label_username')
self.usernamePanel.GetSizer().Add(self.usernameLabel, proportion=1,flag=wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT, border=5)
self.usernameTextField = wx.TextCtrl(self.usernamePanel, wx.ID_ANY, size=(widgetWidth2, -1),name='jobParams_username')
self.usernamePanel.GetSizer().Add(self.usernameTextField, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=5)
self.loginFieldsPanel.GetSizer().Add(self.usernamePanel,proportion=0,flag=wx.EXPAND)
self.projectPanel = wx.Panel(self.loginFieldsPanel,wx.ID_ANY,name="projectPanel")
self.projectPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.projectLabel = wx.StaticText(self.projectPanel, wx.ID_ANY, 'Project',name='label_project')
self.projectPanel.GetSizer().Add(self.projectLabel, proportion=1, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=5)
self.projectField = wx.TextCtrl(self.projectPanel, wx.ID_ANY, size=(widgetWidth2, -1), name='jobParams_project')
#self.projectComboBox.Bind(wx.EVT_TEXT, self.onProjectTextChanged)
self.projectPanel.GetSizer().Add(self.projectField, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=5)
self.loginFieldsPanel.GetSizer().Add(self.projectPanel, proportion=0,flag=wx.EXPAND|wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT)
self.resourcePanel = wx.Panel(self.loginFieldsPanel, wx.ID_ANY,name="resourcePanel")
# self.resourcePanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.resourcePanel.SetSizer(wx.FlexGridSizer(rows=2,cols=4))
self.hoursLabel = wx.StaticText(self.resourcePanel, wx.ID_ANY, 'Hours requested',name='label_hours')
self.resourcePanel.GetSizer().Add(self.hoursLabel, proportion=1,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,border=5)
# Maximum of 336 hours is 2 weeks:
#self.massiveHoursField = wx.SpinCtrl(self.massiveLoginFieldsPanel, wx.ID_ANY, value=self.massiveHoursRequested, min=1,max=336)
self.hoursField = wx.SpinCtrl(self.resourcePanel, wx.ID_ANY, size=(widgetWidth3,-1), min=1,max=336,name='jobParams_hours')
self.resourcePanel.GetSizer().Add(self.hoursField, proportion=0,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,border=5)
self.memLabel = wx.StaticText(self.resourcePanel, wx.ID_ANY, 'Memory (GB)',name='label_mem')
self.resourcePanel.GetSizer().Add(self.memLabel, proportion=1,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,border=5)
# Maximum of 336 mem is 2 weeks:
#self.massiveHoursField = wx.SpinCtrl(self.massiveLoginFieldsPanel, wx.ID_ANY, value=self.massiveHoursRequested, min=1,max=336)
self.memField = wx.SpinCtrl(self.resourcePanel, wx.ID_ANY, size=(widgetWidth3,-1), min=1,max=1024,name='jobParams_mem')
self.resourcePanel.GetSizer().Add(self.memField, proportion=0,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,border=5)
self.nodesLabel = wx.StaticText(self.resourcePanel, wx.ID_ANY, 'Nodes',name='label_nodes')
self.resourcePanel.GetSizer().Add(self.nodesLabel, proportion=1,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,border=5)
self.nodesField = wx.SpinCtrl(self.resourcePanel, wx.ID_ANY, value="1", size=(widgetWidth3,-1), min=1,max=10,name='jobParams_nodes')
self.resourcePanel.GetSizer().Add(self.nodesField, proportion=0,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,border=5)
self.ppnLabel = wx.StaticText(self.resourcePanel, wx.ID_ANY, 'PPN',name='label_ppn')
self.resourcePanel.GetSizer().Add(self.ppnLabel, proportion=1,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,border=5)
self.ppnField = wx.SpinCtrl(self.resourcePanel, wx.ID_ANY, value="12", size=(widgetWidth3,-1), min=1,max=12,name='jobParams_ppn')
self.resourcePanel.GetSizer().Add(self.ppnField, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=5)
self.loginFieldsPanel.GetSizer().Add(self.resourcePanel, proportion=0,border=0,flag=wx.EXPAND|wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
self.resolutionPanel = wx.Panel(self.loginFieldsPanel,name="resolutionPanel")
self.resolutionPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.resolutionLabel = wx.StaticText(self.resolutionPanel, wx.ID_ANY, 'Resolution',name='label_resolution')
self.resolutionPanel.GetSizer().Add(self.resolutionLabel, proportion=1,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=5)
defaultResolution = "Default resolution"
vncDisplayResolutions = [
defaultResolution, "1024x768", "1152x864", "1280x800", "1280x1024", "1360x768", "1366x768", "1440x900", "1600x900", "1680x1050", "1920x1080", "1920x1200", "7680x3200",
]
self.resolutionField = wx.ComboBox(self.resolutionPanel, wx.ID_ANY, value=defaultResolution, choices=vncDisplayResolutions, size=(widgetWidth2, -1), style=wx.CB_DROPDOWN,name='jobParams_resolution')
self.resolutionPanel.GetSizer().Add(self.resolutionField, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=5)
self.loginFieldsPanel.GetSizer().Add(self.resolutionPanel,proportion=0,flag=wx.EXPAND)
self.cipherPanel = wx.Panel(self.loginFieldsPanel,name="cipherPanel")
self.cipherPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.sshTunnelCipherLabel = wx.StaticText(self.cipherPanel, wx.ID_ANY, 'SSH tunnel cipher',name='label_cipher')
self.cipherPanel.GetSizer().Add(self.sshTunnelCipherLabel, proportion=1,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=5)
if sys.platform.startswith("win"):
defaultCipher = "arcfour"
sshTunnelCiphers = ["3des-cbc", "aes128-ctr", "blowfish-cbc", "arcfour"]
else:
defaultCipher = "arcfour128"
sshTunnelCiphers = ["3des-cbc", "aes128-ctr", "blowfish-cbc", "arcfour128"]
self.sshTunnelCipherComboBox = wx.ComboBox(self.cipherPanel, wx.ID_ANY, value=defaultCipher, choices=sshTunnelCiphers, size=(widgetWidth2, -1), style=wx.CB_DROPDOWN,name='jobParams_cipher')
self.cipherPanel.GetSizer().Add(self.sshTunnelCipherComboBox, proportion=0,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=5)
self.loginFieldsPanel.GetSizer().Add(self.cipherPanel,proportion=0,flag=wx.EXPAND)
self.argsPanel = wx.Panel(self.loginFieldsPanel,name="argsPanel")
self.argsPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.argsLabel = wx.StaticText(self.argsPanel, wx.ID_ANY, 'Additional arguments',name='label_args')
self.argsPanel.GetSizer().Add(self.argsLabel, proportion=1,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=5)
self.argsField = wx.TextCtrl(self.argsPanel, wx.ID_ANY, size=(widgetWidth2, -1),name='jobParams_args')
self.argsPanel.GetSizer().Add(self.argsField, proportion=0,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=5)
self.loginFieldsPanel.GetSizer().Add(self.argsPanel,proportion=0,flag=wx.EXPAND)
self.checkBoxPanel = wx.Panel(self.loginFieldsPanel,name="checkBoxPanel")
self.checkBoxPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
p = wx.Panel(self.checkBoxPanel,name="debugCheckBoxPanel")
p.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
l = wx.StaticText(p, wx.ID_ANY, 'Show debug window',name='label_debug')
c = wx.CheckBox(p, wx.ID_ANY, "",name='debugCheckBox')
c.Bind(wx.EVT_CHECKBOX, self.onDebugWindowCheckBoxStateChanged)
p.GetSizer().Add(l,border=5,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
p.GetSizer().Add(c,border=5,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
self.checkBoxPanel.GetSizer().Add(p,flag=wx.ALIGN_LEFT)
t=wx.StaticText(self.checkBoxPanel,label="")
self.checkBoxPanel.GetSizer().Add(t,proportion=1,flag=wx.EXPAND)
p = wx.Panel(self.checkBoxPanel,name="advancedCheckBoxPanel")
p.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
l = wx.StaticText(p, wx.ID_ANY, 'Show Advanced Options',name='label_advanced')
c = wx.CheckBox(p, wx.ID_ANY, "",name='advancedCheckBox')
c.Bind(wx.EVT_CHECKBOX, self.onAdvancedVisibilityStateChanged)
p.GetSizer().Add(l,border=5,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
p.GetSizer().Add(c,border=5,flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
self.checkBoxPanel.GetSizer().Add(p,flag=wx.ALIGN_RIGHT)
self.loginFieldsPanel.GetSizer().Add(self.checkBoxPanel,flag=wx.ALIGN_BOTTOM|wx.EXPAND,proportion=1)
#self.tabbedView.AddPage(self.loginFieldsPanel, "Login")
#self.loginDialogPanelSizer.Add(self.tabbedView, flag=wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT, border=10)
# Buttons Panel
self.buttonsPanel = wx.Panel(self.loginDialogPanel, wx.ID_ANY)
#self.buttonsPanel.SetSizer(wx.FlexGridSizer(rows=1, cols=4, vgap=5, hgap=10))
self.buttonsPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
self.manageResButton = wx.Button(self.buttonsPanel,wx.ID_ANY,'Manage Reservations',name='manageResButton')
self.buttonsPanel.GetSizer().Add(self.manageResButton, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.ALIGN_LEFT,border=10)
self.manageResButton.Bind(wx.EVT_BUTTON, self.onManageReservations)
self.exitButton = wx.Button(self.buttonsPanel, wx.ID_ANY, 'Exit')
self.buttonsPanel.GetSizer().Add(self.exitButton, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT, border=10)
self.Bind(wx.EVT_BUTTON, self.onExit, id=self.exitButton.GetId())
self.loginButton = wx.Button(self.buttonsPanel, wx.ID_ANY, 'Login')
self.buttonsPanel.GetSizer().Add(self.loginButton, flag=wx.TOP|wx.BOTTOM|wx.LEFT|wx.RIGHT, border=10)
self.loginButton.Bind(wx.EVT_BUTTON, self.savePrefsEventHandler)
self.loginButton.Bind(wx.EVT_BUTTON, self.onLogin)
self.loginButton.SetDefault()
#self.buttonsPanel.SetMinSize((-1,100))
#self.preferencesButton.Show(False)
self.loginDialogPanel.GetSizer().Add(self.buttonsPanel, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT, border=15)
self.loginDialogStatusBar = LauncherStatusBar(self)
#self.Fit()
#self.Layout()
#self.menu_bar.Show(False)
#self.Centre()
self.hiddenWindow=wx.Frame(self,name='hidden_window')
self.GetSizer().Add(self.hiddenWindow)
self.hiddenWindow.SetSizer(wx.BoxSizer(wx.VERTICAL))
t=wx.TextCtrl(self.hiddenWindow,wx.ID_ANY,name='jobParams_aaf_idp')
self.hiddenWindow.GetSizer().Add(t)
t=wx.TextCtrl(self.hiddenWindow,wx.ID_ANY,name='jobParams_aaf_username')
self.hiddenWindow.GetSizer().Add(t)
# any controls created on this frame will be inaccessible to the user, but if we set them it will cause them to be saved to the config file
self.logWindow = wx.Frame(self, title="%s Debug Log"%self.programName, name="%s Debug Log"%self.programName,pos=(200,150),size=(700,450))
self.logWindow.Bind(wx.EVT_CLOSE, self.onCloseDebugWindow)
self.logWindowPanel = wx.Panel(self.logWindow)
self.logTextCtrl = wx.TextCtrl(self.logWindowPanel, style=wx.TE_MULTILINE|wx.TE_READONLY)
logWindowSizer = wx.FlexGridSizer(rows=2, cols=1, vgap=0, hgap=0)
logWindowSizer.AddGrowableRow(0)
logWindowSizer.AddGrowableCol(0)
logWindowSizer.Add(self.logTextCtrl, flag=wx.EXPAND)
self.submitDebugLogButton = wx.Button(self.logWindowPanel, wx.ID_ANY, 'Submit debug log')
self.Bind(wx.EVT_BUTTON, self.onSubmitDebugLog, id=self.submitDebugLogButton.GetId())
logWindowSizer.Add(self.submitDebugLogButton, flag=wx.ALIGN_RIGHT|wx.TOP|wx.BOTTOM|wx.RIGHT, border=10)
self.logWindowPanel.SetSizer(logWindowSizer)
if sys.platform.startswith("darwin"):
font = wx.Font(13, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Courier New')
else:
font = wx.Font(11, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Courier New')
self.logTextCtrl.SetFont(font)
if sys.platform.startswith("win"):
_icon = wx.Icon('MASSIVE.ico', wx.BITMAP_TYPE_ICO)
self.logWindow.SetIcon(_icon)
if sys.platform.startswith("linux"):
import MASSIVE_icon
self.logWindow.SetIcon(MASSIVE_icon.getMASSIVElogoTransparent128x128Icon())
logger.sendLogMessagesToDebugWindowTextControl(self.logTextCtrl)
import getpass
logger.debug('getpass.getuser(): ' + getpass.getuser())
logger.debug('sys.platform: ' + sys.platform)
import platform
logger.debug('platform.architecture: ' + str(platform.architecture()))
logger.debug('platform.machine: ' + str(platform.machine()))
logger.debug('platform.node: ' + str(platform.node()))
logger.debug('platform.platform: ' + str(platform.platform()))
logger.debug('platform.processor: ' + str(platform.processor()))
logger.debug('platform.release: ' + str(platform.release()))
logger.debug('platform.system: ' + str(platform.system()))
logger.debug('platform.version: ' + str(platform.version()))
logger.debug('platform.uname: ' + str(platform.uname()))
if sys.platform.startswith("win"):
logger.debug('platform.win32_ver: ' + str(platform.win32_ver()))
if sys.platform.startswith("darwin"):
logger.debug('platform.mac_ver: ' + str(platform.mac_ver()))
if sys.platform.startswith("linux"):
logger.debug('platform.linux_distribution: ' + str(platform.linux_distribution()))
logger.debug('platform.libc_ver: ' + str(platform.libc_ver()))
logger.debug('launcher_version_number.version_number: ' + launcher_version_number.version_number)
import commit_def
logger.debug('launcher commit hash: ' + commit_def.LATEST_COMMIT)
logger.debug('cvlsshutils commit hash: ' + commit_def.LATEST_COMMIT_CVLSSHUTILS)
self.contacted_massive_website = False
self.Bind(wx.EVT_CLOSE,self.onExit)
self.startupinfo = None
try:
self.startupinfo = subprocess.STARTUPINFO()
self.startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
self.startupinfo.wShowWindow = subprocess.SW_HIDE
except:
# On non-Windows systems, the previous block will throw:
# "AttributeError: 'module' object has no attribute 'STARTUPINFO'".
if sys.platform.startswith("win"):
logger.debug('exception: ' + str(traceback.format_exc()))
self.creationflags = 0
try:
import win32process
self.creationflags = win32process.CREATE_NO_WINDOW
except:
# On non-Windows systems, the previous block will throw an exception.
if sys.platform.startswith("win"):
logger.debug('exception: ' + str(traceback.format_exc()))
# launcherMainFrame.keyModel must be initialized before the
# user presses the Login button, because the user might
# use the Identity Menu to delete their key etc. before
# pressing the Login button.
self.keyModel = KeyModel(startupinfo=self.startupinfo,creationflags=self.creationflags,temporaryKey=False)
self.keyModelCreated=threading.Event()
self.keyModelCreated.clear()
if options.has_key('monitor_network_checkbox'):
if options['monitor_network_checkbox']:
self.networkLogStopEvent.clear()
self.networkLogThread = threading.Thread(target=self.monitorNetwork,args=[options['monitor_network_url'],self.networkLogStopEvent,self.networkLog])
self.networkLogThread.start()
else:
self.networkLogStopEvent.set()
#self.loadPrefs()
def manageSitesEventHandler(self,event):
t=threading.Thread(target=self.manageSites)
t.start()
def getSitePrefs(self,queue):
options = self.getPrefsSection('configured_sites')
siteList=[]
for s in options.keys():
if 'siteurl' in s:
site=options[s]
number=int(s[7:])
enabled=options['siteenabled%i'%number]
if enabled=='True':
enabled=True
elif enabled=='False':
enabled=False
name=options['sitename%i'%number]
siteList.append({'url':site,'enabled':enabled,'name':name,'number':number})
siteList.sort(key=lambda x:x['number'])
queue.put(siteList)
def getNewSites(self,queue):
newlist=[]
try:
if sys.platform.startswith("linux"):
f=open(os.path.join(sys.path[0],"masterList.url"),'r')
else:
f=open("masterList.url",'r')
url=f.read().rstrip()
logger.debug("master list of sites is available at %s"%url)
newlist=siteConfig.getMasterSites(url)
queue.put(newlist)
except requests.exceptions.RequestException as e:
logger.debug("getNewSites: Exception %s"%e)
logger.debug("getNewSites: Traceback %s"%traceback.format_exc())
queue.put(None)
except Exception as e:
logger.debug("getNewSites: Exception %s"%e)
logger.debug("getNewSites: Traceback %s"%traceback.format_exc())
queue.put(None)
finally:
f.close()
def showSiteListDialog(self,siteList,newlist,q):
import siteListDialog
dlg=siteListDialog.siteListDialog(parent=self,siteList=siteList,newSites=newlist,style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
r=dlg.ShowModal()
q.put([r,dlg.getList()])
def loadNewSitesNonBlocking(self,time=None):
r=Queue.Queue()
timeoutObject=object()
threading.Thread(target=self.getNewSites,args=[r]).start()
if time!=None:
timer=threading.Timer(time,r.put,args=[timeoutObject])
timer.start()
newlist=r.get()
if isinstance(newlist,type([])):
pass
elif newlist == timeoutObject:
raise siteConfig.TimeoutException("Timeout loading new sites")
elif newlist == None:
raise siteConfig.TimeoutException("Timeout loading new sites")
elif isinstance(newlist,type("")):
raise siteConfig.StatusCode(newlist)
else:
raise siteConfig.CancelException("Cancelled load new sites")
return newlist
def manageSites(self,loadDefaultSessions=True):
siteList=[]
tlist=[]
origq=Queue.Queue()
threading.Thread(target=self.getSitePrefs,args=[origq]).start()
wx.CallAfter(wx.BeginBusyCursor)
retry=True
try:
newlist=self.loadNewSitesNonBlocking(time=10)
except siteConfig.CancelException:
newlist=[]
retry=False
except siteConfig.TimeoutException:
newlist=[]
retry=True
except siteConfig.StatusCode as e:
newlist=[]
retry=False
q=Queue.Queue()
wx.CallAfter(wx.EndBusyCursor)
event=threading.Event()
event.clear()
wx.CallAfter(self.createAndShowModalDialog,event,dlgclass=LauncherOptionsDialog.multiButtonDialog,parent=self,title="",message=dialogs.siteListOtherException.message,ButtonLabels=dialogs.siteListOtherException.ButtonLabels,q=q)
event.wait()
button=q.get()
wx.CallAfter(wx.BeginBusyCursor)
origSiteList=origq.get()
wx.CallAfter(wx.EndBusyCursor)
if origSiteList==[] and newlist==[] and retry==True:
q=Queue.Queue()
e=threading.Event()
e.clear()
wx.CallAfter(self.createAndShowModalDialog,e,dlgclass=LauncherOptionsDialog.multiButtonDialog,parent=self,title="",message=dialogs.siteListRetry.message,ButtonLabels=dialogs.siteListRetry.ButtonLabels,q=q)
e.wait()
button=q.get()
if button==0:
retry=False
while retry:
try:
newlist=self.loadNewSitesNonBlocking(time=None)
if isinstance(newlist,type([])) and newlist!=[]:
retry=False
if newlist==None:
retry=True
except Exception as e:
logger.debug("getNewSites: Exception %s"%e)
logger.debug("getNewSites: Traceback %s"%traceback.format_exc())
q=Queue.Queue()
e=threading.Event()
e.clear()
wx.CallAfter(self.createAndShowModalDialog,e,dlgclass=LauncherOptionsDialog.multiButtonDialog,parent=self,title="",message=dialogs.siteListOtherException.message,ButtonLabels=dialogs.siteListOtherException.ButtonLabels,q=q)
e.wait()
button=q.get()
retry=False
if retry:
q=Queue.Queue()
e=threading.Event()
e.clear()
wx.CallAfter(self.createAndShowModalDialog,e,dlgclass=LauncherOptionsDialog.multiButtonDialog,parent=self,title="",message=dialogs.siteListRetry.message,ButtonLabels=dialogs.siteListRetry.ButtonLabels,q=q)
e.wait()
button=q.get()
if button==0:
retry=False
q=Queue.Queue()
import copy
import re
for newsite in newlist:
if newsite.has_key('replaces'):
replaced=False
urls=newsite['replaces']
siteListCopy=copy.copy(origSiteList)
for site in siteListCopy:
for rurl in urls:
if re.search(rurl,site['url']):
if not newsite.has_key('enabled'):
newsite['enabled']=site['enabled']
origSiteList.remove(site)
wx.CallAfter(self.showSiteListDialog,origSiteList,newlist,q)
r=q.get()
if (r[0] == wx.ID_OK):
newSiteList=r[1]
changed=False
if len(newSiteList) == len(origSiteList):
for i in range(0,len(newSiteList)):
if newSiteList[i]['url']!=origSiteList[i]['url'] or newSiteList[i]['enabled']!=origSiteList[i]['enabled'] or newSiteList[i]['name']!=origSiteList[i]['name']:
changed=True
else:
changed=True
if changed:
options={}
i=0
for s in newSiteList:
options['siteurl%i'%i]='%s'%s['url']
options['siteenabled%i'%i]='%s'%s['enabled']
options['sitename%i'%i]='%s'%s['name']
i=i+1
self.prefs.remove_section('configured_sites')
self.setPrefsSection('configured_sites',options)
self.savePrefs(section='configured_sites')
if loadDefaultSessions:
launcherMainFrame.loadDefaultSessions(True)
def walkChildren(self,window=None,i=0,name=''):
if window==None:
window=self
for item in window.GetChildren():
if item.GetName() == name:
return item
else:
r = self.walkChildren(item,i+1,name=name)
if r!=None:
return r
return None
def loadSessionEvent(self,event):
import SharedSessions
# idpwindow=self.FindWindowByName(name='jobParams_aaf_idp')
# print idpwindow
# idp=self.FindWindowByName('jobParams_aaf_idp').GetValue()
idp = self.walkChildren(name='jobParams_aaf_idp').GetValue()
username = self.walkChildren(name='jobParams_aaf_username').GetValue()
# username=self.FindWindowByName('jobParams_aaf_username').GetValue()
s=SharedSessions.SharedSessions(self,idp=idp,username=username)
t=threading.Thread(target=s.retrieveSession)
t.start()
# dlg=wx.FileDialog(self,"Load a session",style=wx.FD_OPEN)
# status=dlg.ShowModal()
# if status==wx.ID_CANCEL:
# logger.debug('loadSession cancelled')
# f=open(dlg.GetPath(),'r')
# self.loadSession(f)
# f.close()
def loadSession(self,f,path=None):
import collections
import json
if path!=None:
f=open(path,'r')
saved=siteConfig.GenericJSONDecoder().decode(f.read())
if isinstance(saved,list):
self.sites=collections.OrderedDict()
keyorder=saved[0]
for key in keyorder:
nk = key
i=1
while nk in self.sites.keys():
i=i+1
nk = key+" %s"%i
self.sites[nk]=saved[1][key]
else:
self.sites=saved
cb=self.FindWindowByName('jobParams_configName')
for i in range(0,cb.GetCount()):
cb.Delete(0)
for s in self.sites.keys():
cb.Append(s)
cb.SetSelection(0)
if path!=None:
f.close()
self.loadSiteDefaults(configName=self.FindWindowByName('jobParams_configName').GetValue())
self.loadPrefs()
self.updateVisibility()
def createAndShowModalDialog(self,event,dlgclass,*args,**kwargs):
dlg=dlgclass(*args,**kwargs)
# Do not use the return value from ShowModal. It seems on MacOS wx3.0, this event handler may run before the onClose method of the dialog
# Resulting in ShowModal returning an incorrect value. If you need the return value, pass a queue to the dialog and get the onClose method to
# put a value on the queue (as is done in multiButtonDialog)
dlg.ShowModal()
event.set()
def createMultiButtonDialog(self,q,*args,**kwargs):
dlg=LauncherOptionsDialog.multiButtonDialog(*args,**kwargs)
q.put(dlg)
def showModalFromThread(self,dlg,q):
r=dlg.ShowModal()
q.put(r)
def loadDefaultSessions(self,redraw=True):
sites=self.getPrefsSection(section='configured_sites')
retry=True
while sites.keys() == [] and retry:
q=Queue.Queue()
e=threading.Event()
wx.CallAfter(self.createAndShowModalDialog,event=e,dlgclass=LauncherOptionsDialog.multiButtonDialog,parent=self,message=dialogs.siteListFirstUseInfo.message,ButtonLabels=dialogs.siteListFirstUseInfo.ButtonLabels,title="",q=q)
e.wait()
button=q.get()
if button==0:
retry=False
else:
self.manageSites()