summaryrefslogtreecommitdiff
diff options
-rwxr-xr-xBuildBotApplet.py14
-rw-r--r--Client.py16
-rw-r--r--Config.py68
-rw-r--r--ConfigDialog.py10
-rw-r--r--ConfigDialog.ui52
5 files changed, 132 insertions, 28 deletions
diff --git a/BuildBotApplet.py b/BuildBotApplet.py
index d6af28d..2564782 100755
--- a/BuildBotApplet.py
+++ b/BuildBotApplet.py
@@ -19,18 +19,21 @@ import sys
from PyQt4 import QtCore, QtGui
# local imports
-import ConfigDialog
+import Config
import Client
import Resources
class BuildbotApplet(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
- self.client = Client.Client("buildbot:9881")
- self.client.start()
if not QtGui.QSystemTrayIcon.isSystemTrayAvailable():
print "Non system tray available"
sys.exit(1)
+
+ self.config = Config.Config(self)
+
+ self.client = Client.Client(self.config.config['Server'], self.config.config['Port'])
+ self.client.start()
self.okIcon = QtGui.QIcon(":pixmaps/ok.png")
self.failedIcon = QtGui.QIcon(":pixmaps/no.png")
@@ -40,7 +43,7 @@ class BuildbotApplet(QtGui.QWidget):
self.trayIcon.setIcon(self.okIcon)
self.menu = QtGui.QMenu()
- self.menu.addAction(QtGui.QIcon(":pixmaps/configure.png"), "Configure", self.showConfig)
+ self.menu.addAction(QtGui.QIcon(":pixmaps/configure.png"), "Configure", self.config.showDlg)
self.menu.addAction(QtGui.QIcon(":pixmaps/exit.png"), "Quit", self.quit)
QtCore.QObject.connect(self.trayIcon, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"),
self.showMenu)
@@ -57,9 +60,6 @@ class BuildbotApplet(QtGui.QWidget):
if reason == QtGui.QSystemTrayIcon.Context:
self.menu.show()
- def showConfig(self):
- dlg = ConfigDialog.ConfigDialog(self)
- dlg.show()
def setToolTip(self):
toolTip = """<table style='cellspacing:100px'><tr style='font-weight:bold'>
diff --git a/Client.py b/Client.py
index bcfa80e..0bdc488 100644
--- a/Client.py
+++ b/Client.py
@@ -14,8 +14,6 @@
# Copyright (C) 2008 Falco Hirschenberger <[email protected]>
###############################################################################
-import re
-
from threading import Thread
from twisted.spread import pb
from twisted.cred import credentials, error
@@ -25,9 +23,10 @@ from twisted.internet import reactor
import StatusAction
class Client(Thread):
- def __init__(self, master, events="builds"):
+ def __init__(self, server, port, events="builds"):
Thread.__init__(self)
- self.master = master
+ self.server = server
+ self.port = port
self.listener = StatusAction.StatusAction(events)
def run(self):
@@ -35,17 +34,10 @@ class Client(Thread):
reactor.run(installSignalHandlers=0)
def startConnecting(self):
- try:
- host, port = re.search(r'(.+):(\d+)', self.master).groups()
- port = int(port)
- except:
- print "unparseable master location '%s'" % self.master
- print " expecting something more like localhost:8007"
- raise
cf = pb.PBClientFactory()
creds = credentials.UsernamePassword("user", "passwd")
d = cf.login(creds)
- reactor.connectTCP(host, port, cf)
+ reactor.connectTCP(self.server, self.port, cf)
d.addCallbacks(self.connected, self.not_connected)
return d
diff --git a/Config.py b/Config.py
new file mode 100644
index 0000000..a625700
--- /dev/null
+++ b/Config.py
@@ -0,0 +1,68 @@
+###############################################################################
+# 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 3 of the License.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+#
+# Copyright (C) 2008 Falco Hirschenberger <[email protected]>
+###############################################################################
+
+import os, ConfigParser
+from PyQt4.QtCore import Qt
+
+# local includes
+import ConfigDialog
+
+class Config:
+ def __init__(self, parent):
+ self.configFile = os.path.expanduser('~/.bbapplet.cfg')
+ self.parser = ConfigParser.SafeConfigParser()
+ self.dlg = ConfigDialog.ConfigDialog(parent)
+ self.config = {'Server': '', 'Port': 0, 'User': '', 'Pass': '', 'ShowFail': False}
+
+ # is it the first start (does the configfile exist)?
+ if os.path.exists(self.configFile):
+ self.loadConfig()
+ else:
+ self.showDlg()
+
+ def loadConfig(self):
+ self.parser.readfp(open(self.configFile, 'r'))
+ self.config['Server'] = self.parser.get('Connection', 'Server')
+ self.config['Port'] = self.parser.getint('Connection', 'Port')
+ self.config['User'] = self.parser.get('Connection', 'User')
+ self.config['Pass'] = self.parser.get('Connection', 'Pass')
+ self.config['ShowFail'] = self.parser.getboolean('Notification', 'ShowFail')
+
+
+ def storeConfig(self):
+ self.parser.add_section('Connection')
+ self.parser.set('Connection', 'Server', str(self.config['Server']))
+ self.parser.set('Connection', 'Port', str(self.config['Port']))
+ self.parser.set('Connection', 'User', str(self.config['User']))
+ self.parser.set('Connection', 'Pass', str(self.config['Pass']))
+ self.parser.add_section('Notification')
+ self.parser.set('Notification', 'ShowFail', str(self.config['ShowFail']))
+ self.parser.write(open(self.configFile, 'w'))
+
+ def showDlg(self):
+ if self.dlg.exec_():
+ # we have to convert the QString obejct from the widget to a py-string here
+ self.config['Server'] = str(self.dlg.serverEdit.text())
+ self.config['Port'] = self.dlg.portSpinBox.value()
+ self.config['User'] = str(self.dlg.userEdit.text())
+ self.config['Pass'] = str(self.dlg.passEdit.text())
+ if self.dlg.showFailBox.checkState() == Qt.Checked:
+ self.config['ShowFail'] = True
+ else:
+ self.config['ShowFail'] = False
+
+ self.storeConfig()
+
diff --git a/ConfigDialog.py b/ConfigDialog.py
index 7b2d505..c0c26a6 100644
--- a/ConfigDialog.py
+++ b/ConfigDialog.py
@@ -21,3 +21,13 @@ class ConfigDialog(QtGui.QDialog, Ui_ConfigDialog):
def __init__(self, parent):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
+
+ def accept(self):
+ if self.serverEdit.text().isEmpty() or \
+ self.userEdit.text().isEmpty() or \
+ self.passEdit.text().isEmpty():
+ QtGui.QMessageBox.critical(self, 'Error...', 'Please fill out all entries')
+ else:
+ QtGui.QDialog.accept(self)
+
+
diff --git a/ConfigDialog.ui b/ConfigDialog.ui
index 9791c72..350bb9a 100644
--- a/ConfigDialog.ui
+++ b/ConfigDialog.ui
@@ -5,15 +5,15 @@
<rect>
<x>0</x>
<y>0</y>
- <width>400</width>
- <height>130</height>
+ <width>411</width>
+ <height>177</height>
</rect>
</property>
<property name="windowTitle" >
<string>Dialog</string>
</property>
- <layout class="QGridLayout" >
- <item row="0" column="0" >
+ <layout class="QVBoxLayout" >
+ <item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label" >
@@ -23,7 +23,7 @@
</widget>
</item>
<item>
- <widget class="QLineEdit" name="lineEdit" />
+ <widget class="QLineEdit" name="serverEdit" />
</item>
<item>
<widget class="QLabel" name="label_2" >
@@ -33,18 +33,52 @@
</widget>
</item>
<item>
- <widget class="QSpinBox" name="spinBox" />
+ <widget class="QSpinBox" name="portSpinBox" >
+ <property name="minimum" >
+ <number>1</number>
+ </property>
+ <property name="maximum" >
+ <number>65500</number>
+ </property>
+ <property name="value" >
+ <number>9881</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Username:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="userEdit" />
+ </item>
+ <item>
+ <widget class="QLabel" name="label_4" >
+ <property name="text" >
+ <string>Password:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="passEdit" />
</item>
</layout>
</item>
- <item row="1" column="0" >
- <widget class="QCheckBox" name="checkBox" >
+ <item>
+ <widget class="QCheckBox" name="showFailBox" >
<property name="text" >
<string>Popup on build failure</string>
</property>
</widget>
</item>
- <item row="2" column="0" >
+ <item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>