examples: ModemWatcher: convert comments in the doc strings
Move comments under the class and method definitions. Also rework boolean handling.
This commit is contained in:

committed by
Aleksander Morgado

parent
8bf1869f3c
commit
e685ce9ce5
@@ -23,20 +23,18 @@ gi.require_version('ModemManager', '1.0')
|
|||||||
from gi.repository import Gio, GLib, GObject, ModemManager
|
from gi.repository import Gio, GLib, GObject, ModemManager
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
The ModemWatcher class is responsible for monitoring ModemManager
|
|
||||||
"""
|
|
||||||
class ModemWatcher:
|
class ModemWatcher:
|
||||||
|
"""
|
||||||
|
The ModemWatcher class is responsible for monitoring ModemManager.
|
||||||
|
"""
|
||||||
|
|
||||||
"""
|
|
||||||
Constructor
|
|
||||||
"""
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Flag for initial logs
|
# Flag for initial logs
|
||||||
self.initializing = True
|
self.initializing = True
|
||||||
# Setup DBus monitoring
|
# Setup DBus monitoring
|
||||||
self.connection = Gio.bus_get_sync (Gio.BusType.SYSTEM, None)
|
self.connection = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||||
self.manager = ModemManager.Manager.new_sync (self.connection,
|
self.manager = ModemManager.Manager.new_sync(
|
||||||
|
self.connection,
|
||||||
Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START,
|
Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START,
|
||||||
None)
|
None)
|
||||||
# IDs for added/removed signals
|
# IDs for added/removed signals
|
||||||
@@ -49,25 +47,25 @@ class ModemWatcher:
|
|||||||
# Finish initialization
|
# Finish initialization
|
||||||
self.initializing = False
|
self.initializing = False
|
||||||
|
|
||||||
"""
|
|
||||||
ModemManager is now available
|
|
||||||
"""
|
|
||||||
def set_available(self):
|
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())
|
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_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.object_removed_id = self.manager.connect('object-removed', self.on_object_removed)
|
||||||
self.available = True
|
self.available = True
|
||||||
# Initial scan
|
# Initial scan
|
||||||
if self.initializing == True:
|
if self.initializing:
|
||||||
for obj in self.manager.get_objects():
|
for obj in self.manager.get_objects():
|
||||||
self.on_object_added(self.manager, obj)
|
self.on_object_added(self.manager, obj)
|
||||||
|
|
||||||
"""
|
|
||||||
ModemManager is now unavailable
|
|
||||||
"""
|
|
||||||
def set_unavailable(self):
|
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')
|
print('[ModemWatcher] ModemManager service not available in bus')
|
||||||
if self.object_added_id:
|
if self.object_added_id:
|
||||||
self.manager.disconnect(self.object_added_id)
|
self.manager.disconnect(self.object_added_id)
|
||||||
@@ -77,19 +75,19 @@ class ModemWatcher:
|
|||||||
self.object_removed_id = 0
|
self.object_removed_id = 0
|
||||||
self.available = False
|
self.available = False
|
||||||
|
|
||||||
"""
|
|
||||||
Name owner updates
|
|
||||||
"""
|
|
||||||
def on_name_owner(self, manager, prop):
|
def on_name_owner(self, manager, prop):
|
||||||
|
"""
|
||||||
|
Name owner updates.
|
||||||
|
"""
|
||||||
if self.manager.get_name_owner():
|
if self.manager.get_name_owner():
|
||||||
self.set_available()
|
self.set_available()
|
||||||
else:
|
else:
|
||||||
self.set_unavailable()
|
self.set_unavailable()
|
||||||
|
|
||||||
"""
|
|
||||||
Object added
|
|
||||||
"""
|
|
||||||
def on_object_added(self, manager, obj):
|
def on_object_added(self, manager, obj):
|
||||||
|
"""
|
||||||
|
Object added.
|
||||||
|
"""
|
||||||
modem = obj.get_modem()
|
modem = obj.get_modem()
|
||||||
print('[ModemWatcher] %s (%s) modem managed by ModemManager [%s]: %s' %
|
print('[ModemWatcher] %s (%s) modem managed by ModemManager [%s]: %s' %
|
||||||
(modem.get_manufacturer(),
|
(modem.get_manufacturer(),
|
||||||
@@ -100,9 +98,9 @@ class ModemWatcher:
|
|||||||
print('[ModemWatcher] ignoring failed modem: %s' %
|
print('[ModemWatcher] ignoring failed modem: %s' %
|
||||||
obj.get_object_path())
|
obj.get_object_path())
|
||||||
|
|
||||||
"""
|
|
||||||
Object removed
|
|
||||||
"""
|
|
||||||
def on_object_removed(self, manager, obj):
|
def on_object_removed(self, manager, obj):
|
||||||
|
"""
|
||||||
|
Object removed.
|
||||||
|
"""
|
||||||
print('[ModemWatcher] modem unmanaged by ModemManager: %s' %
|
print('[ModemWatcher] modem unmanaged by ModemManager: %s' %
|
||||||
obj.get_object_path())
|
obj.get_object_path())
|
||||||
|
Reference in New Issue
Block a user