From: James Troup Date: Sat, 27 Nov 2004 16:05:12 +0000 (+0000) Subject: 2004-11-27 James Troup * utils.py (validate_changes_file_arg... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=002d032f91d24da4a5478afa51dc718e8991cf25;p=dak 2004-11-27 James Troup * utils.py (validate_changes_file_arg): s/file/filename/. s/fatal/require_changes/. If require_changes is -1, ignore errors and return the .changes filename regardless. * ashley (main): pass require_changes=-1 to utils.validate_changes_file_arg(). --- diff --git a/ashley b/ashley index 4bf9a3cd..e832851f 100755 --- a/ashley +++ b/ashley @@ -2,7 +2,7 @@ # Dump variables from a .katie file to stdout # Copyright (C) 2001, 2002, 2004 James Troup -# $Id: ashley,v 1.10 2004-04-03 02:49:46 troup Exp $ +# $Id: ashley,v 1.11 2004-11-27 16:05:12 troup Exp $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -58,7 +58,7 @@ def main(): k = katie.Katie(Cnf); for arg in sys.argv[1:]: - arg = utils.validate_changes_file_arg(arg); + arg = utils.validate_changes_file_arg(arg,require_changes=-1); k.pkg.changes_file = arg; print "%s:" % (arg); k.init_vars(); diff --git a/utils.py b/utils.py index b2a2ae3e..5872117d 100644 --- a/utils.py +++ b/utils.py @@ -2,7 +2,7 @@ # Utility functions # Copyright (C) 2000, 2001, 2002, 2003, 2004 James Troup -# $Id: utils.py,v 1.70 2004-11-27 13:32:16 troup Exp $ +# $Id: utils.py,v 1.71 2004-11-27 16:05:12 troup Exp $ ################################################################################ @@ -601,30 +601,44 @@ def prefix_multi_line_string(str, prefix, include_blank_lines=0): ################################################################################ -def validate_changes_file_arg(file, fatal=1): +def validate_changes_file_arg(filename, require_changes=1): + """'filename' is either a .changes or .katie file. If 'filename' is a +.katie file, it's changed to be the corresponding .changes file. The +function then checks if the .changes file a) exists and b) is +readable and returns the .changes filename if so. If there's a +problem, the next action depends on the option 'require_changes' +argument: + + o If 'require_changes' == -1, errors are ignored and the .changes + filename is returned. + o If 'require_changes' == 0, a warning is given and 'None' is returned. + o If 'require_changes' == 1, a fatal error is raised. +""" error = None; - orig_filename = file - if file.endswith(".katie"): - file = file[:-6]+".changes"; + orig_filename = filename + if filename.endswith(".katie"): + filename = filename[:-6]+".changes"; - if not file.endswith(".changes"): + if not filename.endswith(".changes"): error = "invalid file type; not a changes file"; else: - if not os.access(file,os.R_OK): - if os.path.exists(file): + if not os.access(filename,os.R_OK): + if os.path.exists(filename): error = "permission denied"; else: error = "file not found"; if error: - if fatal: + if require_changes == 1: fubar("%s: %s." % (orig_filename, error)); - else: + elif require_changes == 0: warn("Skipping %s - %s" % (orig_filename, error)); return None; + else: # We only care about the .katie file + return filename; else: - return file; + return filename; ################################################################################