[elbe-devel] [PATCH 4/4] updated: Depend on pyudev and packaging

bage at linutronix.de bage at linutronix.de
Fri Oct 2 19:46:20 CEST 2020


From: Bastian Germann <bage at linutronix.de>

Make the two optional packages mandatory dependences.
This gets rid of the last ImportError catches in Elbe.

Signed-off-by: Bastian Germann <bage at linutronix.de>
---
 debian/control               |  5 +++--
 elbepack/updated.py          | 20 +++++++-------------
 elbepack/updated_monitors.py |  7 +------
 3 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/debian/control b/debian/control
index 228c466f3..949f161ff 100644
--- a/debian/control
+++ b/debian/control
@@ -191,11 +191,12 @@ Depends: ${misc:Depends},
   python3-lxml (>= 2.3.2-1),
   python3-pyinotify,
   python3-apt,
+  python3-packaging,
+  python3-pyudev,
   python3-suds,
   python3-spyne,
   lsb-base (>= 3.0-6)
-Suggests: python3-pyudev,
-  usbmount
+Suggests: usbmount
 Description: update daemon for embedded systems
  This package is typically installed on a embedded system. The update daemon
  monitors a directory or USB mounts. If an ELBE update file (generated by
diff --git a/elbepack/updated.py b/elbepack/updated.py
index 4c73bbad3..f9117153e 100644
--- a/elbepack/updated.py
+++ b/elbepack/updated.py
@@ -18,6 +18,7 @@ from multiprocessing import Process
 from zipfile import (ZipFile, BadZipfile)
 from shutil import copyfile, rmtree, copy
 
+from packaging import version
 from syslog import syslog
 
 from suds.client import Client
@@ -36,12 +37,6 @@ from elbepack.egpg import unsign_file
 from elbepack.treeutils import etree
 from elbepack.shellhelper import CommandError, system
 
-downgrade_prevention_feature_available = True
-try:
-    from packaging import version
-except ImportError:
-    downgrade_prevention_feature_available = False
-
 # TODO:py3 Remove object inheritance
 # pylint: disable=useless-object-inheritance
 class UpdateStatus(object):
@@ -477,14 +472,13 @@ def action_select(upd_file, status):
         upd_file_z.extract("new.xml", "/tmp/")
 
     # prevent downgrades (if available)
-    if downgrade_prevention_feature_available:
-        try:
-            if reject_downgrade(status, "/tmp/new.xml"):
-                return
-        # pylint: disable=broad-except
-        except Exception as e:
-            status.log('Error while reading XML files occurred: ' + str(e))
+    try:
+        if reject_downgrade(status, "/tmp/new.xml"):
             return
+    # pylint: disable=broad-except
+    except Exception as e:
+        status.log('Error while reading XML files occurred: ' + str(e))
+        return
 
     xml = etree("/tmp/new.xml")
     prefix = status.repo_dir + "/" + fname_replace(xml.text("/project/name"))
diff --git a/elbepack/updated_monitors.py b/elbepack/updated_monitors.py
index 16b4994f2..8424aaa4a 100644
--- a/elbepack/updated_monitors.py
+++ b/elbepack/updated_monitors.py
@@ -7,12 +7,7 @@
 import os
 import threading
 import pyinotify
-
-try:
-    import pyudev
-    udev_available = True
-except ImportError:
-    udev_available = False
+import pyudev
 
 from elbepack.updated import is_update_file, handle_update_file
 
-- 
2.28.0



More information about the elbe-devel mailing list