[elbe-devel] [PATCH] elbe: updated: use apt-pkg for version comparision

Kurt Kanzenbach kurt at linutronix.de
Fri Mar 24 15:10:58 CET 2017


Signed-off-by: Kurt Kanzenbach <kurt at linutronix.de>
---
 ...bian-added-python-packaging-as-dependency.patch | 25 ----------------------
 elbepack/updated.py                                | 24 +++++++++------------
 2 files changed, 10 insertions(+), 39 deletions(-)
 delete mode 100644 contrib/stretch/0001-updated-debian-added-python-packaging-as-dependency.patch

diff --git a/contrib/stretch/0001-updated-debian-added-python-packaging-as-dependency.patch b/contrib/stretch/0001-updated-debian-added-python-packaging-as-dependency.patch
deleted file mode 100644
index 1483e83..0000000
--- a/contrib/stretch/0001-updated-debian-added-python-packaging-as-dependency.patch
+++ /dev/null
@@ -1,25 +0,0 @@
-From b7b647a1151429894c2d6a4ae289e25df345d68e Mon Sep 17 00:00:00 2001
-From: Kurt Kanzenbach <kurt at linutronix.de>
-Date: Wed, 22 Mar 2017 12:36:39 +0100
-Subject: [PATCH] updated: debian: added python-packaging as dependency
-
-Signed-off-by: Kurt Kanzenbach <kurt at linutronix.de>
----
- debian/control | 1 +
- 1 file changed, 1 insertion(+)
-
-diff --git a/debian/control b/debian/control
-index 1148287..477ec2b 100644
---- a/debian/control
-+++ b/debian/control
-@@ -155,6 +155,7 @@ Depends: ${misc:Depends},
-   python-apt,
-   python-suds,
-   python-phyne,
-+  python-packaging,
-   lsb-base (>= 3.0-6)
- Suggests: python-pyudev,
-   usbmount
--- 
-2.1.4
-
diff --git a/elbepack/updated.py b/elbepack/updated.py
index 6b2a966..57c9927 100644
--- a/elbepack/updated.py
+++ b/elbepack/updated.py
@@ -26,6 +26,7 @@ import os
 import subprocess
 import sys
 import threading
+import apt_pkg
 
 from multiprocessing import Process
 from shutil import copyfile, rmtree, copy
@@ -42,12 +43,6 @@ from elbepack.aptprogress import (ElbeInstallProgress,
 from elbepack.gpg import unsign_file
 from elbepack.treeutils import etree
 
-downgrade_prevention_feature_available = True
-try:
-    from packaging import version
-except ImportError:
-    downgrade_prevention_feature_available = False
-
 class UpdateStatus:
     def __init__ (self):
         self.monitor = None
@@ -356,7 +351,9 @@ def is_downgrade (target_version, current_version, base_version):
     current = current_version
     if current == "":
         current = base_version
-    return version.parse (target_version) < version.parse (current)
+    apt_pkg.init_system ()
+    rv = apt_pkg.version_compare (target_version, current)
+    return rv < 0
 
 def is_downgrade_allowed ():
     return os.path.isfile ("/var/cache/elbe/.downgrade_allowed")
@@ -423,14 +420,13 @@ def action_select (upd_file, status):
     with rw_access ("/tmp", 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
-        except Exception as e:
-            status.log ('Error while reading XML files occurred: ' + str(e))
+    # prevent downgrades
+    try:
+        if reject_downgrade (status, "/tmp/new.xml"):
             return
+    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"))
-- 
2.1.4





More information about the elbe-devel mailing list