diff options
Diffstat (limited to 'scripts/maint/format_changelog.py')
-rwxr-xr-x | scripts/maint/format_changelog.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/scripts/maint/format_changelog.py b/scripts/maint/format_changelog.py index 35044b318..f67e89b60 100755 --- a/scripts/maint/format_changelog.py +++ b/scripts/maint/format_changelog.py @@ -23,6 +23,8 @@ import sys # 100 * the fourth power of overflowed characters # PLUS # .1 * a bit more than the cube of ragged space on the last line. +# PLUS +# OPENPAREN_PENALTY for each line that starts with ( # # We use an obvious dynamic programming algorithm to sorta approximate this. # It's not coded right or optimally, but it's fast enough for changelogs @@ -44,6 +46,8 @@ OVERFLOW_PENALTY = 2000 ORPHAN_PENALTY = 10000 +OPENPAREN_PENALTY = 200 + def generate_wrapping(words, divisions): lines = [] last = 0 @@ -65,6 +69,9 @@ def wrapping_quality(words, divisions, width1, width2): else: width = width2 + if line[0:1] == '(': + total += OPENPAREN_PENALTY + if length > width: total += OVERFLOW_PENALTY * ( (length - width) ** OVERFLOW_EXPONENT ) @@ -109,7 +116,7 @@ def wrap_graf(words, prefix_len1=0, prefix_len2=0, width=72): return lines def hyphenateable(word): - if re.match(r'^[^\d\-].*-', word): + if re.match(r'^[^\d\-]\D*-', word): stripped = re.sub(r'^\W+','',word) stripped = re.sub(r'\W+$','',word) return stripped not in NO_HYPHENATE @@ -211,7 +218,7 @@ class ChangeLog(object): elif tp == TP_ITEMBODY: if self.curgraf is None: self.curgraf = [] - self.cursection[2][1][-1].append(self.curgraf) + self.cursection[2][-1][1].append(self.curgraf) self.curgraf.append(line) else: @@ -263,7 +270,16 @@ class ChangeLog(object): CL = ChangeLog() parser = head_parser -sys.stdin = open('ChangeLog', 'r') +if len(sys.argv) == 1: + fname = 'ChangeLog' +else: + fname = sys.argv[1] + +fname_new = fname+".new" + +sys.stdin = open(fname, 'r') + +nextline = None for line in sys.stdin: line = line.rstrip() @@ -279,13 +295,14 @@ for line in sys.stdin: CL.lint() -sys.stdout = open('ChangeLog.new', 'w') +sys.stdout = open(fname_new, 'w') CL.dump() -print nextline +if nextline is not None: + print nextline for line in sys.stdin: sys.stdout.write(line) -os.rename('ChangeLog.new', 'ChangeLog') +os.rename(fname_new, fname) |