X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fsfirenew.py;h=8da166e4de84171b52de94e07a82763eebb9fac5;hp=17cd8d6550ff500754a871e5039c017c88103863;hb=1a0bb6c8cf51c8abcffdc94da1ba4d9c9bb452e0;hpb=ab5bd9742a2d1b306e1a65b7f37c46f602c3fdd3 diff --git a/sface/sfirenew.py b/sface/sfirenew.py index 17cd8d6..8da166e 100644 --- a/sface/sfirenew.py +++ b/sface/sfirenew.py @@ -6,20 +6,28 @@ import sys import time from PyQt4.QtCore import * +from PyQt4.QtGui import * from sface.config import config from sface.sfiprocess import SfiProcess +#from sface.sfithread import SfiThread class SfiRenewer(QObject): def __init__(self, hrn, newExpiration, parent=None): 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): + faultString = self.renewProcess.getFaultString() + if faultString: + self.emitFinished("fault", faultString) + return + f = open("/tmp/slicerecord", "r") data = f.read() f.close() @@ -43,6 +51,11 @@ class SfiRenewer(QObject): 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 = config.fullpath("slice_" + self.hrn.split(".")[-1] + ".cred") if os.path.exists(sliceCredName): @@ -56,6 +69,11 @@ class SfiRenewer(QObject): 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): @@ -63,3 +81,75 @@ class SfiRenewer(QObject): self.statusMsg = statusMsg self.emit(SIGNAL("finished()")) +class RenewWindow(QDialog): + def __init__(self, parent=None): + super(RenewWindow, self).__init__(parent) + self.setWindowTitle("Renew Slivers") + + self.renewProcess = None + + self.duration = QComboBox() + + self.expirations = [] + + durations = ( (1, "One Week"), (2, "Two Weeks"), (3, "Three Weeks"), (4, "One Month") ) + + now = datetime.datetime.utcnow() + for (weeks, desc) in durations: + exp = now + datetime.timedelta(days = weeks * 7) + desc = desc + " " + exp.strftime("%Y-%m-%d %H:%M:%S") + self.expirations.append(exp) + self.duration.addItem(desc) + + self.duration.setCurrentIndex(0) + + self.status = QLabel("") + + self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True) + + layout = QVBoxLayout() + layout.addWidget(self.duration) + layout.addWidget(self.status) + layout.addWidget(self.buttonBox) + self.setLayout(layout) + + #self.status.hide() + + self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) + self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) + + def accept(self): + self.setStatus("Renewing Slice...") + + self.renewProcess = SfiRenewer(config.getSlice(), self.get_new_expiration(), self) + self.connect(self.renewProcess, SIGNAL('finished()'), self.renewFinished) + + self.duration.setEnabled(False) + self.buttonBox.setEnabled(False) + + def setStatus(self, x): + self.status.setText(x) + + def renewFinished(self): + if self.renewProcess.status == "success": + color = "green" + # give the user the button + self.buttonBox.clear() + self.buttonBox.addButton(QDialogButtonBox.Close) + else: + color = "red" + + if self.renewProcess.statusMsg: + self.setStatus("Renew %s: %s" % (color, self.renewProcess.status, self.renewProcess.statusMsg)) + else: + self.setStatus("Renew %s" % (color, self.renewProcess.status)) + + self.buttonBox.setEnabled(True) + + self.disconnect(self.renewProcess, SIGNAL('finished()'), self.renewFinished) + self.renewProcess = None + + def get_new_expiration(self): + index = self.duration.currentIndex() + return self.expirations[index]