]> granicus.if.org Git - icinga2/blobdiff - doc/update-links.py
Merge pull request #7270 from Icinga/feature/notification-after-downtime-ends-5919
[icinga2] / doc / update-links.py
index dd03ad19ba64ba93c31b8cb1b9310afed522e266..765d4a04fbd03d70a15f2dde69fd231db914f2a2 100755 (executable)
@@ -1,29 +1,14 @@
 #!/usr/bin/env python
-# Icinga 2
-# Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org)
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
 
 import os
 import sys
 import re
 
 if len(sys.argv) < 2:
-    print "Syntax: %s <md-files>"
+    print "Syntax: %s <md-files>" % sys.argv[0]
     print ""
-    print "Updates intra-chapter links in the specified Markdown files."
+    print "Updates inter-chapter links in the specified Markdown files."
     sys.exit(1)
 
 anchors = {}
@@ -34,7 +19,7 @@ for file in sys.argv[1:]:
         id = match.group("id")
 
         if id in anchors:
-            print "Anchor '%s' is used multiple times: in %s and %s" % (id, file, anchors[id])
+            print "Error: Anchor '%s' is used multiple times: in %s and %s" % (id, file, anchors[id])
 
         anchors[match.group("id")] = file
 
@@ -44,12 +29,13 @@ def update_anchor(match):
     try:
         file = os.path.basename(anchors[id])
     except KeyError:
-        print "Unmatched anchor: %s" % (id)
+        print "Error: Unmatched anchor: %s" % (id)
         file = ""
 
     return "[%s](%s#%s)" % (match.group("text"), file, id)
 
 for file in sys.argv[1:]:
     text = open(file).read()
-    new_text = re.sub(r"\[(?P<text>.*)\]\((?P<file>[0-9-[a-z]\.]+)?#(?P<id>[^#\)]+)\)", update_anchor, text)
+    print "> Processing file '%s'..." % (file)
+    new_text = re.sub(r"\[(?P<text>.*?)\]\((?P<file>[0-9-a-z\.]+)?#(?P<id>[^#\)]+)\)", update_anchor, text)
     open(file, "w").write(new_text)