import repository from arizona
[raven.git] / apps / gacksui / gacksscreen.py
1 import os
2 import sys
3
4 from PyQt4.QtCore import *
5 from PyQt4.QtGui import *
6
7 from sface.sliceview import SlicePickerWindow, MODE_USER_SLICES, MODE_SELECT_SINGLE
8 from sface.screens.sfascreen import SfaScreen
9
10 from sface.config import config
11 from sface.sfidata import SfiData
12
13 sys.path.append("/usr/share/gacksui")
14
15 import gacksui
16 import gackshelper
17
18 class IdentityNoEntException(Exception):
19         def __init__(self, filename):\r
20             self.filename = filename\r
21             return\r
22 \r
23         def __str__(self):\r
24             return "File does not exist: " + self.filename\r
25 \r
26 class GacksErrorWidget(QWidget):\r
27     def __init__(self, errorMsg=None, parent=None):\r
28         super(GacksErrorWidget, self).__init__(parent)
29
30         layout = QVBoxLayout()
31
32         label = QLabel("GACKS was unable to load due to an error.")
33         label.setWordWrap(True)
34         layout.addWidget(label)
35
36         if errorMsg:
37             label = QLabel(errorMsg)
38             layout.addWidget(label)
39
40         label = QLabel("Check that keys/credentials exist and restart sface.")
41         label.setWordWrap(True)
42         layout.addWidget(label)
43
44         self.setLayout(layout)
45 \r
46 \rclass GacksWidget_Sfa(gacksui.GacksWidget):
47 \r    def __init__(self, gacks=None, parent=None):
48 \r        gacksui.GacksWidget.__init__(self, gacks, parent)
49 \r
50 \r    def onPickButton(self):
51 \r        dlg = SlicePickerWindow(mode=MODE_USER_SLICES+MODE_SELECT_SINGLE, parent=self)
52 \r        dlg.exec_()
53 \r        if dlg.slices:
54 \r            self.editIdentity.setText(dlg.slices[0])
55 \r
56 \r    def externalConfig(self):
57 \r        self.userHrn = config.getUser()
58 \r        username = self.userHrn.split(".")[-1]
59 \r
60         self.keyFile = os.path.join(config.get_dirname(), username) + ".pkey"
61
62     def getSubscribedNodes(self):
63         rspec = SfiData().getSliceRSpec()
64         if (rspec == None):
65             return []
66         names = []
67         nodes = rspec.version.get_nodes()
68         for node in nodes:
69             names.append(node["component_name"])
70         return names
71
72 class GacksScreen(SfaScreen):
73 \r    def __init__(self, parent):
74         SfaScreen.__init__(self, parent)
75
76         self.gacks_helper = gackshelper.Gacks(reg_url=config.registry)
77
78         widget = GacksWidget_Sfa(self.gacks_helper, self)
79
80         self.init(widget, "Gacks", "Gacks Resource Management")
81