mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
wrap-and-sort: Make pylint a little bit happier.
This commit is contained in:
parent
9fa9f3eb96
commit
8351e6876d
@ -42,7 +42,7 @@ class Control(object):
|
|||||||
self.filename = filename
|
self.filename = filename
|
||||||
sequence = open(filename)
|
sequence = open(filename)
|
||||||
if cleanup:
|
if cleanup:
|
||||||
sequence = map(lambda l: l.rstrip(), sequence.readlines())
|
sequence = [l.rstrip() for l in sequence.readlines()]
|
||||||
self.paragraphs = list()
|
self.paragraphs = list()
|
||||||
for paragraph in debian.deb822.Deb822.iter_paragraphs(sequence):
|
for paragraph in debian.deb822.Deb822.iter_paragraphs(sequence):
|
||||||
self.paragraphs.append(paragraph)
|
self.paragraphs.append(paragraph)
|
||||||
@ -50,7 +50,7 @@ class Control(object):
|
|||||||
def save(self, filename=None):
|
def save(self, filename=None):
|
||||||
if filename:
|
if filename:
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
content = u"\n".join(map(lambda x: x.dump(), self.paragraphs))
|
content = u"\n".join([x.dump() for x in self.paragraphs])
|
||||||
f = open(self.filename, "w")
|
f = open(self.filename, "w")
|
||||||
f.write(content.encode("utf-8"))
|
f.write(content.encode("utf-8"))
|
||||||
f.close()
|
f.close()
|
||||||
@ -78,7 +78,7 @@ class Control(object):
|
|||||||
self.paragraphs = first + sorted(sortable, key=key)
|
self.paragraphs = first + sorted(sortable, key=key)
|
||||||
|
|
||||||
def _wrap_field(self, control, entry, wrap_always, short_indent, sort=True):
|
def _wrap_field(self, control, entry, wrap_always, short_indent, sort=True):
|
||||||
packages = map(lambda x: x.strip(), control[entry].split(","))
|
packages = [x.strip() for x in control[entry].split(",")]
|
||||||
if sort:
|
if sort:
|
||||||
# Remove duplicate entries
|
# Remove duplicate entries
|
||||||
packages = set(packages)
|
packages = set(packages)
|
||||||
@ -87,12 +87,12 @@ class Control(object):
|
|||||||
packages.remove("")
|
packages.remove("")
|
||||||
packages = sort_list(packages)
|
packages = sort_list(packages)
|
||||||
|
|
||||||
length = len(entry) + 2 * len(packages) + sum(map(len, packages))
|
length = len(entry) + sum([2 + len(package) for package in packages])
|
||||||
if wrap_always or length > 80:
|
if wrap_always or length > 80:
|
||||||
indentation = " "
|
indentation = " "
|
||||||
if not short_indent:
|
if not short_indent:
|
||||||
indentation *= len(entry) + 2
|
indentation *= len(entry) + 2
|
||||||
packages_with_indention = map(lambda x: indentation + x, packages)
|
packages_with_indention = [indentation + x for x in packages]
|
||||||
packages_with_indention = ",\n".join(packages_with_indention)
|
packages_with_indention = ",\n".join(packages_with_indention)
|
||||||
if short_indent:
|
if short_indent:
|
||||||
control[entry] = "\n" + packages_with_indention
|
control[entry] = "\n" + packages_with_indention
|
||||||
@ -126,22 +126,22 @@ def remove_trailing_whitespaces(filename):
|
|||||||
assert os.path.isfile(filename), "%s does not exist." % (filename)
|
assert os.path.isfile(filename), "%s does not exist." % (filename)
|
||||||
content = open(filename).read().rstrip() + "\n"
|
content = open(filename).read().rstrip() + "\n"
|
||||||
lines = content.split("\n")
|
lines = content.split("\n")
|
||||||
lines = map(lambda l: l.rstrip(), lines)
|
lines = [l.rstrip() for l in lines]
|
||||||
new_content = "\n".join(lines)
|
new_content = "\n".join(lines)
|
||||||
f = open(filename, "w")
|
f = open(filename, "w")
|
||||||
f.write(new_content)
|
f.write(new_content)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def sort_list(l):
|
def sort_list(unsorted_list):
|
||||||
normal = filter(lambda x: not x.startswith("${"), l)
|
normal = [x for x in unsorted_list if not x.startswith("${")]
|
||||||
param = filter(lambda x: x.startswith("${"), l)
|
param = [x for x in unsorted_list if x.startswith("${")]
|
||||||
return sorted(normal) + sorted(param)
|
return sorted(normal) + sorted(param)
|
||||||
|
|
||||||
def main(options):
|
def main(options):
|
||||||
debdir = lambda x: os.path.join(options.debian_directory, x)
|
debdir = lambda x: os.path.join(options.debian_directory, x)
|
||||||
|
|
||||||
control_files = filter(os.path.isfile,
|
control_files = filter(os.path.isfile,
|
||||||
[debdir("control"), debdir("control.in")])
|
[debdir("control"), debdir("control.in")])
|
||||||
for control_file in control_files:
|
for control_file in control_files:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print control_file
|
print control_file
|
||||||
@ -151,7 +151,7 @@ def main(options):
|
|||||||
control.save()
|
control.save()
|
||||||
|
|
||||||
copyright_files = filter(os.path.isfile,
|
copyright_files = filter(os.path.isfile,
|
||||||
[debdir("copyright"), debdir("copyright.in")])
|
[debdir("copyright"), debdir("copyright.in")])
|
||||||
for copyright_file in copyright_files:
|
for copyright_file in copyright_files:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print copyright_file
|
print copyright_file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user