2014-04-24 19:44:24 +02:00
|
|
|
#!/usr/bin/python
|
2019-01-16 18:33:22 +01:00
|
|
|
# Copyright (c) 2014-2019, The Tor Project, Inc.
|
2014-04-24 19:44:24 +02:00
|
|
|
# See LICENSE for licensing information
|
|
|
|
#
|
|
|
|
# This script reformats a section of the changelog to wrap everything to
|
|
|
|
# the right width and put blank lines in the right places. Eventually,
|
|
|
|
# it might include a linter.
|
|
|
|
#
|
|
|
|
# To run it, pipe a section of the changelog (starting with "Changes
|
|
|
|
# in Tor 0.x.y.z-alpha" through the script.)
|
|
|
|
|
2019-12-12 06:58:51 +01:00
|
|
|
# Future imports for Python 2.7, mandatory in 3.0
|
|
|
|
from __future__ import division
|
2019-12-09 16:53:48 +01:00
|
|
|
from __future__ import print_function
|
2019-12-12 06:58:51 +01:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-04-25 08:43:19 +02:00
|
|
|
import os
|
2014-04-24 19:44:24 +02:00
|
|
|
import re
|
|
|
|
import sys
|
2014-10-19 18:44:19 +02:00
|
|
|
import optparse
|
2014-05-02 18:50:23 +02:00
|
|
|
|
|
|
|
# ==============================
|
|
|
|
# Oh, look! It's a cruddy approximation to Knuth's elegant text wrapping
|
|
|
|
# algorithm, with totally ad hoc parameters!
|
|
|
|
#
|
|
|
|
# We're trying to minimize:
|
|
|
|
# The total of the cubes of ragged space on underflowed intermediate lines,
|
|
|
|
# PLUS
|
|
|
|
# 100 * the fourth power of overflowed characters
|
|
|
|
# PLUS
|
|
|
|
# .1 * a bit more than the cube of ragged space on the last line.
|
2014-05-14 18:56:09 +02:00
|
|
|
# PLUS
|
|
|
|
# OPENPAREN_PENALTY for each line that starts with (
|
2014-05-02 18:50:23 +02:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# (Code found in an old directory of mine, lightly cleaned. -NM)
|
|
|
|
|
|
|
|
NO_HYPHENATE=set("""
|
|
|
|
pf-divert
|
2014-10-19 18:57:57 +02:00
|
|
|
tor-resolve
|
|
|
|
tor-gencert
|
2014-05-02 18:50:23 +02:00
|
|
|
""".split())
|
|
|
|
|
|
|
|
LASTLINE_UNDERFLOW_EXPONENT = 1
|
|
|
|
LASTLINE_UNDERFLOW_PENALTY = 1
|
|
|
|
|
|
|
|
UNDERFLOW_EXPONENT = 3
|
|
|
|
UNDERFLOW_PENALTY = 1
|
|
|
|
|
|
|
|
OVERFLOW_EXPONENT = 4
|
|
|
|
OVERFLOW_PENALTY = 2000
|
|
|
|
|
|
|
|
ORPHAN_PENALTY = 10000
|
|
|
|
|
2014-05-14 18:56:09 +02:00
|
|
|
OPENPAREN_PENALTY = 200
|
|
|
|
|
2014-05-02 18:50:23 +02:00
|
|
|
def generate_wrapping(words, divisions):
|
|
|
|
lines = []
|
|
|
|
last = 0
|
|
|
|
for i in divisions:
|
|
|
|
w = words[last:i]
|
|
|
|
last = i
|
|
|
|
line = " ".join(w).replace("\xff ","-").replace("\xff","-")
|
2015-05-06 00:23:56 +02:00
|
|
|
lines.append(line.strip())
|
2014-05-02 18:50:23 +02:00
|
|
|
return lines
|
|
|
|
|
|
|
|
def wrapping_quality(words, divisions, width1, width2):
|
|
|
|
total = 0.0
|
|
|
|
|
|
|
|
lines = generate_wrapping(words, divisions)
|
|
|
|
for line in lines:
|
|
|
|
length = len(line)
|
|
|
|
if line is lines[0]:
|
|
|
|
width = width1
|
|
|
|
else:
|
|
|
|
width = width2
|
|
|
|
|
2014-05-14 18:56:09 +02:00
|
|
|
if line[0:1] == '(':
|
|
|
|
total += OPENPAREN_PENALTY
|
|
|
|
|
2014-05-02 18:50:23 +02:00
|
|
|
if length > width:
|
|
|
|
total += OVERFLOW_PENALTY * (
|
|
|
|
(length - width) ** OVERFLOW_EXPONENT )
|
|
|
|
else:
|
|
|
|
if line is lines[-1]:
|
|
|
|
e,p = (LASTLINE_UNDERFLOW_EXPONENT, LASTLINE_UNDERFLOW_PENALTY)
|
|
|
|
if " " not in line:
|
|
|
|
total += ORPHAN_PENALTY
|
|
|
|
else:
|
|
|
|
e,p = (UNDERFLOW_EXPONENT, UNDERFLOW_PENALTY)
|
|
|
|
|
|
|
|
total += p * ((width - length) ** e)
|
|
|
|
|
|
|
|
return total
|
|
|
|
|
|
|
|
def wrap_graf(words, prefix_len1=0, prefix_len2=0, width=72):
|
|
|
|
wrapping_after = [ (0,), ]
|
|
|
|
|
|
|
|
w1 = width - prefix_len1
|
|
|
|
w2 = width - prefix_len2
|
|
|
|
|
|
|
|
for i in range(1, len(words)+1):
|
|
|
|
best_so_far = None
|
|
|
|
best_score = 1e300
|
|
|
|
for j in range(i):
|
|
|
|
t = wrapping_after[j]
|
|
|
|
t1 = t[:-1] + (i,)
|
|
|
|
t2 = t + (i,)
|
|
|
|
wq1 = wrapping_quality(words, t1, w1, w2)
|
|
|
|
wq2 = wrapping_quality(words, t2, w1, w2)
|
|
|
|
|
|
|
|
if wq1 < best_score:
|
|
|
|
best_so_far = t1
|
|
|
|
best_score = wq1
|
|
|
|
if wq2 < best_score:
|
|
|
|
best_so_far = t2
|
|
|
|
best_score = wq2
|
|
|
|
wrapping_after.append( best_so_far )
|
|
|
|
|
|
|
|
lines = generate_wrapping(words, wrapping_after[-1])
|
|
|
|
|
|
|
|
return lines
|
|
|
|
|
2014-10-19 18:59:17 +02:00
|
|
|
def hyphenatable(word):
|
2014-10-19 18:57:57 +02:00
|
|
|
if "--" in word:
|
|
|
|
return False
|
|
|
|
|
2014-05-29 17:30:15 +02:00
|
|
|
if re.match(r'^[^\d\-]\D*-', word):
|
2014-05-02 18:50:23 +02:00
|
|
|
stripped = re.sub(r'^\W+','',word)
|
|
|
|
stripped = re.sub(r'\W+$','',word)
|
|
|
|
return stripped not in NO_HYPHENATE
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def split_paragraph(s):
|
|
|
|
"Split paragraph into words; tuned for Tor."
|
|
|
|
|
|
|
|
r = []
|
|
|
|
for word in s.split():
|
2014-10-19 18:59:17 +02:00
|
|
|
if hyphenatable(word):
|
2014-05-02 18:50:23 +02:00
|
|
|
while "-" in word:
|
|
|
|
a,word = word.split("-",1)
|
|
|
|
r.append(a+"\xff")
|
|
|
|
r.append(word)
|
|
|
|
return r
|
|
|
|
|
|
|
|
def fill(text, width, initial_indent, subsequent_indent):
|
|
|
|
words = split_paragraph(text)
|
|
|
|
lines = wrap_graf(words, len(initial_indent), len(subsequent_indent),
|
|
|
|
width)
|
|
|
|
res = [ initial_indent, lines[0], "\n" ]
|
|
|
|
for line in lines[1:]:
|
|
|
|
res.append(subsequent_indent)
|
|
|
|
res.append(line)
|
|
|
|
res.append("\n")
|
|
|
|
return "".join(res)
|
|
|
|
|
|
|
|
# ==============================
|
|
|
|
|
2014-04-24 19:44:24 +02:00
|
|
|
|
|
|
|
TP_MAINHEAD = 0
|
|
|
|
TP_HEADTEXT = 1
|
|
|
|
TP_BLANK = 2
|
|
|
|
TP_SECHEAD = 3
|
|
|
|
TP_ITEMFIRST = 4
|
|
|
|
TP_ITEMBODY = 5
|
2014-04-25 08:43:19 +02:00
|
|
|
TP_END = 6
|
2014-10-19 17:47:16 +02:00
|
|
|
TP_PREHEAD = 7
|
2014-04-24 19:44:24 +02:00
|
|
|
|
|
|
|
def head_parser(line):
|
2014-10-19 17:47:16 +02:00
|
|
|
if re.match(r'^Changes in', line):
|
2014-04-24 19:44:24 +02:00
|
|
|
return TP_MAINHEAD
|
2014-10-19 17:47:16 +02:00
|
|
|
elif re.match(r'^[A-Za-z]', line):
|
|
|
|
return TP_PREHEAD
|
2014-04-24 19:44:24 +02:00
|
|
|
elif re.match(r'^ o ', line):
|
|
|
|
return TP_SECHEAD
|
|
|
|
elif re.match(r'^\s*$', line):
|
|
|
|
return TP_BLANK
|
|
|
|
else:
|
|
|
|
return TP_HEADTEXT
|
|
|
|
|
|
|
|
def body_parser(line):
|
|
|
|
if re.match(r'^ o ', line):
|
|
|
|
return TP_SECHEAD
|
|
|
|
elif re.match(r'^ -',line):
|
|
|
|
return TP_ITEMFIRST
|
|
|
|
elif re.match(r'^ \S', line):
|
|
|
|
return TP_ITEMBODY
|
|
|
|
elif re.match(r'^\s*$', line):
|
|
|
|
return TP_BLANK
|
2014-04-25 08:43:19 +02:00
|
|
|
elif re.match(r'^Changes in', line):
|
|
|
|
return TP_END
|
2014-10-19 17:47:16 +02:00
|
|
|
elif re.match(r'^\s+\S', line):
|
|
|
|
return TP_HEADTEXT
|
2014-04-24 19:44:24 +02:00
|
|
|
else:
|
2019-12-09 16:53:48 +01:00
|
|
|
print("Weird line %r"%line, file=sys.stderr)
|
2014-04-24 19:44:24 +02:00
|
|
|
|
2014-10-19 18:44:19 +02:00
|
|
|
def clean_head(head):
|
|
|
|
return head
|
|
|
|
|
|
|
|
def head_score(s):
|
|
|
|
m = re.match(r'^ +o (.*)', s)
|
|
|
|
if not m:
|
2019-12-09 16:53:48 +01:00
|
|
|
print("Can't score %r"%s, file=sys.stderr)
|
2014-10-19 18:44:19 +02:00
|
|
|
return 99999
|
|
|
|
lw = m.group(1).lower()
|
|
|
|
if lw.startswith("security") and "feature" not in lw:
|
|
|
|
score = -300
|
2014-10-29 15:19:10 +01:00
|
|
|
elif lw.startswith("deprecated version"):
|
2014-10-19 18:44:19 +02:00
|
|
|
score = -200
|
2017-02-28 16:12:17 +01:00
|
|
|
elif lw.startswith("directory auth"):
|
|
|
|
score = -150
|
2014-10-29 15:19:10 +01:00
|
|
|
elif (('new' in lw and 'requirement' in lw) or
|
|
|
|
('new' in lw and 'dependenc' in lw) or
|
|
|
|
('build' in lw and 'requirement' in lw) or
|
|
|
|
('removed' in lw and 'platform' in lw)):
|
2014-10-19 18:44:19 +02:00
|
|
|
score = -100
|
|
|
|
elif lw.startswith("major feature"):
|
|
|
|
score = 00
|
|
|
|
elif lw.startswith("major bug"):
|
|
|
|
score = 50
|
|
|
|
elif lw.startswith("major"):
|
|
|
|
score = 70
|
|
|
|
elif lw.startswith("minor feature"):
|
|
|
|
score = 200
|
|
|
|
elif lw.startswith("minor bug"):
|
|
|
|
score = 250
|
|
|
|
elif lw.startswith("minor"):
|
|
|
|
score = 270
|
|
|
|
else:
|
|
|
|
score = 1000
|
|
|
|
|
|
|
|
if 'secur' in lw:
|
|
|
|
score -= 2
|
|
|
|
|
|
|
|
if "(other)" in lw:
|
|
|
|
score += 2
|
|
|
|
|
|
|
|
if '(' not in lw:
|
|
|
|
score -= 1
|
|
|
|
|
|
|
|
return score
|
|
|
|
|
2014-04-24 19:44:24 +02:00
|
|
|
class ChangeLog(object):
|
2014-10-30 22:08:42 +01:00
|
|
|
def __init__(self, wrapText=True, blogOrder=True, drupalBreak=False):
|
2014-10-19 17:47:16 +02:00
|
|
|
self.prehead = []
|
2014-04-24 19:44:24 +02:00
|
|
|
self.mainhead = None
|
|
|
|
self.headtext = []
|
|
|
|
self.curgraf = None
|
|
|
|
self.sections = []
|
|
|
|
self.cursection = None
|
|
|
|
self.lineno = 0
|
2014-10-19 18:44:19 +02:00
|
|
|
self.wrapText = wrapText
|
2014-10-27 15:32:25 +01:00
|
|
|
self.blogOrder = blogOrder
|
2014-10-30 22:08:42 +01:00
|
|
|
self.drupalBreak = drupalBreak
|
2014-04-24 19:44:24 +02:00
|
|
|
|
|
|
|
def addLine(self, tp, line):
|
|
|
|
self.lineno += 1
|
|
|
|
|
|
|
|
if tp == TP_MAINHEAD:
|
|
|
|
assert not self.mainhead
|
|
|
|
self.mainhead = line
|
|
|
|
|
2014-10-19 17:47:16 +02:00
|
|
|
elif tp == TP_PREHEAD:
|
|
|
|
self.prehead.append(line)
|
|
|
|
|
2014-04-24 19:44:24 +02:00
|
|
|
elif tp == TP_HEADTEXT:
|
|
|
|
if self.curgraf is None:
|
|
|
|
self.curgraf = []
|
|
|
|
self.headtext.append(self.curgraf)
|
|
|
|
self.curgraf.append(line)
|
|
|
|
|
|
|
|
elif tp == TP_BLANK:
|
|
|
|
self.curgraf = None
|
|
|
|
|
|
|
|
elif tp == TP_SECHEAD:
|
|
|
|
self.cursection = [ self.lineno, line, [] ]
|
|
|
|
self.sections.append(self.cursection)
|
|
|
|
|
|
|
|
elif tp == TP_ITEMFIRST:
|
|
|
|
item = ( self.lineno, [ [line] ])
|
|
|
|
self.curgraf = item[1][0]
|
|
|
|
self.cursection[2].append(item)
|
|
|
|
|
|
|
|
elif tp == TP_ITEMBODY:
|
|
|
|
if self.curgraf is None:
|
|
|
|
self.curgraf = []
|
2014-05-29 17:30:15 +02:00
|
|
|
self.cursection[2][-1][1].append(self.curgraf)
|
2014-04-24 19:44:24 +02:00
|
|
|
self.curgraf.append(line)
|
|
|
|
|
|
|
|
else:
|
|
|
|
assert "This" is "unreachable"
|
|
|
|
|
|
|
|
def lint_head(self, line, head):
|
|
|
|
m = re.match(r'^ *o ([^\(]+)((?:\([^\)]+\))?):', head)
|
|
|
|
if not m:
|
2019-12-09 16:53:48 +01:00
|
|
|
print("Weird header format on line %s"%line, file=sys.stderr)
|
2014-04-24 19:44:24 +02:00
|
|
|
|
|
|
|
def lint_item(self, line, grafs, head_type):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def lint(self):
|
|
|
|
self.head_lines = {}
|
|
|
|
for sec_line, sec_head, items in self.sections:
|
|
|
|
head_type = self.lint_head(sec_line, sec_head)
|
|
|
|
for item_line, grafs in items:
|
|
|
|
self.lint_item(item_line, grafs, head_type)
|
|
|
|
|
|
|
|
def dumpGraf(self,par,indent1,indent2=-1):
|
2014-10-19 18:44:19 +02:00
|
|
|
if not self.wrapText:
|
|
|
|
for line in par:
|
2019-12-09 16:53:48 +01:00
|
|
|
print(line)
|
2014-10-19 18:44:19 +02:00
|
|
|
return
|
|
|
|
|
2014-04-24 19:44:24 +02:00
|
|
|
if indent2 == -1:
|
|
|
|
indent2 = indent1
|
|
|
|
text = " ".join(re.sub(r'\s+', ' ', line.strip()) for line in par)
|
2014-05-02 18:50:23 +02:00
|
|
|
|
|
|
|
sys.stdout.write(fill(text,
|
|
|
|
width=72,
|
|
|
|
initial_indent=" "*indent1,
|
|
|
|
subsequent_indent=" "*indent2))
|
2014-04-24 19:44:24 +02:00
|
|
|
|
2014-10-27 15:32:25 +01:00
|
|
|
def dumpPreheader(self, graf):
|
|
|
|
self.dumpGraf(graf, 0)
|
2019-12-09 16:53:48 +01:00
|
|
|
print()
|
2014-10-27 15:32:25 +01:00
|
|
|
|
|
|
|
def dumpMainhead(self, head):
|
2019-12-09 16:53:48 +01:00
|
|
|
print(head)
|
2014-10-27 15:32:25 +01:00
|
|
|
|
|
|
|
def dumpHeadGraf(self, graf):
|
|
|
|
self.dumpGraf(graf, 2)
|
2019-12-09 16:53:48 +01:00
|
|
|
print()
|
2014-10-27 15:32:25 +01:00
|
|
|
|
|
|
|
def dumpSectionHeader(self, header):
|
2019-12-09 16:53:48 +01:00
|
|
|
print(header)
|
2014-10-27 15:32:25 +01:00
|
|
|
|
|
|
|
def dumpStartOfSections(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def dumpEndOfSections(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def dumpEndOfSection(self):
|
2019-12-09 16:53:48 +01:00
|
|
|
print()
|
2014-10-27 15:32:25 +01:00
|
|
|
|
|
|
|
def dumpEndOfChangelog(self):
|
2019-12-09 16:53:48 +01:00
|
|
|
print()
|
2014-10-27 15:32:25 +01:00
|
|
|
|
2014-10-30 22:08:42 +01:00
|
|
|
def dumpDrupalBreak(self):
|
|
|
|
pass
|
|
|
|
|
2014-10-27 15:32:25 +01:00
|
|
|
def dumpItem(self, grafs):
|
|
|
|
self.dumpGraf(grafs[0],4,6)
|
|
|
|
for par in grafs[1:]:
|
2019-12-09 16:53:48 +01:00
|
|
|
print()
|
2014-10-27 15:32:25 +01:00
|
|
|
self.dumpGraf(par,6,6)
|
|
|
|
|
2014-10-19 18:44:19 +02:00
|
|
|
def collateAndSortSections(self):
|
|
|
|
heads = []
|
|
|
|
sectionsByHead = { }
|
|
|
|
for _, head, items in self.sections:
|
|
|
|
head = clean_head(head)
|
|
|
|
try:
|
|
|
|
s = sectionsByHead[head]
|
|
|
|
except KeyError:
|
|
|
|
s = sectionsByHead[head] = []
|
2014-10-19 20:19:22 +02:00
|
|
|
heads.append( (head_score(head), head.lower(), head, s) )
|
2014-10-19 18:44:19 +02:00
|
|
|
|
|
|
|
s.extend(items)
|
|
|
|
|
|
|
|
heads.sort()
|
2014-10-19 20:19:22 +02:00
|
|
|
self.sections = [ (0, head, items) for _1,_2,head,items in heads ]
|
2014-10-19 18:44:19 +02:00
|
|
|
|
2014-04-24 19:44:24 +02:00
|
|
|
def dump(self):
|
2014-10-19 17:47:16 +02:00
|
|
|
if self.prehead:
|
2014-10-27 15:32:25 +01:00
|
|
|
self.dumpPreheader(self.prehead)
|
|
|
|
|
|
|
|
if not self.blogOrder:
|
|
|
|
self.dumpMainhead(self.mainhead)
|
|
|
|
|
2014-04-24 19:44:24 +02:00
|
|
|
for par in self.headtext:
|
2014-10-27 15:32:25 +01:00
|
|
|
self.dumpHeadGraf(par)
|
|
|
|
|
|
|
|
if self.blogOrder:
|
|
|
|
self.dumpMainhead(self.mainhead)
|
|
|
|
|
2014-10-30 22:08:42 +01:00
|
|
|
drupalBreakAfter = None
|
|
|
|
if self.drupalBreak and len(self.sections) > 4:
|
|
|
|
drupalBreakAfter = self.sections[1][2]
|
|
|
|
|
2014-10-27 15:32:25 +01:00
|
|
|
self.dumpStartOfSections()
|
2014-04-24 19:44:24 +02:00
|
|
|
for _,head,items in self.sections:
|
|
|
|
if not head.endswith(':'):
|
2019-12-09 16:53:48 +01:00
|
|
|
print("adding : to %r"%head, file=sys.stderr)
|
2014-04-24 19:44:24 +02:00
|
|
|
head = head + ":"
|
2014-10-27 15:32:25 +01:00
|
|
|
self.dumpSectionHeader(head)
|
2014-04-24 19:44:24 +02:00
|
|
|
for _,grafs in items:
|
2014-10-27 15:32:25 +01:00
|
|
|
self.dumpItem(grafs)
|
|
|
|
self.dumpEndOfSection()
|
2014-10-30 22:08:42 +01:00
|
|
|
if items is drupalBreakAfter:
|
|
|
|
self.dumpDrupalBreak()
|
2014-10-27 15:32:25 +01:00
|
|
|
self.dumpEndOfSections()
|
|
|
|
self.dumpEndOfChangelog()
|
|
|
|
|
2016-05-27 15:26:08 +02:00
|
|
|
# Let's turn bugs to html.
|
2019-01-18 16:15:02 +01:00
|
|
|
BUG_PAT = re.compile('(bug|ticket|issue|feature)\s+(\d{4,5})', re.I)
|
2016-05-27 15:26:08 +02:00
|
|
|
def bug_html(m):
|
2016-05-27 21:11:11 +02:00
|
|
|
return "%s <a href='https://bugs.torproject.org/%s'>%s</a>" % (m.group(1), m.group(2), m.group(2))
|
2016-05-27 15:26:08 +02:00
|
|
|
|
2014-10-27 15:32:25 +01:00
|
|
|
class HTMLChangeLog(ChangeLog):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
ChangeLog.__init__(self, *args, **kwargs)
|
|
|
|
|
|
|
|
def htmlText(self, graf):
|
2016-05-27 15:26:08 +02:00
|
|
|
output = []
|
2014-10-27 15:32:25 +01:00
|
|
|
for line in graf:
|
|
|
|
line = line.rstrip().replace("&","&")
|
|
|
|
line = line.rstrip().replace("<","<").replace(">",">")
|
2016-05-27 15:26:08 +02:00
|
|
|
output.append(line.strip())
|
|
|
|
output = " ".join(output)
|
|
|
|
output = BUG_PAT.sub(bug_html, output)
|
|
|
|
sys.stdout.write(output)
|
2014-10-27 15:32:25 +01:00
|
|
|
|
|
|
|
def htmlPar(self, graf):
|
|
|
|
sys.stdout.write("<p>")
|
|
|
|
self.htmlText(graf)
|
|
|
|
sys.stdout.write("</p>\n")
|
|
|
|
|
|
|
|
def dumpPreheader(self, graf):
|
|
|
|
self.htmlPar(graf)
|
|
|
|
|
|
|
|
def dumpMainhead(self, head):
|
|
|
|
sys.stdout.write("<h2>%s</h2>"%head)
|
|
|
|
|
|
|
|
def dumpHeadGraf(self, graf):
|
|
|
|
self.htmlPar(graf)
|
|
|
|
|
|
|
|
def dumpSectionHeader(self, header):
|
|
|
|
header = header.replace(" o ", "", 1).lstrip()
|
|
|
|
sys.stdout.write(" <li>%s\n"%header)
|
|
|
|
sys.stdout.write(" <ul>\n")
|
|
|
|
|
|
|
|
def dumpEndOfSection(self):
|
|
|
|
sys.stdout.write(" </ul>\n\n")
|
|
|
|
|
|
|
|
def dumpEndOfChangelog(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def dumpStartOfSections(self):
|
2019-12-09 16:53:48 +01:00
|
|
|
print("<ul>\n")
|
2014-10-27 15:32:25 +01:00
|
|
|
|
|
|
|
def dumpEndOfSections(self):
|
2019-12-09 16:53:48 +01:00
|
|
|
print("</ul>\n")
|
2014-10-27 15:32:25 +01:00
|
|
|
|
2014-10-30 22:08:42 +01:00
|
|
|
def dumpDrupalBreak(self):
|
2019-12-09 16:53:48 +01:00
|
|
|
print("\n</ul>\n")
|
|
|
|
print("<p> </p>")
|
|
|
|
print("\n<!--break-->\n\n")
|
|
|
|
print("<ul>")
|
2014-10-30 22:08:42 +01:00
|
|
|
|
2014-10-27 15:32:25 +01:00
|
|
|
def dumpItem(self, grafs):
|
|
|
|
grafs[0][0] = grafs[0][0].replace(" - ", "", 1).lstrip()
|
|
|
|
sys.stdout.write(" <li>")
|
|
|
|
if len(grafs) > 1:
|
|
|
|
for par in grafs:
|
|
|
|
self.htmlPar(par)
|
|
|
|
else:
|
|
|
|
self.htmlText(grafs[0])
|
2019-12-09 16:53:48 +01:00
|
|
|
print()
|
2014-04-24 19:44:24 +02:00
|
|
|
|
2014-10-19 18:44:19 +02:00
|
|
|
op = optparse.OptionParser(usage="usage: %prog [options] [filename]")
|
|
|
|
op.add_option('-W', '--no-wrap', action='store_false',
|
|
|
|
dest='wrapText', default=True,
|
|
|
|
help='Do not re-wrap paragraphs')
|
|
|
|
op.add_option('-S', '--no-sort', action='store_false',
|
|
|
|
dest='sort', default=True,
|
|
|
|
help='Do not sort or collate sections')
|
|
|
|
op.add_option('-o', '--output', dest='output',
|
2014-10-30 21:54:10 +01:00
|
|
|
default='-', metavar='FILE', help="write output to FILE")
|
2014-10-27 15:32:25 +01:00
|
|
|
op.add_option('-H', '--html', action='store_true',
|
|
|
|
dest='html', default=False,
|
|
|
|
help="generate an HTML fragment")
|
|
|
|
op.add_option('-1', '--first', action='store_true',
|
|
|
|
dest='firstOnly', default=False,
|
|
|
|
help="write only the first section")
|
2014-10-30 21:54:10 +01:00
|
|
|
op.add_option('-b', '--blog-header', action='store_true',
|
2014-10-27 15:32:25 +01:00
|
|
|
dest='blogOrder', default=False,
|
|
|
|
help="Write the header in blog order")
|
2014-10-30 21:54:10 +01:00
|
|
|
op.add_option('-B', '--blog', action='store_true',
|
|
|
|
dest='blogFormat', default=False,
|
|
|
|
help="Set all other options as appropriate for a blog post")
|
|
|
|
op.add_option('--inplace', action='store_true',
|
|
|
|
dest='inplace', default=False,
|
|
|
|
help="Alter the ChangeLog in place")
|
2014-10-30 22:08:42 +01:00
|
|
|
op.add_option('--drupal-break', action='store_true',
|
|
|
|
dest='drupalBreak', default=False,
|
|
|
|
help='Insert a drupal-friendly <!--break--> as needed')
|
2014-10-19 18:44:19 +02:00
|
|
|
|
|
|
|
options,args = op.parse_args()
|
|
|
|
|
2014-10-30 21:54:10 +01:00
|
|
|
if options.blogFormat:
|
|
|
|
options.blogOrder = True
|
|
|
|
options.html = True
|
|
|
|
options.sort = False
|
|
|
|
options.wrapText = False
|
|
|
|
options.firstOnly = True
|
2014-10-30 22:08:42 +01:00
|
|
|
options.drupalBreak = True
|
2014-10-30 21:54:10 +01:00
|
|
|
|
2014-10-19 18:44:19 +02:00
|
|
|
if len(args) > 1:
|
|
|
|
op.error("Too many arguments")
|
|
|
|
elif len(args) == 0:
|
2014-06-16 21:00:10 +02:00
|
|
|
fname = 'ChangeLog'
|
|
|
|
else:
|
2014-10-19 18:44:19 +02:00
|
|
|
fname = args[0]
|
2014-06-16 21:00:10 +02:00
|
|
|
|
2014-10-30 21:54:10 +01:00
|
|
|
if options.inplace:
|
|
|
|
assert options.output == '-'
|
2014-10-19 18:44:19 +02:00
|
|
|
options.output = fname
|
2014-06-16 21:00:10 +02:00
|
|
|
|
2014-10-19 18:44:19 +02:00
|
|
|
if fname != '-':
|
|
|
|
sys.stdin = open(fname, 'r')
|
2014-06-16 21:00:10 +02:00
|
|
|
|
|
|
|
nextline = None
|
2014-04-25 08:43:19 +02:00
|
|
|
|
2014-10-27 15:32:25 +01:00
|
|
|
if options.html:
|
|
|
|
ChangeLogClass = HTMLChangeLog
|
|
|
|
else:
|
|
|
|
ChangeLogClass = ChangeLog
|
|
|
|
|
2014-10-30 22:08:42 +01:00
|
|
|
CL = ChangeLogClass(wrapText=options.wrapText,
|
|
|
|
blogOrder=options.blogOrder,
|
|
|
|
drupalBreak=options.drupalBreak)
|
2014-10-19 18:44:19 +02:00
|
|
|
parser = head_parser
|
|
|
|
|
2014-04-24 19:44:24 +02:00
|
|
|
for line in sys.stdin:
|
|
|
|
line = line.rstrip()
|
|
|
|
tp = parser(line)
|
|
|
|
|
|
|
|
if tp == TP_SECHEAD:
|
|
|
|
parser = body_parser
|
2014-04-25 08:43:19 +02:00
|
|
|
elif tp == TP_END:
|
|
|
|
nextline = line
|
|
|
|
break
|
|
|
|
|
|
|
|
CL.addLine(tp,line)
|
2014-04-24 19:44:24 +02:00
|
|
|
|
|
|
|
CL.lint()
|
2014-04-25 08:43:19 +02:00
|
|
|
|
2014-10-19 18:44:19 +02:00
|
|
|
if options.output != '-':
|
|
|
|
fname_new = options.output+".new"
|
|
|
|
fname_out = options.output
|
|
|
|
sys.stdout = open(fname_new, 'w')
|
|
|
|
else:
|
|
|
|
fname_new = fname_out = None
|
|
|
|
|
|
|
|
if options.sort:
|
|
|
|
CL.collateAndSortSections()
|
2014-04-25 08:43:19 +02:00
|
|
|
|
2014-04-24 19:44:24 +02:00
|
|
|
CL.dump()
|
2014-04-25 08:43:19 +02:00
|
|
|
|
2014-10-27 15:32:25 +01:00
|
|
|
if options.firstOnly:
|
|
|
|
sys.exit(0)
|
|
|
|
|
2014-06-16 21:00:10 +02:00
|
|
|
if nextline is not None:
|
2019-12-09 16:53:48 +01:00
|
|
|
print(nextline)
|
2014-04-25 08:43:19 +02:00
|
|
|
|
|
|
|
for line in sys.stdin:
|
|
|
|
sys.stdout.write(line)
|
|
|
|
|
2014-10-19 18:44:19 +02:00
|
|
|
if fname_new is not None:
|
|
|
|
os.rename(fname_new, fname_out)
|