diff --git a/econnman-bin.in b/econnman-bin.in index d38cb04..910d470 100755 --- a/econnman-bin.in +++ b/econnman-bin.in @@ -14,7 +14,7 @@ import logging import argparse import os.path -''' For python2 backwards compatibility ''' +# For python2 backwards compatibility try: import configparser except ImportError: @@ -23,7 +23,7 @@ except ImportError: try: import efl.evas as evas import efl.ecore as ecore - import efl.edje as edje + import efl.edje from efl.dbus_mainloop import DBusEcoreMainLoop import efl.elementary as elm from efl.elementary import ELM_POLICY_QUIT, \ @@ -49,7 +49,9 @@ try: from efl.elementary.theme import Theme except: import elementary as elm - import evas, e_dbus, ecore, edje + import evas + import ecore + import edje from e_dbus import DBusEcoreMainLoop from elementary import Window, Background, Box, Label, Naviframe, Popup, \ Button, Scroller, Check, Progressbar, Genlist, GenlistItemClass, \ @@ -73,6 +75,7 @@ EXPAND_HORIZ = (evas.EVAS_HINT_EXPAND, 0.0) FILL_BOTH = (evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) + ######################################################################## # Debug helpers: def dbus_variant_to_str(v): @@ -95,17 +98,24 @@ def dbus_variant_to_str(v): v = repr(v) return v + def dbus_dict_to_str(d): - "Help debug by converting a dbus.Dictionary to a string in a shorter form." + """Help debug by converting a dbus.Dictionary to a string in a shorter + form. + """ s = [] for k, v in d.items(): s.append("%s=%s" % (k, dbus_variant_to_str(v))) return ", ".join(s) + def dbus_array_to_str(a): - "Help debug by converting a complex structure to a string in shorter form." + """Help debug by converting a complex structure to a string in shorter + form. + """ return ", ".join(dbus_variant_to_str(x) for x in a) + def dbus_array_of_dict_to_str(a): """Help debug by converting a complex structure to a string in a shorter form with only the keys, not the value. @@ -252,9 +262,9 @@ class ObjectView(object): en.callback_activated_add(callback) return lb, en + ####################################################################### # Config Files Helper: - def config_file_setup(): global configs configs = configparser.RawConfigParser() @@ -264,14 +274,21 @@ def config_file_setup(): configs.readfp(fd) fd.close() except IOError: - popup_error(win, "Cannot read configuration file", "Econnman cannot read the coniguration file \"" + CONF_FILE + "\", used by connman to configure your ieee802.1x networks. Make sure the user running connman is able to read/write it.") + popup_error( + win, + "Cannot read configuration file", + "Econnman cannot read the coniguration file \"" + CONF_FILE + + "\", used by connman to configure your ieee802.1x networks. " + "Make sure the user running connman is able to read/write it." + ) configs = None raise IOError + def config_del(name): global configs secname = 'service_' + name - if configs == None: + if configs is None: try: config_file_setup() except IOError: @@ -280,10 +297,11 @@ def config_del(name): configs.remove_section(secname) config_write(name) + def config_set(name, key, value): global configs secname = 'service_' + name - if configs == None: + if configs is None: try: config_file_setup() except IOError: @@ -292,43 +310,55 @@ def config_set(name, key, value): configs.add_section(secname) configs.set(secname, 'Type', 'wifi') configs.set(secname, 'Name', name) - if value != None: + if value is not None: configs.set(secname, key, value) elif configs.has_option(secname, key): configs.remove_option(secname, key) config_write(name) + def config_get(name): global configs - if configs == None: + if configs is None: try: config_file_setup() except IOError: return None for sec in configs.sections(): - if configs.has_option(sec, 'Name') and configs.get(sec, 'Name') == name: + if configs.has_option(sec, 'Name') and \ + configs.get(sec, 'Name') == name: return sec else: return None + def config_option_get(secname, key): if configs.has_option(secname, key): return configs.get(secname, key) return None + def config_exists(name): if config_get(name): return True else: return False + def config_write(name): global configs try: with open(CONF_FILE, 'w', encoding='utf8') as configfile: configs.write(configfile) except IOError: - popup_error(win, "Cannot write configuration file", "Econnman cannot write the coniguration file \"" + CONF_FILE + "\", used by connman to configure your ieee802.1x networks. Make sure the user running connman is able to read/write it.") + popup_error( + win, + "Cannot write configuration file", + "Econnman cannot write the coniguration file \"" + CONF_FILE + + "\", used by connman to configure your ieee802.1x networks. " + "Make sure the user running connman is able to read/write it." + ) + ######################################################################## # Views: @@ -371,6 +401,7 @@ class OfflineModeMonitor(object): def _on_user_changed(self, obj): state = obj.state + def on_reply(): log.info("Set OfflineMode=%s", state) @@ -400,21 +431,31 @@ class TechList(object): self.obj.on_del_add(self._deleted) self.on_selected = on_selected self.obj.callback_selected_add(self._tech_selected) - self.sig_added = manager.connect_to_signal("TechnologyAdded", - self._tech_added) - self.sig_removed = manager.connect_to_signal("TechnologyRemoved", - self._tech_removed) - self.sig_propch = bus.add_signal_receiver(self._tech_changed, - "PropertyChanged", - "net.connman.Technology", - "net.connman", - path_keyword='path') - self.itc = GenlistItemClass(item_style="default", - text_get_func=self._item_text_get, - content_get_func=self._item_content_get) + self.sig_added = manager.connect_to_signal( + "TechnologyAdded", + self._tech_added + ) + self.sig_removed = manager.connect_to_signal( + "TechnologyRemoved", + self._tech_removed + ) + self.sig_propch = bus.add_signal_receiver( + self._tech_changed, + "PropertyChanged", + "net.connman.Technology", + "net.connman", + path_keyword='path' + ) + self.itc = GenlistItemClass( + item_style="default", + text_get_func=self._item_text_get, + content_get_func=self._item_content_get + ) - manager.GetTechnologies(reply_handler=self._get_techs_reply, - error_handler=self._get_techs_error) + manager.GetTechnologies( + reply_handler=self._get_techs_reply, + error_handler=self._get_techs_error + ) def _deleted(self, lst): self.sig_added.remove() @@ -540,6 +581,7 @@ class TechView(ObjectView): def _on_user_powered(self, obj): state = bool(self.powered.state) + def on_reply(): log.info("Set %s Powered=%s", self.path, state) @@ -549,8 +591,10 @@ class TechView(ObjectView): popup_error(self.obj, "Failed to Apply Powered", exc.get_dbus_message()) - self.bus_obj.SetProperty("Powered", dbus.Boolean(state), - reply_handler=on_reply, error_handler=on_error) + self.bus_obj.SetProperty( + "Powered", dbus.Boolean(state), + reply_handler=on_reply, error_handler=on_error + ) def _scan(self, obj): def on_reply(): @@ -573,10 +617,12 @@ class TechView(ObjectView): self.passphrase.disabled = not state def _tethering_apply(self, obj): - self.to_apply = [("TetheringIdentifier", self.identifier.text), - ("TetheringPassphrase", self.passphrase.text), - ("Tethering", dbus.Boolean(self.tethering.state)), - ] + self.to_apply = [ + ("TetheringIdentifier", self.identifier.text), + ("TetheringPassphrase", self.passphrase.text), + ("Tethering", dbus.Boolean(self.tethering.state)), + ] + def apply_next(): if not self.to_apply: return @@ -635,18 +681,26 @@ class ServicesList(object): self.on_disclosure = on_disclosure self.obj.callback_selected_add(self._item_selected) self.obj.on_del_add(self._deleted) - self.sig_ch = manager.connect_to_signal("ServicesChanged", - self._services_changed) - self.sig_propch = bus.add_signal_receiver(self._service_prop_changed, - "PropertyChanged", - "net.connman.Service", - "net.connman", - path_keyword='path') - manager.GetServices(reply_handler=self._get_services_reply, - error_handler=self._get_services_error) - self.itc = GenlistItemClass(item_style="default", - text_get_func=self._item_text_get, - content_get_func=self._item_content_get) + self.sig_ch = manager.connect_to_signal( + "ServicesChanged", + self._services_changed + ) + self.sig_propch = bus.add_signal_receiver( + self._service_prop_changed, + "PropertyChanged", + "net.connman.Service", + "net.connman", + path_keyword='path' + ) + manager.GetServices( + reply_handler=self._get_services_reply, + error_handler=self._get_services_error + ) + self.itc = GenlistItemClass( + item_style="default", + text_get_func=self._item_text_get, + content_get_func=self._item_content_get + ) def _deleted(self, obj): self.sig_ch.remove() @@ -995,7 +1049,8 @@ class ServiceView(ObjectView): lb = self.add_label(bx, "EAP:") options = ("PEAP", "TLS", "TTLS", "None") self.eap_method, self.eap_method_items = self.add_segment_control( - bx, options, self._on_eap_method) + bx, options, self._on_eap_method + ) if cfg_sec: conf_val = config_option_get(cfg_sec, 'EAP') if conf_val == "peap": @@ -1004,20 +1059,21 @@ class ServiceView(ObjectView): self.eap_method_items["TLS"].selected = True elif conf_val == "ttls": self.eap_method_items["TTLS"].selected = True - elif conf_val == None: + elif conf_val is None: self.eap_method_items["None"].selected = True options = ("TLS", "MSCHAPv2", "None") lb = self.add_label(bx, "Phase2:") self.phase2, self.phase2_items = self.add_segment_control( - bx, options, self._on_phase2) + bx, options, self._on_phase2 + ) if cfg_sec: conf_val = config_option_get(cfg_sec, 'Phase2') if conf_val == "tls": self.phase2_items["TLS"].selected = True elif conf_val == "MSCHAPV2": self.phase2_items["MSCHAPv2"].selected = True - elif conf_val == None: + elif conf_val is None: self.phase2_items["None"].selected = True def add_readonly_section(self, title, fields): @@ -1053,15 +1109,20 @@ class ServiceView(ObjectView): orig_value = self.readwrite_list_properties[name] conf_value = self.readwrite_list_properties[conf] if (conf_value and value != conf_value) or \ - (not conf_value and value != orig_value): - log.debug("User changed %s=%r (%r, %r)", name, value, - orig_value, conf_value) - value = value.strip() - if not value: - value_array = [] - else: - value_array = list(x.strip() for x in value.split(",")) - self._on_readwrite_changed(conf, value_array) + (not conf_value and value != orig_value): + log.debug( + "User changed %s=%r (%r, %r)" % ( + name, value, + orig_value, conf_value + ) + ) + value = value.strip() + if not value: + value_array = [] + else: + value_array = list(x.strip() for x in value.split(",")) + self._on_readwrite_changed(conf, value_array) + def on_unfocused(obj): self.reload_readwrite_list(name) @@ -1146,6 +1207,7 @@ class ServiceView(ObjectView): self.ipv4_properties[name] = value used = self.ipv4_properties["IPv4"] conf = self.ipv4_properties["IPv4.Configuration"] + def get_val(name): v = used.get(name) or conf.get(name) if not v: @@ -1174,6 +1236,7 @@ class ServiceView(ObjectView): self.proxy_properties[name] = value used = self.proxy_properties["Proxy"] conf = self.proxy_properties["Proxy.Configuration"] + def get_val(name): v = used.get(name) or conf.get(name) if not v: @@ -1204,7 +1267,6 @@ class ServiceView(ObjectView): if wid.visible: self.box.pack_end(wid) - def _disconnect(self, obj): def on_reply(): log.debug("Disconnected %s", self.path) @@ -1251,6 +1313,7 @@ class ServiceView(ObjectView): def _on_user_auto_connect(self, obj): state = obj.state + def on_reply(): log.info("Set AutoConnect=%s", state) @@ -1260,8 +1323,10 @@ class ServiceView(ObjectView): popup_error(self.obj, "Failed to Apply Auto Connect", exc.get_dbus_message()) - self.bus_obj.SetProperty("AutoConnect", dbus.Boolean(state), - reply_handler=on_reply, error_handler=on_error) + self.bus_obj.SetProperty( + "AutoConnect", dbus.Boolean(state), + reply_handler=on_reply, error_handler=on_error + ) def _on_readwrite_changed(self, name, value): def on_reply(): @@ -1273,8 +1338,10 @@ class ServiceView(ObjectView): popup_error(self.obj, "Failed to Apply %s" % (key,), exc.get_dbus_message()) self.reload_readwrite_list(key) - self.bus_obj.SetProperty(name, dbus.Array(value, signature="s"), - reply_handler=on_reply, error_handler=on_error) + self.bus_obj.SetProperty( + name, dbus.Array(value, signature="s"), + reply_handler=on_reply, error_handler=on_error + ) def _ipv4_apply(self): value = self.ipv4_method.item_selected.text @@ -1295,7 +1362,7 @@ class ServiceView(ObjectView): new["Netmask"] = make_variant(self.ipv4_netmask.text) if self.ipv4_gateway.text: new["Gateway"] = make_variant(self.ipv4_gateway.text) - if len(new) == 1: # no properties yet + if len(new) == 1: # no properties yet return conf = self.ipv4_properties["IPv4.Configuration"] @@ -1314,8 +1381,10 @@ class ServiceView(ObjectView): log.error("Failed to set IPv4.Configuration=%s: %s", new, exc) popup_error(self.obj, "Failed to Apply IPv4", exc.get_dbus_message()) - self.bus_obj.SetProperty("IPv4.Configuration", new, - reply_handler=on_reply, error_handler=on_error) + self.bus_obj.SetProperty( + "IPv4.Configuration", new, + reply_handler=on_reply, error_handler=on_error + ) def _on_ipv4_method(self, obj, item): if item.text == "Automatic": @@ -1339,6 +1408,7 @@ class ServiceView(ObjectView): def _on_ipv4_property_unfocused(self, obj): used = self.ipv4_properties["IPv4"] conf = self.ipv4_properties["IPv4.Configuration"] + def get_val(name): v = used.get(name) or conf.get(name) if not v: @@ -1356,7 +1426,7 @@ class ServiceView(ObjectView): elif item.text == "Automatic": method = "auto" conf = self.proxy_properties["Proxy.Configuration"] - editable = (method == "manual") and (not self.immutable) + #editable = (method == "manual") and (not self.immutable) # use editable... if method == conf["Method"]: return @@ -1396,6 +1466,7 @@ class ServiceView(ObjectView): config_set(self.name, 'Phase2', phase2_val) return + ######################################################################## # Main Actions: def show_techs(button, naviframe): @@ -1425,9 +1496,14 @@ def connect_service(path, properties): log.debug("connect to %s (%s): %s", name, path, dbus_dict_to_str(properties)) - ''' Connman only supports 2 phase auth via config files ''' + # Connman only supports 2 phase auth via config files if ("ieee8021x" in sec) and not config_exists(name): - popup_error(win, "This Network needs Configuration", "This network uses 802.1x authentication. Please configure the options in the section at the bottom.") + popup_error( + win, + "This Network needs Configuration", + "This network uses 802.1x authentication. " + "Please configure the options in the section at the bottom." + ) show_service(path, properties) return @@ -1437,7 +1513,7 @@ def connect_service(path, properties): def on_error(exc): exc_name = exc.get_dbus_name() if exc_name == "net.connman.Error.AlreadyConnected" or \ - exc_name == "net.connman.Error.InProgress": + exc_name == "net.connman.Error.InProgress": log.debug("Failed to Connect to %s (%s): %s", name, path, exc) return log.error("Failed to Connect to %s (%s): %s", name, path, exc) @@ -1469,6 +1545,7 @@ def agent_method(in_signature="", out_signature="", **kargs): out_signature=out_signature, **kargs) + class Agent(dbus.service.Object): path = "/org/enlightenment/econnman/agent"