From 751b46f2793491b6332aab5841cfa51e0f8673a6 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 23 May 2012 14:15:20 +0200 Subject: [PATCH] Py: Deprecate the compare_release function. In the process, rewrite it to be based on release_index() for robustness. --- lsb_release.py | 19 +++++++++---------- test/test_lsb_release.py | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lsb_release.py b/lsb_release.py index b7d1689..acc56f4 100644 --- a/lsb_release.py +++ b/lsb_release.py @@ -24,6 +24,7 @@ import sys import subprocess import os import re +import warnings # XXX: Update as needed # This should really be included in apt-cache policy output... it is already @@ -187,16 +188,14 @@ def release_index(x): return 0 def compare_release(x, y): - suite_x = x[1].get('suite') - suite_y = y[1].get('suite') - - if suite_x and suite_y: - if suite_x in RELEASES_ORDER and suite_y in RELEASES_ORDER: - return RELEASES_ORDER.index(suite_y)-RELEASES_ORDER.index(suite_x) - else: - return (suite_x > suite_y) - (suite_x < suite_y) - - return 0 + warnings.warn('compare_release(x,y) is deprecated; please use the release_index(x) as key for sort() instead.', DeprecationWarning, stacklevel=2) + suite_x_i = release_index(x) + suite_y_i = release_index(y) + + try: + return suite_x_i - suite_y_i + except TypeError: + return (suite_x_i > suite_y_i) - (suite_x_i < suite_y_i) def parse_apt_policy(): data = [] diff --git a/test/test_lsb_release.py b/test/test_lsb_release.py index 85790c9..100c0d2 100644 --- a/test/test_lsb_release.py +++ b/test/test_lsb_release.py @@ -9,6 +9,8 @@ import string import os import sys +import warnings + def rnd_string(min_l,max_l): return ''.join( [random.choice(string.ascii_letters) for i in range(random.randint(min_l,max_l))]) -- 2.30.2