1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-26 03:21:44 +03:00
libvirt/docs/reformat-news.py
Daniel P. Berrangé 600462834f Remove all Author(s): lines from source file headers
In many files there are header comments that contain an Author:
statement, supposedly reflecting who originally wrote the code.
In a large collaborative project like libvirt, any non-trivial
file will have been modified by a large number of different
contributors. IOW, the Author: comments are quickly out of date,
omitting people who have made significant contribitions.

In some places Author: lines have been added despite the person
merely being responsible for creating the file by moving existing
code out of another file. IOW, the Author: lines give an incorrect
record of authorship.

With this all in mind, the comments are useless as a means to identify
who to talk to about code in a particular file. Contributors will always
be better off using 'git log' and 'git blame' if they need to  find the
author of a particular bit of code.

This commit thus deletes all Author: comments from the source and adds
a rule to prevent them reappearing.

The Copyright headers are similarly misleading and inaccurate, however,
we cannot delete these as they have legal meaning, despite being largely
inaccurate. In addition only the copyright holder is permitted to change
their respective copyright statement.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-12-13 16:08:38 +00:00

104 lines
2.7 KiB
Python
Executable File

#!/usr/bin/env python
# reformat-news.py: Reformat the NEWS file properly
#
# Copyright (C) 2017 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see
# <http://www.gnu.org/licenses/>.
from __future__ import print_function
import sys
COLUMNS = 80
def reformat_with_indent(text, initial_indent, indent):
res = ""
line = initial_indent
for word in text.split():
# If adding one more word (plus a whitespace, plus a newline)
# to the current line would push us over the desired number
# of columns we start a new line instead
if len(line) + len(word) > (COLUMNS - 2):
res = res + line + "\n"
line = indent
# We need to take care when we've just started a new line,
# as we don't want to add any additional leading whitespace
# in that case
if line == indent or line == initial_indent:
line = line + word
else:
line = line + " " + word
# Append whatever's left
res = res + line
return res
def reformat(line):
# Empty lines don't need to be reformatted or even inspected
if len(line) == 0:
return line
# For all non-empty lines, we decide the indentation level based
# on the first character
marker = line[0]
# Release
if marker == '#':
initial_indent = 0
indent = 2
# Section
elif marker == '*':
initial_indent = 2
indent = 4
# Change summary
elif marker == '-':
initial_indent = 4
indent = 6
# Change description
elif marker == '|':
initial_indent = 8
indent = 8
# In this one case, the marker should not ultimately show
# up in the output file, so we strip it before moving on
line = line[1:]
# Anything else should be left as-is
else:
return line
return reformat_with_indent(line, " " * initial_indent, " " * indent)
def main(args):
if len(args) < 2:
sys.stdout.write("Usage: " + args[0] + " FILE\n")
sys.exit(1)
with open(args[1], 'r') as f:
for line in f:
print(reformat(line.strip()))
if __name__ == "__main__":
main(sys.argv)