-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvlAdministrator.py
766 lines (635 loc) · 35.2 KB
/
cvlAdministrator.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
# CVL Administrator - A GUI for launching/managing NeCTAR instances.
# Copyright (C) 2012 James Wettenhall, Monash University
#
# 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 2 of the License, or
# (at your option) any later version.
#
# This program 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Enquires: [email protected] or [email protected]
# cvl.py
"""
A wxPython GUI for the Characterisation Virtual Laboratory
"""
# Later, STDERR will be redirected to logTextCtrl
# For now, we just want make sure that the Launcher doesn't attempt
# to write to CVL Administrator.exe.log, because it might not have
# permission to do so.
import sys
sys.stderr = sys.stdout
if sys.platform.startswith("win"):
import _winreg
import subprocess
import wx
import time
import traceback
import threading
import os
import ssh # Pure Python-based ssh module, based on Paramiko, published on PyPi
#import libssh2 # Unpublished SSH module (Python bindings for libssh2) by Sebastian Noack: git clone git://github.com/wallunit/ssh4py
import HTMLParser
import urllib
import cvl_administrator_version_number
import StringIO
import xmlrpclib
import appdirs
import ConfigParser
import boto
from boto.ec2.connection import EC2Connection
from boto.ec2.regioninfo import RegionInfo
#import logging
#logger = ssh.util.logging.getLogger()
#logger.setLevel(logging.WARN)
defaultImageName = ""
global imageName
imageName = ""
defaultInstanceName = "CVL Instance 1"
instanceName = defaultInstanceName
global sshKeyPair
sshKeyPair = ""
global securityGroup
securityGroup = "default"
global contactEmail
contactEmail = ""
global sshTunnelProcess
sshTunnelProcess = None
global sshTunnelReady
sshTunnelReady = False
global localPortNumber
localPortNumber = "5901"
global privateKeyFile
global launchDialogFrame
launchDialogFrame = None
global ec2CredentialsZipFilePath
ec2CredentialsZipFilePath = ""
global ec2Connection
ec2Connection = None
class MyHtmlParser(HTMLParser.HTMLParser):
def __init__(self):
HTMLParser.HTMLParser.__init__(self)
self.recording = 0
self.data = []
def handle_starttag(self, tag, attributes):
if tag != 'span':
return
if self.recording:
self.recording += 1
return
for name, value in attributes:
if name == 'id' and value == 'CVLAdministratorLatestVersionNumber':
break
else:
return
self.recording = 1
def handle_endtag(self, tag):
if tag == 'span' and self.recording:
self.recording -= 1
def handle_data(self, data):
if self.recording:
self.data.append(data)
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
global logTextCtrl
# The default window style is wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN
# If you remove wx.RESIZE_BORDER from it, you'll get a frame which cannot be resized.
# wx.Frame(parent, style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
if sys.platform.startswith("darwin"):
wx.Frame.__init__(self, parent, id, title, size=(400, 390), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
else:
wx.Frame.__init__(self, parent, id, title, size=(400, 430), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
if sys.platform.startswith("win"):
_icon = wx.Icon('CVL Administrator.ico', wx.BITMAP_TYPE_ICO)
self.SetIcon(_icon)
if sys.platform.startswith("linux"):
import cvlAdministratorIcon
self.SetIcon(cvlAdministratorIcon.getMASSIVElogoTransparent128x128Icon())
self.menu_bar = wx.MenuBar()
if sys.platform.startswith("win") or sys.platform.startswith("linux"):
self.file_menu = wx.Menu()
self.file_menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Close window and exit program.")
self.Bind(wx.EVT_MENU, self.onExit, id=wx.ID_EXIT)
self.menu_bar.Append(self.file_menu, "&File")
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 CVL Administrator main dialog, and doesn't work for
# non Mac platforms, because of 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.help_menu = wx.Menu()
self.help_menu.Append(wx.ID_ABOUT, "&About CVL Administrator")
self.Bind(wx.EVT_MENU, self.onAbout, id=wx.ID_ABOUT)
self.menu_bar.Append(self.help_menu, "&Help")
self.SetTitle("CVL Administrator")
self.SetMenuBar(self.menu_bar)
# Let's implement the About menu using py2app instead,
# so that we can easily insert the version number.
# We may need to treat different OS's differently.
global launchDialogPanel
launchDialogPanel = wx.Panel(self)
global cvlImageNameLabel
cvlImageNameLabel = wx.StaticText(launchDialogPanel, -1, 'Image name', (10, 60))
global cvlInstanceNameLabel
cvlInstanceNameLabel = wx.StaticText(launchDialogPanel, -1, 'Instance name', (10, 100))
global cvlAdministratorSshKeyPairLabel
cvlAdministratorSshKeyPairLabel = wx.StaticText(launchDialogPanel, -1, 'SSH key pair', (10, 140))
global cvlAdministratorSecurityGroupLabel
cvlAdministratorSecurityGroupLabel = wx.StaticText(launchDialogPanel, -1, 'Security group', (10, 180))
global cvlAdministratorContactEmailLabel
cvlAdministratorContactEmailLabel = wx.StaticText(launchDialogPanel, -1, 'Contact email', (10, 220))
widgetWidth1 = 220
widgetWidth2 = 220
if not sys.platform.startswith("win"):
widgetWidth2 = widgetWidth2 + 25
global defaultImageName
#defaultImageName = "Centos 6.2 amd64"
defaultImageName = "CvlDemoSnapshot27071"
images = ec2Connection.get_all_images()
imageNames = []
for image in images:
imageNames.append(image.name)
global imageNameComboBox
global imageName
imageNameComboBox = wx.ComboBox(launchDialogPanel, -1, value='', pos=(125, 55), size=(widgetWidth2, -1),choices=imageNames, style=wx.CB_DROPDOWN)
if config.has_section("CVL Administrator Preferences"):
if config.has_option("CVL Administrator Preferences", "imageName"):
imageName = config.get("CVL Administrator Preferences", "imageName")
else:
config.set("CVL Administrator Preferences","imageName","")
with open(cvlAdministratorPreferencesFilePath, 'wb') as cvlAdministratorPreferencesFileObject:
config.write(cvlAdministratorPreferencesFileObject)
else:
config.add_section("CVL Administrator Preferences")
with open(cvlAdministratorPreferencesFilePath, 'wb') as cvlAdministratorPreferencesFileObject:
config.write(cvlAdministratorPreferencesFileObject)
if imageName.strip()!="":
imageNameComboBox.SetValue(imageName)
else:
imageNameComboBox.SetValue(defaultImageName)
global instanceNameTextField
if sys.platform.startswith("darwin"):
instanceNameTextField = wx.TextCtrl(launchDialogPanel, -1, value=defaultInstanceName, pos=(127, 95), size=(widgetWidth1, -1))
else:
instanceNameTextField = wx.TextCtrl(launchDialogPanel, -1, value=defaultInstanceName, pos=(125, 95), size=(widgetWidth1, -1))
if instanceName.strip()!="":
instanceNameTextField.SelectAll()
instanceNameTextField.SetFocus()
global defaultSshKeyPair
defaultSshKeyPair = ""
ssh_key_pairs = ec2Connection.get_all_key_pairs()
sshKeyPairs = []
for ssh_key_pair in ssh_key_pairs:
sshKeyPairs.append(ssh_key_pair.name)
if len(sshKeyPairs) > 0:
sshKeyPair = sshKeyPairs[0]
global sshKeyPairComboBox
sshKeyPairComboBox = wx.ComboBox(launchDialogPanel, -1, value='', pos=(125, 135), size=(widgetWidth2, -1),choices=sshKeyPairs, style=wx.CB_DROPDOWN)
if config.has_section("CVL Administrator Preferences"):
if config.has_option("CVL Administrator Preferences", "sshKeyPair"):
sshKeyPair = config.get("CVL Administrator Preferences", "sshKeyPair")
else:
config.set("CVL Administrator Preferences","sshKeyPair","")
with open(cvlAdministratorPreferencesFilePath, 'wb') as cvlAdministratorPreferencesFileObject:
config.write(cvlAdministratorPreferencesFileObject)
else:
config.add_section("CVL Administrator Preferences")
with open(cvlAdministratorPreferencesFilePath, 'wb') as cvlAdministratorPreferencesFileObject:
config.write(cvlAdministratorPreferencesFileObject)
if sshKeyPair.strip()!="":
sshKeyPairComboBox.SetValue(sshKeyPair)
else:
sshKeyPairComboBox.SetValue(defaultSshKeyPair)
defaultSecurityGroup = "default"
securityGroup = defaultSecurityGroup
security_groups = ec2Connection.get_all_security_groups()
securityGroups = []
for security_group in security_groups:
securityGroups.append(security_group.name)
global securityGroupComboBox
securityGroupComboBox = wx.ComboBox(launchDialogPanel, -1, value='', pos=(125, 175), size=(widgetWidth2, -1),choices=securityGroups, style=wx.CB_DROPDOWN)
if config.has_section("CVL Administrator Preferences"):
if config.has_option("CVL Administrator Preferences", "securityGroup"):
securityGroup = config.get("CVL Administrator Preferences", "securityGroup")
else:
config.set("CVL Administrator Preferences","securityGroup","")
with open(cvlAdministratorPreferencesFilePath, 'wb') as cvlAdministratorPreferencesFileObject:
config.write(cvlAdministratorPreferencesFileObject)
else:
config.add_section("CVL Administrator Preferences")
with open(cvlAdministratorPreferencesFilePath, 'wb') as cvlAdministratorPreferencesFileObject:
config.write(cvlAdministratorPreferencesFileObject)
if securityGroup.strip()!="":
securityGroupComboBox.SetValue(securityGroup)
else:
securityGroupComboBox.SetValue(defaultSecurityGroup)
global contactEmail
if config.has_section("CVL Administrator Preferences"):
if config.has_option("CVL Administrator Preferences", "contactEmail"):
contactEmail = config.get("CVL Administrator Preferences", "contactEmail")
else:
config.set("CVL Administrator Preferences","contactEmail","")
with open(cvlAdministratorPreferencesFilePath, 'wb') as cvlAdministratorPreferencesFileObject:
config.write(cvlAdministratorPreferencesFileObject)
else:
config.add_section("CVL Administrator Preferences")
with open(cvlAdministratorPreferencesFilePath, 'wb') as cvlAdministratorPreferencesFileObject:
config.write(cvlAdministratorPreferencesFileObject)
global contactEmailTextField
if sys.platform.startswith("darwin"):
contactEmailTextField = wx.TextCtrl(launchDialogPanel, -1, contactEmail, (127, 215), (widgetWidth1, -1))
else:
contactEmailTextField = wx.TextCtrl(launchDialogPanel, -1, contactEmail, (125, 215), (widgetWidth1, -1))
instanceNameTextField.MoveAfterInTabOrder(imageNameComboBox)
sshKeyPairComboBox.MoveAfterInTabOrder(instanceNameTextField)
securityGroupComboBox.MoveAfterInTabOrder(sshKeyPairComboBox)
contactEmailTextField.MoveAfterInTabOrder(securityGroupComboBox)
global cancelButton
cancelButton = wx.Button(launchDialogPanel, 1, 'Cancel', (130, 305))
global loginButton
loginButton = wx.Button(launchDialogPanel, 2, 'Launch', (230, 305))
loginButton.SetDefault()
self.Bind(wx.EVT_BUTTON, self.onCancel, id=1)
self.Bind(wx.EVT_BUTTON, self.onLaunch, id=2)
self.statusbar = MyStatusBar(self)
global launchDialogStatusBar
launchDialogStatusBar = self.statusbar
self.SetStatusBar(self.statusbar)
self.Centre()
def onAbout(self, event):
dlg = wx.MessageDialog(self, "Version " + cvl_administrator_version_number.version_number + "\n",
"CVL Administrator", wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def onExit(self, event):
try:
os.unlink(privateKeyFile.name)
finally:
os._exit(0)
def onCancel(self, event):
try:
os.unlink(privateKeyFile.name)
finally:
os._exit(0)
def onCut(self, event):
textCtrl = self.FindFocus()
if textCtrl is not None:
textCtrl.Cut()
def onCopy(self, event):
textCtrl = self.FindFocus()
if textCtrl is not None:
textCtrl.Copy()
def onPaste(self, event):
textCtrl = self.FindFocus()
if textCtrl is not None:
textCtrl.Paste()
def onSelectAll(self, event):
textCtrl = self.FindFocus()
if textCtrl is not None:
textCtrl.SelectAll()
def onLaunch(self, event):
class LaunchThread(threading.Thread):
"""Launch Thread Class."""
def __init__(self, notify_window):
"""Init Worker Thread Class."""
threading.Thread.__init__(self)
self._notify_window = notify_window
self._want_abort = 0
# This starts the thread running on creation, but you could
# also make the GUI thread responsible for calling this
self.start()
def run(self):
"""Run Worker Thread."""
# This is the time-consuming code executing in the new thread.
waitCursor = wx.StockCursor(wx.CURSOR_WAIT)
launchDialogFrame.SetCursor(waitCursor)
launchDialogPanel.SetCursor(waitCursor)
cvlInstanceNameLabel.SetCursor(waitCursor)
cvlAdministratorContactEmailLabel.SetCursor(waitCursor)
instanceNameTextField.SetCursor(waitCursor)
contactEmailTextField.SetCursor(waitCursor)
cancelButton.SetCursor(waitCursor)
loginButton.SetCursor(waitCursor)
global logTextCtrl
global launchDialogStatusBar
try:
wx.CallAfter(launchDialogStatusBar.SetStatusText, "Launching " + instanceName + "...")
wx.CallAfter(sys.stdout.write, "Launching " + instanceName + "...\n\n")
images = ec2Connection.get_all_images()
image_id = "?"
for image in images:
if image.name == imageName:
image_id = image.id
reservation = ec2Connection.run_instances(image_id,key_name=sshKeyPair,security_groups=[securityGroup],user_data="Contact email: " + contactEmail + "\n")
wx.CallAfter(sys.stdout.write, "reservation = ec2Connection.run_instances(\""+image_id+"\",key_name=\""+sshKeyPair+"\",security_groups=[\""+securityGroup+"\"])\n")
time.sleep(5)
wx.CallAfter(sys.stdout.write, "instance = reservation.instances[0]\n")
instance = reservation.instances[0]
#wx.CallAfter(sys.stdout.write, "\ninstance.add_tag(\"Name\",\"({" + instanceName +"})\")\n")
#instance.add_tag("Name", "({" + instanceName + "})")
#instance.add_tag(({"Name": instanceName}))
#ec2Connection.create_tags([instance.id], {"Name" : instanceName})
#wx.CallAfter(sys.stdout.write, "ec2Connection.create_tags([instance.id], {\"Name\": instanceName})\n")
#ec2Connection.create_tags([instance.id], {"tag:Name": instanceName})
#wx.CallAfter(sys.stdout.write, "\ninstance.add_tag(\"Contact Email\", \"({" + contactEmail + "})\")\n")
#instance.add_tag("Contact Email", "({" + contactEmail+ "})")
while instance.state != "running":
wx.CallAfter(sys.stdout.write, "instance.state = " + instance.state + "...\n")
time.sleep(10)
instance.update()
wx.CallAfter(sys.stdout.write, "instance.state = " + instance.state + "...\n")
wx.CallAfter(sys.stdout.write, "\ninstance.ip_address = " + instance.ip_address + "...\n\n")
#instance.add_tag("Name", instanceName)
wx.CallAfter(sys.stdout.write, "import pprint\n")
import pprint
wx.CallAfter(sys.stdout.write, "instanceProperties = pprint.pprint(instance.__dict__)\n")
instanceProperties = pprint.pformat(instance.__dict__)
wx.CallAfter(sys.stdout.write, instanceProperties + "\n")
except:
wx.CallAfter(sys.stdout.write, "CVL Administrator v" + cvl_administrator_version_number.version_number + "\n")
wx.CallAfter(sys.stdout.write, traceback.format_exc())
arrowCursor = wx.StockCursor(wx.CURSOR_ARROW)
launchDialogFrame.SetCursor(arrowCursor)
launchDialogPanel.SetCursor(arrowCursor)
cvlInstanceNameLabel.SetCursor(arrowCursor)
cvlAdministratorContactEmailLabel.SetCursor(arrowCursor)
instanceNameTextField.SetCursor(arrowCursor)
contactEmailTextField.SetCursor(arrowCursor)
cancelButton.SetCursor(arrowCursor)
loginButton.SetCursor(arrowCursor)
def abort(self):
"""abort worker thread."""
# Method for use by main thread to signal an abort
self._want_abort = 1
imageName = imageNameComboBox.GetValue()
instanceName = instanceNameTextField.GetValue()
sshKeyPair = sshKeyPairComboBox.GetValue()
securityGroup = securityGroupComboBox.GetValue()
contactEmail = contactEmailTextField.GetValue()
config.set("CVL Administrator Preferences","imageName",imageName)
config.set("CVL Administrator Preferences","sshKeyPair",sshKeyPair)
config.set("CVL Administrator Preferences","securityGroup",securityGroup)
config.set("CVL Administrator Preferences","contactEmail",contactEmail)
with open(cvlAdministratorPreferencesFilePath, 'wb') as cvlAdministratorPreferencesFileObject:
config.write(cvlAdministratorPreferencesFileObject)
logWindow = wx.Frame(self, title="Launching a Characterisation Virtual Laboratory Instance", name="CVL Launch Instance",pos=(200,150),size=(800,500))
if sys.platform.startswith("win"):
_icon = wx.Icon('CVL Administrator.ico', wx.BITMAP_TYPE_ICO)
logWindow.SetIcon(_icon)
if sys.platform.startswith("linux"):
import cvlAdministratorIcon
logWindow.SetIcon(cvlAdministratorIcon.getMASSIVElogoTransparent128x128Icon())
logTextCtrl = wx.TextCtrl(logWindow, style=wx.TE_MULTILINE|wx.TE_READONLY)
gs = wx.GridSizer(rows=1, cols=1, vgap=5, hgap=5)
gs.Add(logTextCtrl, 0, wx.EXPAND)
logWindow.SetSizer(gs)
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')
logTextCtrl.SetFont(font)
logWindow.Show(True)
sys.stdout = logTextCtrl
sys.stderr = logTextCtrl
LaunchThread(self)
class MyStatusBar(wx.StatusBar):
def __init__(self, parent):
wx.StatusBar.__init__(self, parent)
self.SetFieldsCount(2)
self.SetStatusText('Welcome to the Characterisation Virtual Laboratory', 0)
self.SetStatusWidths([-5, -2])
class MyApp(wx.App):
def OnInit(self):
appDirs = appdirs.AppDirs("CVL Administrator", "Monash University")
appUserDataDir = appDirs.user_data_dir
# Add trailing slash:
appUserDataDir = os.path.join(appUserDataDir,"")
if not os.path.exists(appUserDataDir):
os.makedirs(appUserDataDir)
global config
config = ConfigParser.RawConfigParser(allow_no_value=True)
global cvlAdministratorPreferencesFilePath
cvlAdministratorPreferencesFilePath = os.path.join(appUserDataDir,"CVL Administrator Preferences.cfg")
if os.path.exists(cvlAdministratorPreferencesFilePath):
config.read(cvlAdministratorPreferencesFilePath)
tempFrame = wx.Frame(None, -1)
tempFrame.Center()
#cvlAdministratorURL = "https://www.cvlAdministrator.org.au/index.php?option=com_content&view=article&id=121"
#try:
#myHtmlParser = MyHtmlParser()
#feed = urllib.urlopen(cvlAdministratorURL)
#html = feed.read()
#myHtmlParser.feed(html)
#myHtmlParser.close()
#except:
#dlg = wx.MessageDialog(tempFrame, "Error: Unable to contact MASSIVE website to check version number.\n\n" +
#"CVL Administrator cannot continue.\n",
#"CVL Administrator", wx.OK | wx.ICON_INFORMATION)
#dlg.ShowModal()
#dlg.Destroy()
#sys.exit(1)
#latestVersion = myHtmlParser.data[0].strip()
dlg = wx.MessageDialog(tempFrame, "Warning: Bypassing version number check for now...\n", "CVL Administrator", wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
latestVersion = "0.0.1"
if latestVersion!=cvl_administrator_version_number.version_number:
newVersionAlertDialog = wx.Dialog(tempFrame, title="CVL Administrator", name="CVL Administrator",pos=(200,150),size=(680,290))
if sys.platform.startswith("win"):
_icon = wx.Icon('CVL Administrator.ico', wx.BITMAP_TYPE_ICO)
newVersionAlertDialog.SetIcon(_icon)
if sys.platform.startswith("linux"):
import cvlAdministratorIcon
newVersionAlertDialog.SetIcon(cvlAdministratorIcon.getMASSIVElogoTransparent128x128Icon())
cvlAdministratorIconPanel = wx.Panel(newVersionAlertDialog)
import cvlAdministratorIcon
cvlAdministratorIconAsBitmap = cvlAdministratorIcon.getMASSIVElogoTransparent128x128Bitmap()
wx.StaticBitmap(cvlAdministratorIconPanel, -1,
cvlAdministratorIconAsBitmap,
(0, 50),
(cvlAdministratorIconAsBitmap.GetWidth(), cvlAdministratorIconAsBitmap.GetHeight()))
newVersionAlertTextPanel = wx.Panel(newVersionAlertDialog)
gs = wx.FlexGridSizer(rows=4, cols=1, vgap=5, hgap=5)
newVersionAlertTextPanel.SetSizer(gs)
newVersionAlertTitleLabel = wx.StaticText(newVersionAlertTextPanel,
label = "CVL Administrator")
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
font.SetPointSize(14)
font.SetWeight(wx.BOLD)
newVersionAlertTitleLabel.SetFont(font)
gs.Add(wx.StaticText(newVersionAlertTextPanel))
gs.Add(newVersionAlertTitleLabel, flag=wx.EXPAND)
gs.Add(wx.StaticText(newVersionAlertTextPanel))
newVersionAlertTextLabel1 = wx.StaticText(newVersionAlertTextPanel,
label =
"You are running version " + cvl_administrator_version_number.version_number + "\n\n" +
"The latest version is " + myHtmlParser.data[0] + "\n\n" +
"Please download a new version from:\n\n")
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
if sys.platform.startswith("darwin"):
font.SetPointSize(11)
else:
font.SetPointSize(9)
newVersionAlertTextLabel1.SetFont(font)
gs.Add(newVersionAlertTextLabel1, flag=wx.EXPAND)
newVersionAlertHyperlink = wx.HyperlinkCtrl(newVersionAlertTextPanel,
id = wx.ID_ANY,
label = cvlAdministratorURL,
url = cvlAdministratorURL)
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
if sys.platform.startswith("darwin"):
font.SetPointSize(11)
else:
font.SetPointSize(8)
newVersionAlertHyperlink.SetFont(font)
gs.Add(newVersionAlertHyperlink, flag=wx.EXPAND)
gs.Add(wx.StaticText(newVersionAlertTextPanel))
newVersionAlertTextLabel2 = wx.StaticText(newVersionAlertTextPanel,
label =
"For queries, please contact:\n\[email protected]\[email protected]\n")
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
if sys.platform.startswith("darwin"):
font.SetPointSize(11)
else:
font.SetPointSize(9)
newVersionAlertTextLabel2.SetFont(font)
gs.Add(newVersionAlertTextLabel2, flag=wx.EXPAND)
def onOK(event):
sys.exit(1)
okButton = wx.Button(newVersionAlertTextPanel, 1, ' OK ')
okButton.SetDefault()
gs.Add(okButton, flag=wx.ALIGN_RIGHT)
gs.Add(wx.StaticText(newVersionAlertTextPanel))
gs.Fit(newVersionAlertTextPanel)
newVersionAlertDialog.Bind(wx.EVT_BUTTON, onOK, id=1)
gs = wx.FlexGridSizer(rows=1, cols=3, vgap=5, hgap=5)
gs.Add(cvlAdministratorIconPanel, flag=wx.EXPAND)
gs.Add(newVersionAlertTextPanel, flag=wx.EXPAND)
gs.Add(wx.StaticText(newVersionAlertDialog,label=" "))
newVersionAlertDialog.SetSizer(gs)
gs.Fit(newVersionAlertDialog)
newVersionAlertDialog.ShowModal()
newVersionAlertDialog.Destroy()
sys.exit(1)
global ec2CredentialsDialog
ec2CredentialsDialog = wx.Dialog(tempFrame, title="CVL Administrator", name="CVL Administrator",size=(600,220))
ec2CredentialsDialog.Center()
ec2CredentialsPanel = wx.Panel(ec2CredentialsDialog)
gs = wx.FlexGridSizer(rows=8, cols=6, vgap=5, hgap=5)
ec2CredentialsPanel.SetSizer(gs)
ec2CredentialsPanelTitleLabel = wx.StaticText(ec2CredentialsPanel, label = "CVL Administrator")
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
font.SetPointSize(14)
font.SetWeight(wx.BOLD)
ec2CredentialsPanelTitleLabel.SetFont(font)
gs.Add(wx.StaticText(ec2CredentialsPanel, -1, " ")); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel));
gs.Add(wx.StaticText(ec2CredentialsPanel, -1, " ")); gs.Add(ec2CredentialsPanelTitleLabel); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel));
ec2CredentialsZipFileLabel = wx.StaticText(ec2CredentialsPanel, label = "EC2 credentials zip file:")
dummyPanel = wx.Panel(ec2CredentialsDialog)
defaultTextFieldSize = wx.TextCtrl(dummyPanel, -1, "").GetSize()
dummyPanel.Destroy()
ec2CredentialsZipFilenameField = wx.TextCtrl(ec2CredentialsPanel, -1, "", size=(200, defaultTextFieldSize.height))
def onBrowse(self):
filters = 'EC2 Credentials files (*.zip)|*.zip'
openFileDialog = wx.FileDialog ( None, message = 'Open EC2 credentials zip file...', wildcard = filters, style = wx.OPEN)
if openFileDialog.ShowModal() == wx.ID_OK:
global ec2CredentialsZipFilePath
ec2CredentialsZipFilePath = openFileDialog.GetPath()
ec2CredentialsZipFilenameField.WriteText(ec2CredentialsZipFilePath)
browseButton = wx.Button(ec2CredentialsPanel, 1, "Browse...")
ec2CredentialsDialog.Bind(wx.EVT_BUTTON, onBrowse, id=1)
def onHelp(self):
import cStringIO
import downloadingEC2CredentialsImage
global bmp
class DisplayDownloadingEC2CredentialsImage(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
bmp = downloadingEC2CredentialsImage.getDownloadingEC2CredentialsBitmap()
wx.StaticBitmap(self, -1, bmp, (0, 0), (bmp.GetWidth(), bmp.GetHeight()))
bmp = downloadingEC2CredentialsImage.getDownloadingEC2CredentialsBitmap()
ec2ImageFrame = wx.Frame(None, -1, "CVL Administrator - How To Download EC2 Credentials From Nectar", size = (bmp.GetWidth(), bmp.GetHeight()))
DisplayDownloadingEC2CredentialsImage(ec2ImageFrame,-1)
ec2ImageFrame.Show(1)
helpButton = wx.Button(ec2CredentialsPanel, 2, "Help...")
ec2CredentialsDialog.Bind(wx.EVT_BUTTON, onHelp, id=2)
def onOK(self):
if ec2CredentialsZipFilePath.strip() != "":
import zipfile
zf = zipfile.ZipFile(ec2CredentialsZipFilePath)
ec2rcFilename = 'ec2rc.sh'
try:
info = zf.getinfo(ec2rcFilename)
except KeyError:
print 'ERROR: Did not find %s in zip file' % ec2rcFilename
else:
#print '%s is %d bytes' % (info.filename, info.file_size)
ec2rcContents = zf.read(ec2rcFilename)
stringBuffer = StringIO.StringIO(ec2rcContents)
line = "\n"
ec2_access_key = ""
ec2_secret_key = ""
while line!="":
line = stringBuffer.readline()
if "export EC2_ACCESS_KEY" in line:
lineSplit = line.split("=")
ec2_access_key = lineSplit[1].strip()
#print "EC2_ACCESS_KEY = " + ec2_access_key
if "export EC2_SECRET_KEY" in line:
lineSplit = line.split("=")
ec2_secret_key = lineSplit[1].strip()
#print "EC2_SECRET_KEY = " + ec2_secret_key
import boto
from boto.ec2.connection import EC2Connection
from boto.ec2.regioninfo import RegionInfo
region = RegionInfo(name="NeCTAR", endpoint="nova.rc.nectar.org.au")
global ec2Connection
ec2Connection = boto.connect_ec2(aws_access_key_id=ec2_access_key,
aws_secret_access_key=ec2_secret_key,
is_secure=False,
region=region,
port=8773,
path="/services/Cloud",debug=1)
ec2CredentialsDialog.Destroy()
else:
dlg = wx.MessageDialog(None, "Error: Please upload a zip file containing your NeCTAR EC2 credentials, e.g. \"810-x509.zip\".",
"CVL Administrator", wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
okButton = wx.Button(ec2CredentialsPanel, 3, "OK")
ec2CredentialsDialog.Bind(wx.EVT_BUTTON, onOK, id=3)
def onCancel(self):
sys.exit(1)
cancelButton = wx.Button(ec2CredentialsPanel, 4, "Cancel")
ec2CredentialsDialog.Bind(wx.EVT_BUTTON, onCancel, id=4)
gs.Add(wx.StaticText(ec2CredentialsPanel, -1, " ")); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel));
gs.Add(wx.StaticText(ec2CredentialsPanel, -1, " ")); gs.Add(ec2CredentialsZipFileLabel); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(ec2CredentialsZipFilenameField, flag=wx.EXPAND); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(browseButton, flag=wx.EXPAND);
gs.Add(wx.StaticText(ec2CredentialsPanel, -1, " ")); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel));
gs.Add(wx.StaticText(ec2CredentialsPanel, -1, " ")); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(helpButton, flag=wx.EXPAND);
gs.Add(wx.StaticText(ec2CredentialsPanel, -1, " ")); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel));
gs.Add(wx.StaticText(ec2CredentialsPanel, -1, " ")); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(cancelButton, flag=wx.ALIGN_RIGHT); gs.Add(wx.StaticText(ec2CredentialsPanel)); gs.Add(okButton, flag=wx.EXPAND);
gs.Fit(ec2CredentialsPanel)
ec2CredentialsDialog.ShowModal()
global launchDialogFrame
launchDialogFrame = MyFrame(None, -1, 'CVL Administrator')
launchDialogFrame.Show(True)
return True
app = MyApp(False) # Don't automatically redirect sys.stdout and sys.stderr to a Window.
app.MainLoop()