Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
starting to address #33, fixed #21
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed Apr 24, 2015
1 parent a630b02 commit 16fb581
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 38 deletions.
57 changes: 44 additions & 13 deletions Imagr/MainController.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MainController(NSObject):
introTab = objc.IBOutlet()
loginTab = objc.IBOutlet()
mainTab = objc.IBOutlet()
errorTab = objc.IBOutlet()

password = objc.IBOutlet()
passwordLabel = objc.IBOutlet()
Expand Down Expand Up @@ -73,6 +74,19 @@ class MainController(NSObject):
packages_to_install = None
restartAction = None
blessTarget = None
errorMessage = None

def errorPanel(self, error):
errorText = str(error)
alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
NSLocalizedString(errorText, None),
NSLocalizedString(u"Okay", None),
objc.nil,
objc.nil,
NSLocalizedString(u"", None))

alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
self.mainWindow, self, self.setStartupDisk_, objc.nil)

def runStartupTasks(self):
self.mainWindow.center()
Expand All @@ -92,26 +106,37 @@ def loadData(self):
theURL = Utils.getServerURL()
if theURL:
plistData = Utils.downloadFile(theURL)
converted_plist = FoundationPlist.readPlistFromString(plistData)
self.passwordHash = converted_plist['password']
self.workflows = converted_plist['workflows']
if plistData:
try:
converted_plist = FoundationPlist.readPlistFromString(plistData)
except:
self.errorMessage = "Configuration plist couldn't be read."
try:
self.passwordHash = converted_plist['password']
except:
self.errorMessage = "Password wasn't set."

try:
self.workflows = converted_plist['workflows']
except:
self.errorMessage = "No workflows found in the configuration plist."
else:
self.errorMessage = "Couldn't get configuration plist from server."
else:
self.passwordHash = False
self.errorMessage = "Configuration URL wasn't set."

self.performSelectorOnMainThread_withObject_waitUntilDone_(
self.loadDataComplete, None, YES)
del pool

def loadDataComplete(self):
if not self.passwordHash:
self.password.setEnabled_(False)
self.loginButton.setEnabled_(False)
self.disableAllButtons(self)
self.startUpDiskText.setStringValue_(
"No Server URL has been set. Please contact your administrator.")
self.setStartupDisk_(self)
self.theTabView.selectTabViewItem_(self.loginTab)
self.mainWindow.makeFirstResponder_(self.password)
NSLog(self.errorMessage)
if self.errorMessage:
self.theTabView.selectTabViewItem_(self.errorTab)
self.errorPanel(self.errorMessage)
else:
self.theTabView.selectTabViewItem_(self.loginTab)
self.mainWindow.makeFirstResponder_(self.password)

@objc.IBAction
def login_(self, sender):
Expand All @@ -127,6 +152,7 @@ def login_(self, sender):

@objc.IBAction
def setStartupDisk_(self, sender):
self.restartAction = 'restart'
# This stops the console being spammed with: unlockFocus called too many times. Called on <NSButton
NSGraphicsContext.saveGraphicsState()
self.disableAllButtons(sender)
Expand Down Expand Up @@ -479,6 +505,11 @@ def downloadAndCopyPackages(self):
# copy bits for first boot script
Utils.copyFirstBoot(self.workVolume.mountpoint)

@objc.IBAction
def restartButtonClicked_(self, sender):
NSLog("Restart Button Clicked")
self.restartToImagedVolume()

def restartToImagedVolume(self):
# set the startup disk to the restored volume
if self.blessTarget == True:
Expand Down

0 comments on commit 16fb581

Please sign in to comment.