<p>pespin has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18055">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ms_ofono: import pydbus and GLib modules on first use<br><br>Change-Id: I754e1290eb5593c0ef168f74747f42db1b50f16c<br>---<br>M src/osmo_gsm_tester/obj/ms_ofono.py<br>1 file changed, 26 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/55/18055/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/osmo_gsm_tester/obj/ms_ofono.py b/src/osmo_gsm_tester/obj/ms_ofono.py</span><br><span>index e03bab8..2598eee 100644</span><br><span>--- a/src/osmo_gsm_tester/obj/ms_ofono.py</span><br><span>+++ b/src/osmo_gsm_tester/obj/ms_ofono.py</span><br><span>@@ -17,21 +17,35 @@</span><br><span> # You should have received a copy of the GNU General Public License</span><br><span> # along with this program.  If not, see <http://www.gnu.org/licenses/>.</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+import os</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> from ..core import log, util, process</span><br><span> from ..core.event_loop import MainLoop</span><br><span> from .ms import MS</span><br><span> from . import sms</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-from pydbus import SystemBus, Variant</span><br><span style="color: hsl(0, 100%, 40%);">-import os</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-# Required for Gio.Cancellable.</span><br><span style="color: hsl(0, 100%, 40%);">-# See https://lazka.github.io/pgi-docs/Gio-2.0/classes/Cancellable.html#Gio.Cancellable</span><br><span style="color: hsl(0, 100%, 40%);">-from gi.module import get_introspection_module</span><br><span style="color: hsl(0, 100%, 40%);">-Gio = get_introspection_module('Gio')</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-from gi.repository import GLib</span><br><span style="color: hsl(120, 100%, 40%);">+_import_external_modules_done = False</span><br><span> bus = None</span><br><span style="color: hsl(120, 100%, 40%);">+Gio = None</span><br><span style="color: hsl(120, 100%, 40%);">+GLib = None</span><br><span style="color: hsl(120, 100%, 40%);">+Variant = None</span><br><span style="color: hsl(120, 100%, 40%);">+def _import_external_modules():</span><br><span style="color: hsl(120, 100%, 40%);">+    global _import_external_modules_done, bus, Gio, GLib, Variant</span><br><span style="color: hsl(120, 100%, 40%);">+    if _import_external_modules_done:</span><br><span style="color: hsl(120, 100%, 40%);">+        return</span><br><span style="color: hsl(120, 100%, 40%);">+    _import_external_modules_done = True</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Required for Gio.Cancellable.</span><br><span style="color: hsl(120, 100%, 40%);">+    # See https://lazka.github.io/pgi-docs/Gio-2.0/classes/Cancellable.html#Gio.Cancellable</span><br><span style="color: hsl(120, 100%, 40%);">+    from gi.module import get_introspection_module</span><br><span style="color: hsl(120, 100%, 40%);">+    Gio = get_introspection_module('Gio')</span><br><span style="color: hsl(120, 100%, 40%);">+    from gi.repository import GLib as glib_module</span><br><span style="color: hsl(120, 100%, 40%);">+    GLib = glib_module</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    from pydbus import SystemBus, Variant</span><br><span style="color: hsl(120, 100%, 40%);">+    bus = SystemBus()</span><br><span style="color: hsl(120, 100%, 40%);">+    from pydbus import Variant as variant_class</span><br><span style="color: hsl(120, 100%, 40%);">+    Variant = variant_class</span><br><span> </span><br><span> I_MODEM = 'org.ofono.Modem'</span><br><span> I_NETREG = 'org.ofono.NetworkRegistration'</span><br><span>@@ -68,9 +82,6 @@</span><br><span>     return DeferredDBus(dbus_iface, handler).subscription_id</span><br><span> </span><br><span> def systembus_get(path):</span><br><span style="color: hsl(0, 100%, 40%);">-    global bus</span><br><span style="color: hsl(0, 100%, 40%);">-    if not bus:</span><br><span style="color: hsl(0, 100%, 40%);">-        bus = SystemBus()</span><br><span>     return bus.get('org.ofono', path)</span><br><span> </span><br><span> def list_modems():</span><br><span>@@ -362,9 +373,11 @@</span><br><span>     CTX_PROT_IPv46 = 'dual'</span><br><span> </span><br><span>     def __init__(self, testenv, conf):</span><br><span style="color: hsl(120, 100%, 40%);">+        super().__init__('modem', conf)</span><br><span style="color: hsl(120, 100%, 40%);">+        _import_external_modules()</span><br><span>         self.syspath = conf.get('path')</span><br><span>         self.dbuspath = get_dbuspath_from_syspath(self.syspath)</span><br><span style="color: hsl(0, 100%, 40%);">-        super().__init__(self.dbuspath, conf)</span><br><span style="color: hsl(120, 100%, 40%);">+        self.set_name(self.dbuspath)</span><br><span>         self.dbg('creating from syspath %s' % self.syspath)</span><br><span>         self._ki = None</span><br><span>         self._imsi = None</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18055">change 18055</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18055"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-gsm-tester </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I754e1290eb5593c0ef168f74747f42db1b50f16c </div>
<div style="display:none"> Gerrit-Change-Number: 18055 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>