diff options
author | emkael <emkael@tlen.pl> | 2019-06-05 19:57:53 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-06-05 19:57:53 +0200 |
commit | bcaa7f9d14f0757d21ac95c71723cedae43dca65 (patch) | |
tree | 61d30a2103f53fe5d41f9d9896e77eb3479da383 /jfr_playoff/gui/frames | |
parent | 8f7ff764cd5fd9cb7e751990d22c4a83c650a969 (diff) |
Refactoring network test code
Diffstat (limited to 'jfr_playoff/gui/frames')
-rw-r--r-- | jfr_playoff/gui/frames/network.py | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/jfr_playoff/gui/frames/network.py b/jfr_playoff/gui/frames/network.py index 961ee21..1ee8fce 100644 --- a/jfr_playoff/gui/frames/network.py +++ b/jfr_playoff/gui/frames/network.py @@ -10,6 +10,17 @@ from ...db import PlayoffDB from ..frames import RepeatableEntry, WidgetRepeater from ..frames import ScrollableFrame, getIntVal +def network_test(connFunction, testLabel): + try: + connFunction() + testLabel.configure(text='✓') + testLabel.configure(foreground='green') + return None + except Exception as e: + testLabel.configure(text='✗') + testLabel.configure(foreground='red') + return unicode(str(e).decode('utf-8', errors='replace')) + class MySQLConfigurationFrame(tk.Frame): def __init__(self, *args, **kwargs): tk.Frame.__init__(self, *args, **kwargs) @@ -26,18 +37,12 @@ class MySQLConfigurationFrame(tk.Frame): return None def _testDB(self): - try: + def test(): dbConfig = self.getConfig() if dbConfig is None: raise AttributeError('Database not configured') db = PlayoffDB(dbConfig) - self.dbError = None - self.dbTestLabel.configure(text='✓') - self.dbTestLabel.configure(foreground='green') - except Exception as e: - self.dbError = unicode(e) - self.dbTestLabel.configure(text='✗') - self.dbTestLabel.configure(foreground='red') + self.dbError = network_test(test, self.dbTestLabel) def _dbError(self, event): if self.dbError is not None: @@ -95,18 +100,12 @@ class GoniecConfigurationFrame(tk.Frame): state=tk.NORMAL if self.enable.get() else tk.DISABLED) def _test(self): - try: + def test(): goniec = socket.socket() goniec.connect( (self.host.get().strip(), getIntVal(self.port, 8080))) goniec.close() - self.testError = None - self.testLabel.configure(text='✓') - self.testLabel.configure(foreground='green') - except socket.error as e: - self.testError = unicode(str(e).decode('utf-8', errors='replace')) - self.testLabel.configure(text='✗') - self.testLabel.configure(foreground='red') + self.testError = network_test(test, self.testLabel) def _testError(self, event): if self.testError is not None: |