better error checking in sfirenew; color-coding of status
authorsmbaker <smbaker@fc8clean.lan>
Wed, 7 Sep 2011 03:01:34 +0000 (20:01 -0700)
committersmbaker <smbaker@fc8clean.lan>
Wed, 7 Sep 2011 03:01:34 +0000 (20:01 -0700)
sface/sfirenew.py

index ca80386..682d09a 100644 (file)
@@ -16,12 +16,18 @@ class SfiRenewer(QObject):
         QObject.__init__(self, parent)
         self.hrn = hrn
         self.newExpiration = newExpiration
         QObject.__init__(self, parent)
         self.hrn = hrn
         self.newExpiration = newExpiration
+        self.faultString = None
 
         self.renewProcess = SfiProcess(self)
         self.connect(self.renewProcess, SIGNAL('finished()'), self.finishedGetRecord)
         self.renewProcess.getRecord(hrn=config.getSlice(), filename="/tmp/slicerecord")
 
     def finishedGetRecord(self):
 
         self.renewProcess = SfiProcess(self)
         self.connect(self.renewProcess, SIGNAL('finished()'), self.finishedGetRecord)
         self.renewProcess.getRecord(hrn=config.getSlice(), filename="/tmp/slicerecord")
 
     def finishedGetRecord(self):
+        faultString = self.renewProcess.getFaultString()
+        if faultString:
+            self.emitFinished("fault", faultString)
+            return
+
         f = open("/tmp/slicerecord", "r")
         data = f.read()
         f.close()
         f = open("/tmp/slicerecord", "r")
         data = f.read()
         f.close()
@@ -45,6 +51,11 @@ class SfiRenewer(QObject):
         self.renewProcess.updateRecord("/tmp/slicerecord")
 
     def finishedUpdateRecord(self):
         self.renewProcess.updateRecord("/tmp/slicerecord")
 
     def finishedUpdateRecord(self):
+        faultString = self.renewProcess.getFaultString()
+        if faultString:
+            self.emitFinished("fault", faultString)
+            return
+
         # we have to force sfi.py to download an updated slice credential
         sliceCredName = os.path.expanduser("~/.sfi/slice_" + self.hrn.split(".")[-1] + ".cred")
         if os.path.exists(sliceCredName):
         # we have to force sfi.py to download an updated slice credential
         sliceCredName = os.path.expanduser("~/.sfi/slice_" + self.hrn.split(".")[-1] + ".cred")
         if os.path.exists(sliceCredName):
@@ -58,6 +69,11 @@ class SfiRenewer(QObject):
         self.renewProcess.renewSlivers(self.newExpiration.strftime("%Y-%m-%dT%H:%M:%SZ"))
 
     def finishedRenewSlivers(self):
         self.renewProcess.renewSlivers(self.newExpiration.strftime("%Y-%m-%dT%H:%M:%SZ"))
 
     def finishedRenewSlivers(self):
+        faultString = self.renewProcess.getFaultString()
+        if faultString:
+            self.emitFinished("fault", faultString)
+            return
+
         self.emitFinished("success")
 
     def emitFinished(self, status, statusMsg=None):
         self.emitFinished("success")
 
     def emitFinished(self, status, statusMsg=None):
@@ -116,16 +132,23 @@ class RenewWindow(QDialog):
         self.status.setText(x)
 
     def renewFinished(self):
         self.status.setText(x)
 
     def renewFinished(self):
+        if self.renewProcess.status == "success":
+            color = "green"
+            # give the user the <close> button
+            self.buttonBox.clear()
+            self.buttonBox.addButton(QDialogButtonBox.Close)
+        else:
+            color = "red"
+
         if self.renewProcess.statusMsg:
         if self.renewProcess.statusMsg:
-            self.setStatus("Renew " + self.renewProcess.status + ": " + self.renewProcess.statusMsg)
+            self.setStatus("<font color='%s'>Renew %s: %s</font>" % (color, self.renewProcess.status, self.renewProcess.statusMsg))
         else:
         else:
-            self.setStatus("Renew " + self.renewProcess.status)
-        self.disconnect(self.renewProcess, SIGNAL('finished()'), self.renewFinished)
-        self.renewProcess = None
+            self.setStatus("<font color='%s'>Renew %s</font>" % (color, self.renewProcess.status))
 
         self.buttonBox.setEnabled(True)
 
         self.buttonBox.setEnabled(True)
-        self.buttonBox.clear()
-        self.buttonBox.addButton(QDialogButtonBox.Close)
+
+        self.disconnect(self.renewProcess, SIGNAL('finished()'), self.renewFinished)
+        self.renewProcess = None
 
     def get_new_expiration(self):
         index = self.duration.currentIndex()
 
     def get_new_expiration(self):
         index = self.duration.currentIndex()