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\)\*$")
41 # Ensure "C" locale is used
42 curlocale = locale.getlocale()
43 if curlocale != (None, None):
44 raise Exception("Invalid locale %s" % curlocale)
49 for line in fileinput.input():
50 line = line.rstrip("\n")
52 if DASHES_RE.match(line):
53 if not prevline.startswith("Version "):
54 raise Exception("Line %s: Invalid title" % (fileinput.lineno() - 1))
62 if UNRELEASED_RE.match(line):
63 # Ignore unreleased versions
67 m = RELEASED_RE.match(line)
69 raise Exception("Line %s: Invalid release line" % fileinput.lineno())
71 # Including the weekday in the date string does not work as time.strptime
72 # would return an inconsistent result if the weekday is incorrect.
73 parsed_ts = time.mktime(time.strptime(m.group("date"), "%d %b %Y"))
74 parsed = datetime.date.fromtimestamp(parsed_ts)
75 weekday = parsed.strftime("%a")
78 if m.group("day") != weekday:
79 raise Exception("Line %s: %s was/is a %s, not %s" %
80 (fileinput.lineno(), parsed, weekday, m.group("day")))
89 if __name__ == "__main__":