mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 16:11:15 +00:00
wrap-and-sort: Add option to use on individual file (LP: #699696).
This commit is contained in:
parent
ce34dff75f
commit
bc3e647fc3
5
debian/changelog
vendored
5
debian/changelog
vendored
@ -10,7 +10,10 @@ ubuntu-dev-tools (0.114) UNRELEASED; urgency=low
|
|||||||
- purge the errno utility per request of the ubuntu-dev-tools
|
- purge the errno utility per request of the ubuntu-dev-tools
|
||||||
maintainer; errno now provided by the 'errno' package; (LP: #666540)
|
maintainer; errno now provided by the 'errno' package; (LP: #666540)
|
||||||
|
|
||||||
-- Dustin Kirkland <kirkland@ubuntu.com> Mon, 24 Jan 2011 00:40:03 -0600
|
[ Benjamin Drung ]
|
||||||
|
* wrap-and-sort: Add option to use on individual file (LP: #699696).
|
||||||
|
|
||||||
|
-- Benjamin Drung <bdrung@debian.org> Tue, 25 Jan 2011 21:52:55 +0100
|
||||||
|
|
||||||
ubuntu-dev-tools (0.113) unstable; urgency=low
|
ubuntu-dev-tools (0.113) unstable; urgency=low
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ control files and all .install files. Beside that \fBwrap\-and\-sort\fP removes
|
|||||||
trailing spaces in these files.
|
trailing spaces in these files.
|
||||||
.PP
|
.PP
|
||||||
This script should be run in the root of a Debian package tree. It searches for
|
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,
|
control, control.in, copyright, copyright.in, install, and *.install in the
|
||||||
and debian/*.install.
|
debian directory.
|
||||||
|
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
@ -59,6 +59,11 @@ do not remove trailing whitespaces
|
|||||||
\fB\-d \fIPATH\fR, \fB\-\-debian\-directory\fR=\fIPATH\fR
|
\fB\-d \fIPATH\fR, \fB\-\-debian\-directory\fR=\fIPATH\fR
|
||||||
location of the \fIdebian\fR directory (default: \fB./debian\fR)
|
location of the \fIdebian\fR directory (default: \fB./debian\fR)
|
||||||
.TP
|
.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
|
\fB\-v\fR, \fB\-\-verbose\fR
|
||||||
print all files that are touched
|
print all files that are touched
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# Copyright (C) 2010, Benjamin Drung <bdrung@ubuntu.com>,
|
# Copyright (C) 2010-2011, Benjamin Drung <bdrung@ubuntu.com>
|
||||||
# 2010, Stefano Rivera <stefanor@ubuntu.com>
|
# 2010, Stefano Rivera <stefanor@ubuntu.com>
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and/or distribute this software for any
|
# Permission to use, copy, modify, and/or distribute this software for any
|
||||||
@ -19,6 +19,7 @@ import glob
|
|||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ubuntutools.control import Control
|
from ubuntutools.control import Control
|
||||||
@ -37,6 +38,15 @@ CONTROL_LIST_FIELDS = (
|
|||||||
"Xb-Npp-MimeType",
|
"Xb-Npp-MimeType",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SUPPORTED_FILES = (
|
||||||
|
"control",
|
||||||
|
"control.in",
|
||||||
|
"copyright",
|
||||||
|
"copyright.in",
|
||||||
|
"install",
|
||||||
|
"*.install",
|
||||||
|
)
|
||||||
|
|
||||||
class WrapAndSortControl(Control):
|
class WrapAndSortControl(Control):
|
||||||
def wrap_and_sort(self, wrap_always, short_indent, sort_paragraphs,
|
def wrap_and_sort(self, wrap_always, short_indent, sort_paragraphs,
|
||||||
keep_first):
|
keep_first):
|
||||||
@ -123,10 +133,7 @@ def sort_list(unsorted_list):
|
|||||||
return sorted(normal) + sorted(param)
|
return sorted(normal) + sorted(param)
|
||||||
|
|
||||||
def wrap_and_sort(options):
|
def wrap_and_sort(options):
|
||||||
debdir = lambda x: os.path.join(options.debian_directory, x)
|
control_files = [f for f in options.files if re.search("/control[^/]*$", f)]
|
||||||
|
|
||||||
possible_control_files = [debdir("control"), debdir("control.in")]
|
|
||||||
control_files = [f for f in possible_control_files if os.path.isfile(f)]
|
|
||||||
for control_file in control_files:
|
for control_file in control_files:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print control_file
|
print control_file
|
||||||
@ -137,23 +144,28 @@ def wrap_and_sort(options):
|
|||||||
options.sort_binary_packages, options.keep_first)
|
options.sort_binary_packages, options.keep_first)
|
||||||
control.save()
|
control.save()
|
||||||
|
|
||||||
possible_copyright_files = [debdir("copyright"), debdir("copyright.in")]
|
copyright_files = [f for f in options.files
|
||||||
copyright_files = [f for f in possible_copyright_files if os.path.isfile(f)]
|
if re.search("/copyright[^/]*$", f)]
|
||||||
for copyright_file in copyright_files:
|
for copyright_file in copyright_files:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print copyright_file
|
print copyright_file
|
||||||
remove_trailing_whitespaces(copyright_file)
|
remove_trailing_whitespaces(copyright_file)
|
||||||
|
|
||||||
install_files = sorted(glob.glob(debdir("*.install")))
|
install_files = [f for f in options.files if re.search("install$", f)]
|
||||||
if os.path.isfile(debdir("install")):
|
for install_file in sorted(install_files):
|
||||||
install_files.insert(0, debdir("install"))
|
|
||||||
for install_file in install_files:
|
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print install_file
|
print install_file
|
||||||
install = Install(install_file)
|
install = Install(install_file)
|
||||||
install.sort()
|
install.sort()
|
||||||
install.save()
|
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():
|
def main():
|
||||||
script_name = os.path.basename(sys.argv[0])
|
script_name = os.path.basename(sys.argv[0])
|
||||||
usage = "%s [options]" % (script_name)
|
usage = "%s [options]" % (script_name)
|
||||||
@ -182,7 +194,11 @@ def main():
|
|||||||
parser.add_option("-d", "--debian-directory", dest="debian_directory",
|
parser.add_option("-d", "--debian-directory", dest="debian_directory",
|
||||||
help="location of the 'debian' directory (default: "
|
help="location of the 'debian' directory (default: "
|
||||||
"./debian)", metavar="PATH", default="debian")
|
"./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)
|
dest="verbose", action="store_true", default=False)
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
@ -195,6 +211,13 @@ def main():
|
|||||||
parser.error('Debian directory not found, expecting "%s".' % \
|
parser.error('Debian directory not found, expecting "%s".' % \
|
||||||
options.debian_directory)
|
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)
|
wrap_and_sort(options)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user