Revision f0fa05ac
b/autotools/check-news | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2011 Google Inc. |
|
4 |
# Copyright (C) 2011, 2012 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
23 | 23 |
|
24 | 24 |
""" |
25 | 25 |
|
26 |
# pylint: disable=C0103 |
|
27 |
# [C0103] Invalid name |
|
28 |
|
|
26 | 29 |
import sys |
27 | 30 |
import time |
28 | 31 |
import datetime |
... | ... | |
37 | 40 |
UNRELEASED_RE = re.compile(r"^\*\(unreleased\)\*$") |
38 | 41 |
VERSION_RE = re.compile(r"^Version \d+(\.\d+)+( (beta|rc)\d+)?$") |
39 | 42 |
|
43 |
errors = [] |
|
44 |
|
|
45 |
|
|
46 |
def Error(msg): |
|
47 |
"""Log an error for later display. |
|
48 |
|
|
49 |
""" |
|
50 |
errors.append(msg) |
|
51 |
|
|
52 |
|
|
53 |
def ReqNLines(req, count_empty, lineno, line): |
|
54 |
"""Check if we have N empty lines. |
|
55 |
|
|
56 |
""" |
|
57 |
if count_empty < req: |
|
58 |
Error("Line %s: Missing empty line(s) before %s," |
|
59 |
" %d needed but got only %d" % |
|
60 |
(lineno, line, req, count_empty)) |
|
61 |
if count_empty > req: |
|
62 |
Error("Line %s: Too many empty lines before %s," |
|
63 |
" %d needed but got %d" % |
|
64 |
(lineno, line, req, count_empty)) |
|
65 |
|
|
40 | 66 |
|
41 | 67 |
def main(): |
42 | 68 |
# Ensure "C" locale is used |
43 | 69 |
curlocale = locale.getlocale() |
44 | 70 |
if curlocale != (None, None): |
45 |
raise Exception("Invalid locale %s" % curlocale)
|
|
71 |
Error("Invalid locale %s" % curlocale)
|
|
46 | 72 |
|
47 | 73 |
prevline = None |
48 | 74 |
expect_date = False |
... | ... | |
52 | 78 |
line = line.rstrip("\n") |
53 | 79 |
|
54 | 80 |
if VERSION_RE.match(line): |
55 |
if count_empty != 2: |
|
56 |
raise Exception("Line %s: Missing 2 empty lines before %s" % |
|
57 |
(fileinput.filelineno(), line)) |
|
81 |
ReqNLines(2, count_empty, fileinput.filelineno(), line) |
|
58 | 82 |
|
59 | 83 |
if UNRELEASED_RE.match(line) or RELEASED_RE.match(line): |
60 |
if count_empty != 1: |
|
61 |
raise Exception("Line %s: Missing 1 empty line before %s" % |
|
62 |
(fileinput.filelineno(), line)) |
|
84 |
ReqNLines(1, count_empty, fileinput.filelineno(), line) |
|
63 | 85 |
|
64 | 86 |
if line: |
65 | 87 |
count_empty = 0 |
... | ... | |
68 | 90 |
|
69 | 91 |
if DASHES_RE.match(line): |
70 | 92 |
if not VERSION_RE.match(prevline): |
71 |
raise Exception("Line %s: Invalid title" %
|
|
72 |
(fileinput.filelineno() - 1))
|
|
93 |
Error("Line %s: Invalid title" %
|
|
94 |
(fileinput.filelineno() - 1)) |
|
73 | 95 |
if len(line) != len(prevline): |
74 |
raise Exception("Line %s: Invalid dashes length" %
|
|
75 |
(fileinput.filelineno()))
|
|
96 |
Error("Line %s: Invalid dashes length" %
|
|
97 |
(fileinput.filelineno())) |
|
76 | 98 |
expect_date = True |
77 | 99 |
|
78 | 100 |
elif expect_date: |
... | ... | |
87 | 109 |
|
88 | 110 |
m = RELEASED_RE.match(line) |
89 | 111 |
if not m: |
90 |
raise Exception("Line %s: Invalid release line" % |
|
91 |
fileinput.filelineno()) |
|
112 |
Error("Line %s: Invalid release line" % fileinput.filelineno()) |
|
92 | 113 |
|
93 | 114 |
# Including the weekday in the date string does not work as time.strptime |
94 | 115 |
# would return an inconsistent result if the weekday is incorrect. |
... | ... | |
98 | 119 |
|
99 | 120 |
# Check weekday |
100 | 121 |
if m.group("day") != weekday: |
101 |
raise Exception("Line %s: %s was/is a %s, not %s" %
|
|
102 |
(fileinput.filelineno(), parsed, weekday,
|
|
103 |
m.group("day")))
|
|
122 |
Error("Line %s: %s was/is a %s, not %s" %
|
|
123 |
(fileinput.filelineno(), parsed, weekday, |
|
124 |
m.group("day"))) |
|
104 | 125 |
|
105 | 126 |
expect_date = False |
106 | 127 |
|
107 | 128 |
prevline = line |
108 | 129 |
|
109 |
sys.exit(0) |
|
130 |
if errors: |
|
131 |
for msg in errors: |
|
132 |
print >> sys.stderr, msg |
|
133 |
sys.exit(1) |
|
134 |
else: |
|
135 |
sys.exit(0) |
|
110 | 136 |
|
111 | 137 |
|
112 | 138 |
if __name__ == "__main__": |
Also available in: Unified diff