Yun Peng | a50635d | 2016-07-26 13:29:03 +0000 | [diff] [blame] | 1 | # pylint: disable=g-bad-file-header |
| 2 | # Copyright 2015 The Bazel Authors. All rights reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | """This tool convert Bazel's changelog file to debian changelog format.""" |
| 16 | |
| 17 | from datetime import datetime |
| 18 | import sys |
| 19 | |
| 20 | |
Damien Martin-Guillerez | 332b61f | 2016-12-20 07:47:35 +0000 | [diff] [blame] | 21 | def main(input_file, changelog_file, output_file): |
Yun Peng | a50635d | 2016-07-26 13:29:03 +0000 | [diff] [blame] | 22 | changelog_out = open(output_file, "w") |
Damien Martin-Guillerez | 332b61f | 2016-12-20 07:47:35 +0000 | [diff] [blame] | 23 | changelog = None |
| 24 | version = None |
| 25 | with open(input_file, "r") as status_file: |
| 26 | for line in status_file: |
Yun Peng | a50635d | 2016-07-26 13:29:03 +0000 | [diff] [blame] | 27 | line = line.strip() |
| 28 | |
Damien Martin-Guillerez | 332b61f | 2016-12-20 07:47:35 +0000 | [diff] [blame] | 29 | if line.startswith("RELEASE_NOTES"): |
| 30 | changelog = line[14:].strip().replace("\f", "\n") |
| 31 | elif line.startswith("RELEASE_NAME"): |
| 32 | version = line[13:].strip() |
Yun Peng | a50635d | 2016-07-26 13:29:03 +0000 | [diff] [blame] | 33 | |
Damien Martin-Guillerez | 332b61f | 2016-12-20 07:47:35 +0000 | [diff] [blame] | 34 | if changelog: |
| 35 | time_stamp = None |
| 36 | lines = changelog.split("\n") |
| 37 | header = lines[0] |
| 38 | lines = lines[4:] # Skip the header |
| 39 | if lines[0] == "Cherry picks:": |
| 40 | # Skip cherry picks list |
| 41 | i = 1 |
| 42 | while lines[i].strip(): |
| 43 | i += 1 |
| 44 | lines = lines[i + 1:] |
Yun Peng | a50635d | 2016-07-26 13:29:03 +0000 | [diff] [blame] | 45 | |
Damien Martin-Guillerez | 332b61f | 2016-12-20 07:47:35 +0000 | [diff] [blame] | 46 | # Process header |
| 47 | parts = header.split(" ") |
| 48 | time_stamp = datetime.strptime( |
| 49 | parts[2], "(%Y-%m-%d)").strftime("%a, %d %b %Y %H:%M:%S +0100") |
| 50 | changelog_out.write("bazel (%s) unstable; urgency=low\n" % version) |
| 51 | |
| 52 | for line in lines: |
| 53 | if line.startswith("+") or line.startswith("-"): |
Yun Peng | a50635d | 2016-07-26 13:29:03 +0000 | [diff] [blame] | 54 | parts = line.split(" ") |
| 55 | line = "*" + line[1:] |
| 56 | changelog_out.write(" %s\n" % line) |
| 57 | |
| 58 | elif line.endswith(":"): |
| 59 | changelog_out.write("\n %s\n" % line) |
| 60 | |
| 61 | elif line: |
| 62 | changelog_out.write(" %s\n" % line) |
| 63 | |
| 64 | if time_stamp: |
| 65 | changelog_out.write( |
| 66 | "\n -- The Bazel Authors <bazel-dev@googlegroups.com> %s\n\n" % |
| 67 | time_stamp) |
Damien Martin-Guillerez | 332b61f | 2016-12-20 07:47:35 +0000 | [diff] [blame] | 68 | else: |
| 69 | # Develeopment version, generate a changelog from the change log file |
| 70 | with open(changelog_file, "r") as changelog_in: |
| 71 | for line in changelog_in: |
| 72 | line = line.strip() |
| 73 | if line.startswith("## Release"): |
| 74 | parts = line.split(" ") |
| 75 | version = parts[2] |
| 76 | time_stamp = datetime.strptime( |
| 77 | parts[3], "(%Y-%m-%d)").strftime("%a, %d %b %Y %H:%M:%S +0100") |
| 78 | changelog_out.write("bazel (%s~HEAD) unstable; urgency=low\n" % |
| 79 | version) |
| 80 | changelog_out.write(" Development version\n") |
| 81 | changelog_out.write( |
| 82 | "\n -- The Bazel Authors <bazel-dev@googlegroups.com> %s\n\n" % |
| 83 | time_stamp) |
| 84 | # Stop after parsing latest release |
| 85 | return |
Yun Peng | a50635d | 2016-07-26 13:29:03 +0000 | [diff] [blame] | 86 | |
John Cater | b0308d4 | 2017-01-30 17:49:26 +0000 | [diff] [blame] | 87 | |
Yun Peng | a50635d | 2016-07-26 13:29:03 +0000 | [diff] [blame] | 88 | if __name__ == "__main__": |
Damien Martin-Guillerez | 332b61f | 2016-12-20 07:47:35 +0000 | [diff] [blame] | 89 | main(sys.argv[1], sys.argv[2], sys.argv[3]) |