4 # Copyright (C) 2011 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """Script to check NEWS file.
34 DASHES_RE = re.compile(r"^\s*-+\s*$")
35 RELEASED_RE = re.compile(r"^\*\(Released (?P<day>[A-Z][a-z]{2}),"
36 r" (?P<date>.+)\)\*$")
37 UNRELEASED_RE = re.compile(r"^\*\(unreleased\)\*$")
38 VERSION_RE = re.compile(r"^Version \d+(\.\d+)+( (beta|rc)\d+)?$")
42 # Ensure "C" locale is used
43 curlocale = locale.getlocale()
44 if curlocale != (None, None):
45 raise Exception("Invalid locale %s" % curlocale)
51 for line in fileinput.input():
52 line = line.rstrip("\n")
54 if VERSION_RE.match(line):
56 raise Exception("Line %s: Missing 2 empty lines before %s" %
57 (fileinput.filelineno(), line))
59 if UNRELEASED_RE.match(line) or RELEASED_RE.match(line):
61 raise Exception("Line %s: Missing 1 empty line before %s" %
62 (fileinput.filelineno(), line))
69 if DASHES_RE.match(line):
70 if not VERSION_RE.match(prevline):
71 raise Exception("Line %s: Invalid title" %
72 (fileinput.filelineno() - 1))
73 if len(line) != len(prevline):
74 raise Exception("Line %s: Invalid dashes length" %
75 (fileinput.filelineno()))
83 if UNRELEASED_RE.match(line):
84 # Ignore unreleased versions
88 m = RELEASED_RE.match(line)
90 raise Exception("Line %s: Invalid release line" %
91 fileinput.filelineno())
93 # Including the weekday in the date string does not work as time.strptime
94 # would return an inconsistent result if the weekday is incorrect.
95 parsed_ts = time.mktime(time.strptime(m.group("date"), "%d %b %Y"))
96 parsed = datetime.date.fromtimestamp(parsed_ts)
97 weekday = parsed.strftime("%a")
100 if m.group("day") != weekday:
101 raise Exception("Line %s: %s was/is a %s, not %s" %
102 (fileinput.filelineno(), parsed, weekday,
112 if __name__ == "__main__":