From 4b52040da3750096b73fd3d5b790c2494ef18b0b Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Thu, 12 Jun 2014 15:11:25 -0300 Subject: Use a dict instead of an object to ease serialization. --- changes/use-dict-instead-of-object | 1 + src/leap/bitmask/backend/components.py | 5 ++- src/leap/bitmask/config/providerconfig.py | 55 ++++++++++--------------------- src/leap/bitmask/gui/mainwindow.py | 12 +++---- src/leap/bitmask/gui/wizard.py | 22 ++++++------- 5 files changed, 37 insertions(+), 58 deletions(-) create mode 100644 changes/use-dict-instead-of-object diff --git a/changes/use-dict-instead-of-object b/changes/use-dict-instead-of-object new file mode 100644 index 00000000..b7ed58e4 --- /dev/null +++ b/changes/use-dict-instead-of-object @@ -0,0 +1 @@ +- Use a dict instead an object to ease later serialization. diff --git a/src/leap/bitmask/backend/components.py b/src/leap/bitmask/backend/components.py index 59fdfb68..19fcf283 100644 --- a/src/leap/bitmask/backend/components.py +++ b/src/leap/bitmask/backend/components.py @@ -257,8 +257,7 @@ class Provider(object): def get_details(self, domain, lang=None): """ - Signal a ProviderConfigLight object with the current ProviderConfig - settings. + Signal a dict with the current ProviderConfig settings. :param domain: the domain name of the provider. :type domain: str @@ -266,7 +265,7 @@ class Provider(object): :type lang: str Signals: - prov_get_details -> ProviderConfigLight + prov_get_details -> dict """ self._signaler.signal( self._signaler.PROV_GET_DETAILS, diff --git a/src/leap/bitmask/config/providerconfig.py b/src/leap/bitmask/config/providerconfig.py index cf31b3b2..7b979e61 100644 --- a/src/leap/bitmask/config/providerconfig.py +++ b/src/leap/bitmask/config/providerconfig.py @@ -38,35 +38,6 @@ class MissingCACert(Exception): pass -class ProviderConfigLight(object): - """ - A light config object to hold some provider settings needed by the GUI. - """ - def __init__(self): - """ - Define the public attributes. - """ - self.domain = "" - self.name = "" - self.description = "" - self.enrollment_policy = "" - self.services = [] - - @property - def services_string(self): - """ - Return a comma separated list of serices provided by this provider. - - :rtype: str - """ - services = [] - for service in self.services: - services.append(get_service_display_name(service)) - - services_str = ", ".join(services) - return services_str - - class ProviderConfig(BaseConfig): """ Provider configuration abstraction class @@ -76,24 +47,32 @@ class ProviderConfig(BaseConfig): def get_light_config(self, domain, lang=None): """ - Return a ProviderConfigLight object with the data for the loaded - object. + Return a dict with the data for the loaded object. :param domain: the domain name of the provider. :type domain: str :param lang: the language to use for localized strings. :type lang: str - :rtype: ProviderConfigLight or None if the ProviderConfig isn't loaded. + :rtype: dict or None if the ProviderConfig isn't loaded. """ config = self.get_provider_config(domain) - details = ProviderConfigLight() - details.domain = config.get_domain() - details.name = config.get_name(lang=lang) - details.description = config.get_description(lang=lang) - details.enrollment_policy = config.get_enrollment_policy() - details.services = config.get_services() + if config is None: + return + + details = {} + details["domain"] = config.get_domain() + details["name"] = config.get_name(lang=lang) + details["description"] = config.get_description(lang=lang) + details["enrollment_policy"] = config.get_enrollment_policy() + details["services"] = config.get_services() + + services = [] + for service in config.get_services(): + services.append(get_service_display_name(service)) + + details['services_string'] = ", ".join(services) return details diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 5feaf610..9e0e78bc 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -549,7 +549,7 @@ class MainWindow(QtGui.QMainWindow): details = self._provider_details mx_provided = False if details is not None: - mx_provided = MX_SERVICE in details.services + mx_provided = MX_SERVICE in details['services'] # XXX: handle differently not logged in user? akm = AdvancedKeyManagement(self, mx_provided, logged_user, @@ -569,7 +569,7 @@ class MainWindow(QtGui.QMainWindow): domain = self._login_widget.get_selected_provider() mx_provided = False if self._provider_details is not None: - mx_provided = MX_SERVICE in self._provider_details.services + mx_provided = MX_SERVICE in self._provider_details['services'] preferences = PreferencesWindow(self, user, domain, self._backend, self._soledad_started, mx_provided) @@ -1267,7 +1267,7 @@ class MainWindow(QtGui.QMainWindow): sig.soledad_bootstrap_failed.connect(lambda: btn_enabled(True)) sig.soledad_bootstrap_finished.connect(lambda: btn_enabled(True)) - if not MX_SERVICE in self._provider_details.services: + if not MX_SERVICE in self._provider_details['services']: self._set_mx_visible(False) def _start_eip_bootstrap(self): @@ -1310,7 +1310,7 @@ class MainWindow(QtGui.QMainWindow): Set the details for the just downloaded provider. :param details: the details of the provider. - :type details: ProviderConfigLight + :type details: dict """ self._provider_details = details @@ -1327,7 +1327,7 @@ class MainWindow(QtGui.QMainWindow): mx_enabled = MX_SERVICE in enabled_services mx_provided = False if self._provider_details is not None: - mx_provided = MX_SERVICE in self._provider_details.services + mx_provided = MX_SERVICE in self._provider_details['services'] return mx_enabled and mx_provided @@ -1344,7 +1344,7 @@ class MainWindow(QtGui.QMainWindow): eip_enabled = EIP_SERVICE in enabled_services eip_provided = False if self._provider_details is not None: - eip_provided = EIP_SERVICE in self._provider_details.services + eip_provided = EIP_SERVICE in self._provider_details['services'] return eip_enabled and eip_provided diff --git a/src/leap/bitmask/gui/wizard.py b/src/leap/bitmask/gui/wizard.py index 05cfbed3..f66c553d 100644 --- a/src/leap/bitmask/gui/wizard.py +++ b/src/leap/bitmask/gui/wizard.py @@ -569,7 +569,7 @@ class Wizard(QtGui.QWizard): Set the details for the just downloaded provider. :param details: the details of the provider. - :type details: ProviderConfigLight + :type details: dict """ self._provider_details = details @@ -640,9 +640,9 @@ class Wizard(QtGui.QWizard): the user to enable or disable. """ self.ui.grpServices.setTitle( - self.tr("Services by {0}").format(self._provider_details.name)) + self.tr("Services by {0}").format(self._provider_details['name'])) - services = get_supported(self._provider_details.services) + services = get_supported(self._provider_details['services']) for service in services: try: @@ -685,7 +685,7 @@ class Wizard(QtGui.QWizard): if not self._provider_setup_ok: self._reset_provider_setup() sub_title = self.tr("Gathering configuration options for {0}") - sub_title = sub_title.format(self._provider_details.name) + sub_title = sub_title.format(self._provider_details['name']) self.page(pageId).setSubTitle(sub_title) self.ui.lblDownloadCaCert.setPixmap(self.QUESTION_ICON) self._provider_setup_defer = self._backend.\ @@ -693,22 +693,22 @@ class Wizard(QtGui.QWizard): if pageId == self.PRESENT_PROVIDER_PAGE: sub_title = self.tr("Description of services offered by {0}") - sub_title = sub_title.format(self._provider_details.name) + sub_title = sub_title.format(self._provider_details['name']) self.page(pageId).setSubTitle(sub_title) details = self._provider_details - name = "{0}".format(details.name) - domain = "https://{0}".format(details.domain) - description = "{0}".format(details.description) + name = "{0}".format(details['name']) + domain = "https://{0}".format(details['domain']) + description = "{0}".format(details['description']) self.ui.lblProviderName.setText(name) self.ui.lblProviderURL.setText(domain) self.ui.lblProviderDesc.setText(description) - self.ui.lblServicesOffered.setText(details.services_string) - self.ui.lblProviderPolicy.setText(details.enrollment_policy) + self.ui.lblServicesOffered.setText(details['services_string']) + self.ui.lblProviderPolicy.setText(details['enrollment_policy']) if pageId == self.REGISTER_USER_PAGE: sub_title = self.tr("Register a new user with {0}") - sub_title = sub_title.format(self._provider_details.name) + sub_title = sub_title.format(self._provider_details['name']) self.page(pageId).setSubTitle(sub_title) self.ui.chkRemember.setVisible(False) -- cgit v1.2.3