]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blobdiff - wwwbin/clean-dups.py
Fix call to cmp_to_key
[projects/pld-ftp-admin.git] / wwwbin / clean-dups.py
index ff9d65f6bd26a78a87c7abf72686a66bc714abcc..b1b0e33c8fd75451a29b45ec6e17d241e127f30e 100755 (executable)
@@ -1,9 +1,10 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 # arekm, 2008
 # remove 
 
 from __future__ import print_function
 
+import functools
 import os
 import re
 import time
@@ -79,8 +80,14 @@ def compare(f1, f2):
        os.close(fd1)
        os.close(fd2)
 
-       l1 = rpm.versionCompare(h1, h2)
-       l2 = rpm.versionCompare(h2, h1)
+       try:
+               l1 = rpm.versionCompare(h1, h2)
+       except ValueError:
+               l1 = -1
+       try:
+               l2 = rpm.versionCompare(h2, h1)
+       except ValueError:
+               l2 = -1
 
        if l1 > 0 and l2 > 0:
                return 0
@@ -89,7 +96,7 @@ def compare(f1, f2):
 
 
 def find_old(files):
-       return sorted(files, compare)
+       return sorted(files, key=functools.cmp_to_key(compare))
 
 files = {}
 dupes = {}
@@ -114,8 +121,8 @@ for file in os.listdir(dir):
 
        name = m.group(1)
 
-       if files.has_key(name):
-               if dupes.has_key(name):
+       if name in files:
+               if name in dupes:
                        dupes[name].append(file)
                else:
                        dupes[name] = [ files[name] ]
This page took 0.086589 seconds and 4 git commands to generate.