mitogen/scripts/release-notes.py

48 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding=UTF-8
# Generate the fragment used to make email release announcements
# usage: release-notes.py 0.2.6
import sys
import urllib
import lxml.html
import subprocess
response = urllib.urlopen('https://mitogen.networkgenomics.com/changelog.html')
tree = lxml.html.parse(response)
prefix = 'v' + sys.argv[1].replace('.', '-')
for elem in tree.getroot().cssselect('div.section[id]'):
if elem.attrib['id'].startswith(prefix):
break
else:
print('cant find')
for child in tree.getroot().cssselect('body > *'):
child.getparent().remove(child)
body, = tree.getroot().cssselect('body')
body.append(elem)
proc = subprocess.Popen(
args=['w3m', '-T', 'text/html', '-dump', '-cols', '72'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
stdout, _ = proc.communicate(input=(lxml.html.tostring(tree)))
stdout = stdout.decode('UTF-8')
stdout = stdout.translate({
ord(u''): None,
ord(u''): ord(u'*'),
ord(u''): ord(u"'"),
ord(u''): ord(u'"'),
ord(u''): ord(u'"'),
})
print(stdout)