1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Picard, the next-generation MusicBrainz tagger
5#
6# Copyright (C) 2020 Philipp Wolfer
7#
8# This program is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License
10# as published by the Free Software Foundation; either version 2
11# of the License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22
23import re
24import sys
25
26
27if len(sys.argv) == 1:
28    print("Call with changelog-for-version.py [version]", file=sys.stderr)
29    sys.exit(1)
30
31version = sys.argv[1]
32re_changes = re.compile(r'^# Version ' + re.escape(version) + '.*?\n(.*?)# Version',
33    re.DOTALL | re.MULTILINE)
34
35with open('NEWS.md', 'r') as newsfile:
36    news = newsfile.read()
37    result = re_changes.search(news)
38    if not result:
39        print("No changelog found for version %s" % version, file=sys.stderr)
40        sys.exit(1)
41    print(result[1].strip())
42