X-Git-Url: https://git.pld-linux.org/?a=blobdiff_plain;f=wwwbin%2Fclean-dups.py;h=b1b0e33c8fd75451a29b45ec6e17d241e127f30e;hb=8c195b0ffcd930308f26c52ff7d081e22bac7bbe;hp=ff9d65f6bd26a78a87c7abf72686a66bc714abcc;hpb=9c170c6153b10298811a5de004899f912d8b1e4d;p=projects%2Fpld-ftp-admin.git diff --git a/wwwbin/clean-dups.py b/wwwbin/clean-dups.py index ff9d65f..b1b0e33 100755 --- a/wwwbin/clean-dups.py +++ b/wwwbin/clean-dups.py @@ -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] ]