From bc3e647fc33cea4a8733681d04fa862e432adba6 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Tue, 25 Jan 2011 22:01:26 +0100 Subject: [PATCH] wrap-and-sort: Add option to use on individual file (LP: #699696). --- debian/changelog | 5 ++++- doc/wrap-and-sort.1 | 9 +++++++-- wrap-and-sort | 47 +++++++++++++++++++++++++++++++++------------ 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/debian/changelog b/debian/changelog index 8ce50ae..f26b00d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,7 +10,10 @@ ubuntu-dev-tools (0.114) UNRELEASED; urgency=low - purge the errno utility per request of the ubuntu-dev-tools maintainer; errno now provided by the 'errno' package; (LP: #666540) - -- Dustin Kirkland Mon, 24 Jan 2011 00:40:03 -0600 + [ Benjamin Drung ] + * wrap-and-sort: Add option to use on individual file (LP: #699696). + + -- Benjamin Drung Tue, 25 Jan 2011 21:52:55 +0100 ubuntu-dev-tools (0.113) unstable; urgency=low diff --git a/doc/wrap-and-sort.1 b/doc/wrap-and-sort.1 index d227405..63f5415 100644 --- a/doc/wrap-and-sort.1 +++ b/doc/wrap-and-sort.1 @@ -27,8 +27,8 @@ control files and all .install files. Beside that \fBwrap\-and\-sort\fP removes trailing spaces in these files. .PP This script should be run in the root of a Debian package tree. It searches for -debian/control, debian/control.in, debian/copyright, debian/copyright.in, -and debian/*.install. +control, control.in, copyright, copyright.in, install, and *.install in the +debian directory. .SH OPTIONS .TP @@ -59,6 +59,11 @@ do not remove trailing whitespaces \fB\-d \fIPATH\fR, \fB\-\-debian\-directory\fR=\fIPATH\fR location of the \fIdebian\fR directory (default: \fB./debian\fR) .TP +\fB\-f\fI FILE\fR, \fB\-\-file\fR=\fIFILE\fR +Wrap and sort only the specified file. +You can specify this parameter multiple times. +All supported files will be processed if no files are specified. +.TP \fB\-v\fR, \fB\-\-verbose\fR print all files that are touched diff --git a/wrap-and-sort b/wrap-and-sort index febf120..6707a74 100755 --- a/wrap-and-sort +++ b/wrap-and-sort @@ -1,6 +1,6 @@ #!/usr/bin/python # -# Copyright (C) 2010, Benjamin Drung , +# Copyright (C) 2010-2011, Benjamin Drung # 2010, Stefano Rivera # # Permission to use, copy, modify, and/or distribute this software for any @@ -19,6 +19,7 @@ import glob import optparse import os import os.path +import re import sys from ubuntutools.control import Control @@ -37,6 +38,15 @@ CONTROL_LIST_FIELDS = ( "Xb-Npp-MimeType", ) +SUPPORTED_FILES = ( + "control", + "control.in", + "copyright", + "copyright.in", + "install", + "*.install", +) + class WrapAndSortControl(Control): def wrap_and_sort(self, wrap_always, short_indent, sort_paragraphs, keep_first): @@ -123,10 +133,7 @@ def sort_list(unsorted_list): return sorted(normal) + sorted(param) def wrap_and_sort(options): - debdir = lambda x: os.path.join(options.debian_directory, x) - - possible_control_files = [debdir("control"), debdir("control.in")] - control_files = [f for f in possible_control_files if os.path.isfile(f)] + control_files = [f for f in options.files if re.search("/control[^/]*$", f)] for control_file in control_files: if options.verbose: print control_file @@ -137,23 +144,28 @@ def wrap_and_sort(options): options.sort_binary_packages, options.keep_first) control.save() - possible_copyright_files = [debdir("copyright"), debdir("copyright.in")] - copyright_files = [f for f in possible_copyright_files if os.path.isfile(f)] + copyright_files = [f for f in options.files + if re.search("/copyright[^/]*$", f)] for copyright_file in copyright_files: if options.verbose: print copyright_file remove_trailing_whitespaces(copyright_file) - install_files = sorted(glob.glob(debdir("*.install"))) - if os.path.isfile(debdir("install")): - install_files.insert(0, debdir("install")) - for install_file in install_files: + install_files = [f for f in options.files if re.search("install$", f)] + for install_file in sorted(install_files): if options.verbose: print install_file install = Install(install_file) install.sort() install.save() +def get_files(debian_directory): + """Returns a list of files that should be wrapped and sorted.""" + files = [] + for supported_files in SUPPORTED_FILES: + files.extend(glob.glob(os.path.join(debian_directory, supported_files))) + return files + def main(): script_name = os.path.basename(sys.argv[0]) usage = "%s [options]" % (script_name) @@ -182,7 +194,11 @@ def main(): parser.add_option("-d", "--debian-directory", dest="debian_directory", help="location of the 'debian' directory (default: " "./debian)", metavar="PATH", default="debian") - parser.add_option("-v", "--verbose", help="print more information", + parser.add_option("-f", "--file", metavar="FILE", + dest="files", action="append", default=list(), + help="Wrap and sort only the specified file.") + parser.add_option("-v", "--verbose", + help="print all files that are touched", dest="verbose", action="store_true", default=False) (options, args) = parser.parse_args() @@ -195,6 +211,13 @@ def main(): parser.error('Debian directory not found, expecting "%s".' % \ options.debian_directory) + not_found = [f for f in options.files if not os.path.isfile(f)] + if not_found: + parser.error('Specified files not found: %s' % ", ".join(not_found)) + + if not options.files: + options.files = get_files(options.debian_directory) + wrap_and_sort(options) if __name__ == "__main__":