Updated Hungarian translation
[empathy-mirror.git] / tools / make-release-mail.py
blobb03ebd25618c0868011ab8224b8cf47c2bb319f2
1 #!/usr/bin/env python
2 # vim: set fileencoding=utf-8 :
4 # Hello. This is make-release-mail.py from the Telepathy project. It's
5 # designed to turn an item from a NEWS file into a mail suitable for sending
6 # to <telepathy@lists.freedesktop.org>. I hope that you enjoy your stay.
8 import sys
9 import re
11 def looks_like_a_header(line, package, version=None):
12 if version is None:
13 pattern = "^%s .* \(.*\)$" % package
14 else:
15 pattern = "^%s %s \(.*\)$" % (package, version)
17 return re.match(pattern, line) is not None
19 def extract_description(package, version, news_path):
20 release_name = []
21 details = []
23 with open(news_path) as f:
24 lines = (line for line in f.readlines())
25 for line in lines:
26 # Find the 'telepathy-foo 0.1.2' header
27 if looks_like_a_header(line, package, version):
28 break
30 # Skip the ====== line, and the first blank line
31 lines.next()
32 lines.next()
34 got_release_name = False
36 for line in lines:
37 line = line.rstrip()
38 # If we hit the next version header, we're done
39 if looks_like_a_header(line, package):
40 break
41 # Else, if we hit a blank line and we're still reading the release
42 # name, we're done with the release name.
43 elif not got_release_name and line == '':
44 got_release_name = True
45 # Otherwise, append this to the relevant list
46 elif not got_release_name:
47 release_name.append(line)
48 else:
49 details.append(line)
51 assert got_release_name, (release_name, details)
53 # We rstrip details because it picks up a trailing blank line
54 return ('\n'.join(release_name), '\n'.join(details).rstrip())
56 BASE_URL = 'http://telepathy.freedesktop.org/releases'
57 GIT_URL = 'http://cgit.freedesktop.org/telepathy'
59 def main(package, version, news_path):
60 release_name, details = extract_description(package, version, news_path)
62 print """
63 %(release_name)s
65 tarball: %(base_url)s/%(package)s/%(package)s-%(version)s.tar.gz
66 signature: %(base_url)s/%(package)s/%(package)s-%(version)s.tar.gz.asc
67 git: %(git_url)s/%(package)s
69 %(details)s""".strip().rstrip() % {
70 'base_url': BASE_URL,
71 'git_url': GIT_URL,
72 'package': package,
73 'version': version,
74 'release_name': release_name,
75 'details': details,
78 if __name__ == '__main__':
79 try:
80 package, version, news_path = sys.argv[1:]
82 main(package, version, news_path)
83 except ValueError, e:
84 sys.stderr.write(
85 'Usage: %s package-name package.version.number path/to/NEWS\n' %
86 sys.argv[0])
87 sys.stderr.flush()
88 sys.exit(1)