From: Yegor Yefremov <yegorsli...@googlemail.com> Move comments under the class and method definitions.
Also rework boolean handling. --- examples/modem-watcher-python/ModemWatcher.py | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/examples/modem-watcher-python/ModemWatcher.py b/examples/modem-watcher-python/ModemWatcher.py index 2311a8ad..7ee8939b 100644 --- a/examples/modem-watcher-python/ModemWatcher.py +++ b/examples/modem-watcher-python/ModemWatcher.py @@ -23,22 +23,20 @@ gi.require_version('ModemManager', '1.0') from gi.repository import Gio, GLib, GObject, ModemManager -""" -The ModemWatcher class is responsible for monitoring ModemManager -""" class ModemWatcher: - """ - Constructor + The ModemWatcher class is responsible for monitoring ModemManager. """ + def __init__(self): # Flag for initial logs self.initializing = True # Setup DBus monitoring - self.connection = Gio.bus_get_sync (Gio.BusType.SYSTEM, None) - self.manager = ModemManager.Manager.new_sync (self.connection, - Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, - None) + self.connection = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) + self.manager = ModemManager.Manager.new_sync( + self.connection, + Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, + None) # IDs for added/removed signals self.object_added_id = 0 self.object_removed_id = 0 @@ -49,25 +47,25 @@ class ModemWatcher: # Finish initialization self.initializing = False - """ - ModemManager is now available - """ def set_available(self): - if self.available == False or self.initializing == True: + """ + ModemManager is now available. + """ + if not self.available or self.initializing: print('[ModemWatcher] ModemManager %s service is available in bus' % self.manager.get_version()) self.object_added_id = self.manager.connect('object-added', self.on_object_added) self.object_removed_id = self.manager.connect('object-removed', self.on_object_removed) self.available = True # Initial scan - if self.initializing == True: + if self.initializing: for obj in self.manager.get_objects(): self.on_object_added(self.manager, obj) - """ - ModemManager is now unavailable - """ def set_unavailable(self): - if self.available == True or self.initializing == True: + """ + ModemManager is now unavailable. + """ + if self.available or self.initializing: print('[ModemWatcher] ModemManager service not available in bus') if self.object_added_id: self.manager.disconnect(self.object_added_id) @@ -77,19 +75,19 @@ class ModemWatcher: self.object_removed_id = 0 self.available = False - """ - Name owner updates - """ def on_name_owner(self, manager, prop): + """ + Name owner updates. + """ if self.manager.get_name_owner(): self.set_available() else: self.set_unavailable() - """ - Object added - """ def on_object_added(self, manager, obj): + """ + Object added. + """ modem = obj.get_modem() print('[ModemWatcher] %s (%s) modem managed by ModemManager [%s]: %s' % (modem.get_manufacturer(), @@ -100,9 +98,9 @@ class ModemWatcher: print('[ModemWatcher] ignoring failed modem: %s' % obj.get_object_path()) - """ - Object removed - """ def on_object_removed(self, manager, obj): + """ + Object removed. + """ print('[ModemWatcher] modem unmanaged by ModemManager: %s' % obj.get_object_path()) -- 2.17.0 _______________________________________________ ModemManager-devel mailing list ModemManager-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel