rpc: Use definitions directly instead of via generated code
[ganeti-local] / autotools / check-news
1 #!/usr/bin/python
2 #
3
4 # Copyright (C) 2011 Google Inc.
5 #
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.
10 #
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.
15 #
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
19 # 02110-1301, USA.
20
21
22 """Script to check NEWS file.
23
24 """
25
26 import sys
27 import time
28 import datetime
29 import locale
30 import fileinput
31 import re
32
33
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
39
40 def main():
41   # Ensure "C" locale is used
42   curlocale = locale.getlocale()
43   if curlocale != (None, None):
44     raise Exception("Invalid locale %s" % curlocale)
45
46   prevline = None
47   expect_date = False
48
49   for line in fileinput.input():
50     line = line.rstrip("\n")
51
52     if DASHES_RE.match(line):
53       if not prevline.startswith("Version "):
54         raise Exception("Line %s: Invalid title" % (fileinput.filelineno() - 1))
55       expect_date = True
56
57     elif expect_date:
58       if not line:
59         # Ignore empty lines
60         continue
61
62       if UNRELEASED_RE.match(line):
63         # Ignore unreleased versions
64         expect_date = False
65         continue
66
67       m = RELEASED_RE.match(line)
68       if not m:
69         raise Exception("Line %s: Invalid release line" %
70                         fileinput.filelineno())
71
72       # Including the weekday in the date string does not work as time.strptime
73       # would return an inconsistent result if the weekday is incorrect.
74       parsed_ts = time.mktime(time.strptime(m.group("date"), "%d %b %Y"))
75       parsed = datetime.date.fromtimestamp(parsed_ts)
76       weekday = parsed.strftime("%a")
77
78       # Check weekday
79       if m.group("day") != weekday:
80         raise Exception("Line %s: %s was/is a %s, not %s" %
81                         (fileinput.filelineno(), parsed, weekday,
82                          m.group("day")))
83
84       expect_date = False
85
86     prevline = line
87
88   sys.exit(0)
89
90
91 if __name__ == "__main__":
92   main()