Py: Deprecate the compare_release function.
authorDidier Raboud <odyx@debian.org>
Wed, 23 May 2012 12:15:20 +0000 (14:15 +0200)
committerDidier Raboud <odyx@debian.org>
Wed, 23 May 2012 12:56:49 +0000 (14:56 +0200)
In the process, rewrite it to be based on release_index() for robustness.

lsb_release.py
test/test_lsb_release.py

index b7d1689d6785fa5002448c43b57ad5ff7b351290..acc56f4d3f71f5d933594f52a632a57e65bb7f41 100644 (file)
@@ -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 = []
index 85790c92bdff9aef7ac234f28dd9e5083e83abf2..100c0d2f51fa0fe736ca45efa08e7531337b7f75 100644 (file)
@@ -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))])