replaced GObject with GLib in network.py

See the previous commit. And the one preceding that. And the one before
that. Keep going until /dev/brain0 gets symlinked to /dev/urandom
This commit is contained in:
Pranav Jerry 2021-11-16 22:00:00 +05:30
parent 183ce16eca
commit d7a84d8ccc
No known key found for this signature in database
GPG Key ID: F1DCDC4FED0A0C5B
2 changed files with 17 additions and 4 deletions

View File

@ -42,4 +42,4 @@ given below.
# #
# In case you forgot to change the version, skip the number # In case you forgot to change the version, skip the number
# and put the next number in the next commit. # and put the next number in the next commit.
__version__ = "0.5.1a0.dev4" __version__ = "0.5.1a0.dev5"

View File

@ -29,9 +29,8 @@ examples.
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from gi.repository import GObject
from dasbus.connection import SystemMessageBus from dasbus.connection import SystemMessageBus
from dasbus.loop import EventLoop from dasbus.loop import EventLoop, GLib
NETWORKD_BUS = "org.freedesktop.network1" NETWORKD_BUS = "org.freedesktop.network1"
@ -46,6 +45,7 @@ class NetworkD:
""" """
def __init__(self, runtime_dir="/run/systemd/network", bus=SystemMessageBus()): def __init__(self, runtime_dir="/run/systemd/network", bus=SystemMessageBus()):
print("NetworkD init")
self._bus = bus self._bus = bus
self.proxy_reload() self.proxy_reload()
@ -122,6 +122,9 @@ class NetworkD:
self.remove_config(i.name) self.remove_config(i.name)
# TODO: remove all calls to print() before merging to master
class NetworkLoop(NetworkD): class NetworkLoop(NetworkD):
"""Used to wait until a condition is met """Used to wait until a condition is met
@ -133,6 +136,7 @@ class NetworkLoop(NetworkD):
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
print("NetworkLoop init")
# first, initialise the parent object # first, initialise the parent object
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.waitfor = None self.waitfor = None
@ -141,6 +145,9 @@ class NetworkLoop(NetworkD):
def start_loop(self): def start_loop(self):
"""start the dasbus loop""" """start the dasbus loop"""
print("start loop")
print("waitfor", self.waitfor)
print("waitfor func", self.wait_function)
self.proxy.PropertiesChanged.connect(self.on_properties_changed) self.proxy.PropertiesChanged.connect(self.on_properties_changed)
self.loop.run() self.loop.run()
@ -150,31 +157,37 @@ class NetworkLoop(NetworkD):
network interface is shown routable by networkd. Does not wait network interface is shown routable by networkd. Does not wait
for timeout if timeout==0 for timeout if timeout==0
""" """
print("wait until routable")
self.wait_for_change("AddressState", self.on_addressstate_change) self.wait_for_change("AddressState", self.on_addressstate_change)
self.setup_timeout(timeout) self.setup_timeout(timeout)
return self.is_routable() return self.is_routable()
def wait_for_change(self, name, function): def wait_for_change(self, name, function):
"""used by the public functions""" """used by the public functions"""
print("wait for change")
self.waitfor = name self.waitfor = name
self.wait_function = function self.wait_function = function
self.start_loop() self.start_loop()
def on_addressstate_change(self): def on_addressstate_change(self):
"""quit the loop if the network is routable""" """quit the loop if the network is routable"""
print("on addrstate change")
if self.is_routable(): if self.is_routable():
self.loop.quit() self.loop.quit()
def on_properties_changed(self, bus_interface, data, blah): def on_properties_changed(self, bus_interface, data, blah):
"""give this function some documentation""" """give this function some documentation"""
print("on properties changed")
if self.waitfor in data: if self.waitfor in data:
return self.wait_function() return self.wait_function()
def setup_timeout(self, timeout): def setup_timeout(self, timeout):
"""setup a timeout""" """setup a timeout"""
print("setup timeout")
if timeout != 0: if timeout != 0:
GObject.timeout_add(timeout, self.on_timeout) GLib.timeout_add(timeout, self.on_timeout)
def on_timeout(self): def on_timeout(self):
"""called by dasbus when a timeout occurs""" """called by dasbus when a timeout occurs"""
print("on timeout")
self.loop.quit() self.loop.quit()