X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=utils.py;h=580ceda8d0920734dafd0a9ce65951b638a419fc;hb=de3991e803cc6f69d5eee0fbf75daf95b0f9969d;hp=5872117dc7460aa99a29004fe32fee2b0ce911c1;hpb=002d032f91d24da4a5478afa51dc718e8991cf25;p=dak.git diff --git a/utils.py b/utils.py index 5872117d..580ceda8 100644 --- a/utils.py +++ b/utils.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # Utility functions -# Copyright (C) 2000, 2001, 2002, 2003, 2004 James Troup -# $Id: utils.py,v 1.71 2004-11-27 16:05:12 troup Exp $ +# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 James Troup +# $Id: utils.py,v 1.73 2005-03-18 05:24:38 troup Exp $ ################################################################################ @@ -22,17 +22,16 @@ ################################################################################ -import commands, encodings.ascii, encodings.utf_8, encodings.latin_1, \ - email.Header, os, pwd, re, select, socket, shutil, string, sys, \ - tempfile, traceback; +import codecs, commands, email.Header, os, pwd, re, select, socket, shutil, \ + string, sys, tempfile, traceback; import apt_pkg; import db_access; ################################################################################ re_comments = re.compile(r"\#.*") -re_no_epoch = re.compile(r"^\d*\:") -re_no_revision = re.compile(r"\-[^-]*$") +re_no_epoch = re.compile(r"^\d+\:") +re_no_revision = re.compile(r"-[^-]+$") re_arch_from_filename = re.compile(r"/binary-[^/]+/") re_extract_src_version = re.compile (r"(\S+)\s*\((.*)\)") re_isadeb = re.compile (r"(.+?)_(.+?)_(.+)\.u?deb$"); @@ -48,7 +47,7 @@ changes_parse_error_exc = "Can't parse line in .changes file"; invalid_dsc_format_exc = "Invalid .dsc file"; nk_format_exc = "Unknown Format: in .changes file"; no_files_exc = "No Files: field in .dsc or .changes file."; -cant_open_exc = "Can't read file."; +cant_open_exc = "Can't open file"; unknown_hostname_exc = "Unknown hostname"; cant_overwrite_exc = "Permission denied; can't overwrite existent file." file_exists_exc = "Destination file exists"; @@ -298,12 +297,12 @@ def rfc2047_encode(s): """Encodes a (header) string per RFC2047 if necessary. If the string is neither ASCII nor UTF-8, it's assumed to be ISO-8859-1.""" try: - encodings.ascii.Codec().decode(s); + codecs.lookup('ascii')[1](s) return s; except UnicodeError: pass; try: - encodings.utf_8.Codec().decode(s); + codecs.lookup('utf-8')[1](s) h = email.Header.Header(s, 'utf-8', 998); return str(h); except UnicodeError: @@ -546,8 +545,8 @@ def changes_compare (a, b): return q; # Sort by source version - a_version = a_changes.get("version"); - b_version = b_changes.get("version"); + a_version = a_changes.get("version", "0"); + b_version = b_changes.get("version", "0"); q = apt_pkg.VersionCompare(a_version, b_version); if q: return q; @@ -654,7 +653,7 @@ def join_with_commas_and(list): ################################################################################ -def pp_dep (deps): +def pp_deps (deps): pp_deps = []; for atom in deps: (pkg, version, constraint) = atom;