Move disk template unit tests to test/py/cmdlib/
[ganeti-local] / autotools / check-news
index 146faf2..1405b58 100755 (executable)
@@ -32,13 +32,14 @@ import datetime
 import locale
 import fileinput
 import re
+import os
 
 
 DASHES_RE = re.compile(r"^\s*-+\s*$")
 RELEASED_RE = re.compile(r"^\*\(Released (?P<day>[A-Z][a-z]{2}),"
                          r" (?P<date>.+)\)\*$")
 UNRELEASED_RE = re.compile(r"^\*\(unreleased\)\*$")
-VERSION_RE = re.compile(r"^Version \d+(\.\d+)+( (beta|rc)\d+)?$")
+VERSION_RE = re.compile(r"^Version (\d+(\.\d+)+( (alpha|beta|rc)\d+)?)$")
 
 #: How many days release timestamps may be in the future
 TIMESTAMP_FUTURE_DAYS_MAX = 3
@@ -54,7 +55,7 @@ def Error(msg):
 
 
 def ReqNLines(req, count_empty, lineno, line):
-  """Check if we have N empty lines.
+  """Check if we have N empty lines before the current one.
 
   """
   if count_empty < req:
@@ -67,23 +68,57 @@ def ReqNLines(req, count_empty, lineno, line):
           (lineno, line, req, count_empty))
 
 
+def IsAlphaVersion(version):
+  return "alpha" in version
+
+
+def UpdateAllowUnreleased(allow_unreleased, version_match, release):
+  if not allow_unreleased:
+    return False
+  if IsAlphaVersion(release):
+    return True
+  version = version_match.group(1)
+  if version == release:
+    return False
+  return True
+
+
 def main():
   # Ensure "C" locale is used
   curlocale = locale.getlocale()
   if curlocale != (None, None):
     Error("Invalid locale %s" % curlocale)
 
+  # Get the release version, but replace "~" with " " as the version
+  # in the NEWS file uses spaces for beta and rc releases.
+  release = os.environ.get('RELEASE', "").replace("~", " ")
+
   prevline = None
   expect_date = False
   count_empty = 0
+  allow_unreleased = True
+  found_versions = set()
 
   for line in fileinput.input():
     line = line.rstrip("\n")
 
-    if VERSION_RE.match(line):
+    version_match = VERSION_RE.match(line)
+    if version_match:
       ReqNLines(2, count_empty, fileinput.filelineno(), line)
-
-    if UNRELEASED_RE.match(line) or RELEASED_RE.match(line):
+      version = version_match.group(1)
+      if version in found_versions:
+        Error("Line %s: Duplicate release %s found" %
+              (fileinput.filelineno(), version))
+      found_versions.add(version)
+      allow_unreleased = UpdateAllowUnreleased(allow_unreleased, version_match,
+                                               release)
+
+    unreleased_match = UNRELEASED_RE.match(line)
+    if unreleased_match and not allow_unreleased:
+      Error("Line %s: Unreleased version after current release %s" %
+            (fileinput.filelineno(), release))
+
+    if unreleased_match or RELEASED_RE.match(line):
       ReqNLines(1, count_empty, fileinput.filelineno(), line)
 
     if line:
@@ -113,6 +148,8 @@ def main():
       m = RELEASED_RE.match(line)
       if not m:
         Error("Line %s: Invalid release line" % fileinput.filelineno())
+        expect_date = False
+        continue
 
       # Including the weekday in the date string does not work as time.strptime
       # would return an inconsistent result if the weekday is incorrect.