mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-12 23:51:08 +00:00
Add one-space-indentation option: --short-indent
This commit is contained in:
parent
b04aa7844f
commit
11d5296e86
3
debian/changelog
vendored
3
debian/changelog
vendored
@ -5,8 +5,9 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low
|
|||||||
* wrap-and-sort:
|
* wrap-and-sort:
|
||||||
- Correct typo in options --wrap-allways -> --wrap-always
|
- Correct typo in options --wrap-allways -> --wrap-always
|
||||||
- Sort debian/install as well as debian/*.install
|
- Sort debian/install as well as debian/*.install
|
||||||
|
- Add one-space-indentation option: --short-indent
|
||||||
|
|
||||||
-- Stefano Rivera <stefanor@ubuntu.com> Wed, 24 Nov 2010 18:47:21 +0200
|
-- Stefano Rivera <stefanor@ubuntu.com> Wed, 24 Nov 2010 19:15:28 +0200
|
||||||
|
|
||||||
ubuntu-dev-tools (0.106) experimental; urgency=low
|
ubuntu-dev-tools (0.106) experimental; urgency=low
|
||||||
|
|
||||||
|
@ -53,22 +53,26 @@ class Control(object):
|
|||||||
f.write(content.encode("utf-8"))
|
f.write(content.encode("utf-8"))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def wrap_and_sort(self, wrap_always=True):
|
def wrap_and_sort(self, wrap_always, short_indent):
|
||||||
for paragraph in self.paragraphs:
|
for paragraph in self.paragraphs:
|
||||||
for field in CONTROL_LIST_FIELDS:
|
for field in CONTROL_LIST_FIELDS:
|
||||||
if field in paragraph:
|
if field in paragraph:
|
||||||
self._wrap_field(paragraph, field, wrap_always)
|
self._wrap_field(paragraph, field, wrap_always,
|
||||||
|
short_indent)
|
||||||
if "Uploaders" in paragraph:
|
if "Uploaders" in paragraph:
|
||||||
self._wrap_field(paragraph, "Uploaders", wrap_always, False)
|
self._wrap_field(paragraph, "Uploaders", wrap_always,
|
||||||
|
short_indent, False)
|
||||||
|
|
||||||
def _wrap_field(self, control, entry, wrap_always, sort=True):
|
def _wrap_field(self, control, entry, wrap_always, short_indent, sort=True):
|
||||||
packages = map(lambda x: x.strip(), control[entry].split(","))
|
packages = map(lambda x: x.strip(), control[entry].split(","))
|
||||||
if sort:
|
if sort:
|
||||||
packages = sort_list(packages)
|
packages = sort_list(packages)
|
||||||
|
|
||||||
lenght = len(entry) + 2 * len(packages) + sum(map(len, packages))
|
lenght = len(entry) + 2 * len(packages) + sum(map(len, packages))
|
||||||
if wrap_always or lenght > 80:
|
if wrap_always or lenght > 80:
|
||||||
indentation = " " * (len(entry) + 2)
|
indentation = " "
|
||||||
|
if not short_indent:
|
||||||
|
indentation *= (len(entry) + 2)
|
||||||
packages_with_indention = map(lambda x: indentation + x, packages)
|
packages_with_indention = map(lambda x: indentation + x, packages)
|
||||||
control[entry] = ",\n".join(packages_with_indention).strip()
|
control[entry] = ",\n".join(packages_with_indention).strip()
|
||||||
else:
|
else:
|
||||||
@ -110,7 +114,7 @@ def sort_list(l):
|
|||||||
param = filter(lambda x: x.startswith("${"), l)
|
param = filter(lambda x: x.startswith("${"), l)
|
||||||
return sorted(normal) + sorted(param)
|
return sorted(normal) + sorted(param)
|
||||||
|
|
||||||
def main(script_name, cleanup, wrap_always, verbose=False):
|
def main(script_name, cleanup, wrap_always, short_indent, verbose=False):
|
||||||
if not os.path.isdir("debian"):
|
if not os.path.isdir("debian"):
|
||||||
print >> sys.stderr, "%s: Error: No debian directory found." % \
|
print >> sys.stderr, "%s: Error: No debian directory found." % \
|
||||||
(script_name)
|
(script_name)
|
||||||
@ -122,7 +126,7 @@ def main(script_name, cleanup, wrap_always, verbose=False):
|
|||||||
if verbose:
|
if verbose:
|
||||||
print control_file
|
print control_file
|
||||||
control = Control(control_file, cleanup)
|
control = Control(control_file, cleanup)
|
||||||
control.wrap_and_sort(wrap_always)
|
control.wrap_and_sort(wrap_always, short_indent)
|
||||||
control.save()
|
control.save()
|
||||||
|
|
||||||
copyright_files = filter(os.path.isfile,
|
copyright_files = filter(os.path.isfile,
|
||||||
@ -151,6 +155,10 @@ if __name__ == "__main__":
|
|||||||
parser.add_option("-a", "--wrap-always",
|
parser.add_option("-a", "--wrap-always",
|
||||||
help="wrap lists even if they fit into one 80 character long line",
|
help="wrap lists even if they fit into one 80 character long line",
|
||||||
dest="wrap_always", action="store_true", default=False)
|
dest="wrap_always", action="store_true", default=False)
|
||||||
|
parser.add_option("-s", "--short-indent",
|
||||||
|
help="only indent wrapped lines by one space (default is in-line "
|
||||||
|
"with the field name)",
|
||||||
|
dest="short_indent", action="store_true", default=False)
|
||||||
parser.add_option("-n", "--no-cleanup", help="don't cleanup whitespaces",
|
parser.add_option("-n", "--no-cleanup", help="don't cleanup whitespaces",
|
||||||
dest="cleanup", action="store_false", default=True)
|
dest="cleanup", action="store_false", default=True)
|
||||||
parser.add_option("-v", "--verbose", help="print more information",
|
parser.add_option("-v", "--verbose", help="print more information",
|
||||||
@ -163,4 +171,5 @@ if __name__ == "__main__":
|
|||||||
"Unsupported additional parameters specified", ", ".join(args))
|
"Unsupported additional parameters specified", ", ".join(args))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
main(script_name, options.cleanup, options.wrap_always, options.verbose)
|
main(script_name, options.cleanup, options.wrap_always,
|
||||||
|
options.short_indent, options.verbose)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user