From df505e2faeb65a17e90935485c1c98601ff33204 Mon Sep 17 00:00:00 2001
From: Simon Schampijer <simon@schampijer.de>
Date: Wed, 25 Aug 2010 14:54:38 +0200
Subject: [PATCH] Refinements of #1630
- pylint cleanups
- better error handling with loggings
---
extensions/cpsection/modemconfiguration/model.py | 16 ++++++++++--
extensions/cpsection/modemconfiguration/view.py | 28 ++++++++++++---------
2 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/extensions/cpsection/modemconfiguration/model.py b/extensions/cpsection/modemconfiguration/model.py
index 42f7563..dbec47d 100644
a
|
b
|
import gconf |
18 | 18 | import gtk |
19 | 19 | import os |
20 | 20 | import locale |
| 21 | import logging |
| 22 | |
21 | 23 | from xml.etree.cElementTree import ElementTree |
22 | 24 | from gettext import gettext as _ |
23 | 25 | |
… |
… |
def set_puk(puk): |
79 | 81 | |
80 | 82 | def has_providers_db(): |
81 | 83 | if not os.path.isfile(COUNTRY_CODES_PATH): |
| 84 | logging.debug("Mobile broadband provider database: Country " \ |
| 85 | "codes path %s not found.", COUNTRY_CODES_PATH) |
82 | 86 | return False |
83 | 87 | try: |
84 | 88 | tree = ElementTree(file=PROVIDERS_PATH) |
| 89 | except (IOError, SyntaxError), e: |
| 90 | logging.debug("Mobile broadband provider database: Could not read " \ |
| 91 | "provider information %s error=%s", PROVIDERS_PATH) |
| 92 | return False |
| 93 | else: |
85 | 94 | elem = tree.getroot() |
86 | 95 | if elem is None or elem.get('format') != PROVIDERS_FORMAT_SUPPORTED: |
| 96 | logging.debug("Mobile broadband provider database: Could not " \ |
| 97 | "read provider information. %s is wrong format.", |
| 98 | elem.get('format')) |
87 | 99 | return False |
88 | 100 | return True |
89 | | except IOError: |
90 | | return False |
| 101 | |
91 | 102 | |
92 | 103 | class CountryListStore(gtk.ListStore): |
93 | 104 | COUNTRY_CODE = locale.getdefaultlocale()[0][3:5].lower() |
… |
… |
class PlanListStore(gtk.ListStore): |
176 | 187 | |
177 | 188 | def get_row_plan(self, row): |
178 | 189 | return self[row][1] |
179 | | |
diff --git a/extensions/cpsection/modemconfiguration/view.py b/extensions/cpsection/modemconfiguration/view.py
index 1d9d27f..3b03b3d 100644
a
|
b
|
|
14 | 14 | # along with this program; if not, write to the Free Software |
15 | 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US |
16 | 16 | |
17 | | import os |
18 | | import logging |
19 | 17 | from gettext import gettext as _ |
20 | 18 | |
21 | 19 | import gtk |
… |
… |
class EntryWithLabel(gtk.HBox): |
31 | 29 | __gtype_name__ = "SugarEntryWithLabel" |
32 | 30 | |
33 | 31 | def __init__(self, label_text): |
34 | | gtk.HBox.__init__(self, spacing=style.DEFAULT_SPACING*2) |
| 32 | gtk.HBox.__init__(self, spacing=style.DEFAULT_SPACING * 2) |
35 | 33 | |
36 | 34 | self._timeout_sid = 0 |
37 | 35 | self._changed_handler = None |
… |
… |
class EntryWithLabel(gtk.HBox): |
79 | 77 | def get_value(self): |
80 | 78 | raise NotImplementedError |
81 | 79 | |
82 | | def set_value(self): |
| 80 | def set_value(self, value): |
83 | 81 | raise NotImplementedError |
84 | 82 | |
85 | 83 | def _get_is_valid(self): |
86 | 84 | return self._is_valid |
| 85 | |
87 | 86 | is_valid = gobject.property(type=bool, getter=_get_is_valid, default=True) |
88 | 87 | |
| 88 | |
89 | 89 | class UsernameEntry(EntryWithLabel): |
90 | 90 | def __init__(self, model): |
91 | 91 | EntryWithLabel.__init__(self, _('Username:')) |
… |
… |
class UsernameEntry(EntryWithLabel): |
97 | 97 | def set_value(self, username): |
98 | 98 | self._model.set_username(username) |
99 | 99 | |
| 100 | |
100 | 101 | class PasswordEntry(EntryWithLabel): |
101 | 102 | def __init__(self, model): |
102 | 103 | EntryWithLabel.__init__(self, _('Password:')) |
… |
… |
class PasswordEntry(EntryWithLabel): |
108 | 109 | def set_value(self, password): |
109 | 110 | self._model.set_password(password) |
110 | 111 | |
| 112 | |
111 | 113 | class NumberEntry(EntryWithLabel): |
112 | 114 | def __init__(self, model): |
113 | 115 | EntryWithLabel.__init__(self, _('Number:')) |
… |
… |
class NumberEntry(EntryWithLabel): |
119 | 121 | def set_value(self, number): |
120 | 122 | self._model.set_number(number) |
121 | 123 | |
| 124 | |
122 | 125 | class ApnEntry(EntryWithLabel): |
123 | 126 | def __init__(self, model): |
124 | 127 | EntryWithLabel.__init__(self, _('Access Point Name (APN):')) |
… |
… |
class ApnEntry(EntryWithLabel): |
130 | 133 | def set_value(self, apn): |
131 | 134 | self._model.set_apn(apn) |
132 | 135 | |
| 136 | |
133 | 137 | class PinEntry(EntryWithLabel): |
134 | 138 | def __init__(self, model): |
135 | 139 | EntryWithLabel.__init__(self, _('Personal Identity Number (PIN):')) |
… |
… |
class PinEntry(EntryWithLabel): |
141 | 145 | def set_value(self, pin): |
142 | 146 | self._model.set_pin(pin) |
143 | 147 | |
| 148 | |
144 | 149 | class PukEntry(EntryWithLabel): |
145 | 150 | def __init__(self, model): |
146 | 151 | EntryWithLabel.__init__(self, _('Personal Unblocking Key (PUK):')) |
… |
… |
class ModemConfiguration(SectionView): |
192 | 197 | self._upper_box.show() |
193 | 198 | |
194 | 199 | |
195 | | box = gtk.HBox(spacing=style.DEFAULT_SPACING*2) |
| 200 | box = gtk.HBox(spacing=style.DEFAULT_SPACING * 2) |
196 | 201 | label = gtk.Label(_('Country:')) |
197 | 202 | label.set_alignment(1, 0.5) |
198 | 203 | label_group.add_widget(label) |
… |
… |
class ModemConfiguration(SectionView): |
211 | 216 | self._upper_box.pack_start(box, False) |
212 | 217 | box.show() |
213 | 218 | |
214 | | box = gtk.HBox(spacing=style.DEFAULT_SPACING*2) |
| 219 | box = gtk.HBox(spacing=style.DEFAULT_SPACING * 2) |
215 | 220 | label = gtk.Label(_('Provider:')) |
216 | 221 | label.set_alignment(1, 0.5) |
217 | 222 | label_group.add_widget(label) |
… |
… |
class ModemConfiguration(SectionView): |
346 | 351 | |
347 | 352 | def _validate(self): |
348 | 353 | if self._username_entry.is_valid and \ |
349 | | self._password_entry.is_valid and \ |
| 354 | self._password_entry.is_valid and \ |
350 | 355 | self._number_entry.is_valid and \ |
351 | | self._apn_entry.is_valid and \ |
352 | | self._pin_entry.is_valid and \ |
353 | | self._puk_entry.is_valid: |
354 | | self.props.is_valid = True |
| 356 | self._apn_entry.is_valid and \ |
| 357 | self._pin_entry.is_valid and \ |
| 358 | self._puk_entry.is_valid: |
| 359 | self.props.is_valid = True |
355 | 360 | else: |
356 | 361 | self.props.is_valid = False |
357 | 362 | |
… |
… |
class ModemConfiguration(SectionView): |
359 | 364 | if entry.is_valid: |
360 | 365 | self.needs_restart = True |
361 | 366 | self._validate() |
362 | | |