[gimp-web/testing] Disentangled XHTML and JSON mirrors files creation



commit 703d263e300f1f1bc6054c6c3daaf7ee6fcc0c63
Author: Michael Schumacher <schumaml gmx de>
Date:   Tue Aug 4 03:21:32 2015 +0200

    Disentangled XHTML and JSON mirrors files creation

 programmatic/downloads/Makefile          |    3 ++
 programmatic/downloads/mirrorfmt.py      |    9 -----
 programmatic/downloads/mirrorfmt_json.py |   49 ++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 9 deletions(-)
---
diff --git a/programmatic/downloads/Makefile b/programmatic/downloads/Makefile
index 61b707d..05f07df 100644
--- a/programmatic/downloads/Makefile
+++ b/programmatic/downloads/Makefile
@@ -12,6 +12,9 @@ MIRRORS: MIRRORS.in
 mirrors.xhtml: MIRRORS
        ${PYTHON} mirrorfmt.py MIRRORS > mirrors.xhtml
 
+mirrors.json:
+       ${PYTHON} mirrorfmt_json.py MIRRORS > mirrors.json
+
 clean:
        /bin/rm -f mirrors.xhtml
 
diff --git a/programmatic/downloads/mirrorfmt.py b/programmatic/downloads/mirrorfmt.py
index ea6fb9e..9a29f04 100644
--- a/programmatic/downloads/mirrorfmt.py
+++ b/programmatic/downloads/mirrorfmt.py
@@ -8,13 +8,10 @@ import string
 def do_file(filename):
 
     fp = open(filename, "r")
-    fj = open(filename + ".json", "w")
     print "<!-- This file automatically generated by mirrorfmt.py $Revision$ -->"
     print "<!-- DO NOT EDIT THIS FILE - edit the master file MIRRORS instead -->"
     print xhtml.dl.init({"class" : "download-mirror"})
 
-    print >>fj, '"mirrors_http":[\n'
-
     for l in fp:
         l = l.rstrip()
         if len(l) > 1:
@@ -31,20 +28,14 @@ def do_file(filename):
                     # split the link (before whitespace) from the comment
                     print xhtml.dd(xhtml.hyperlink(l[0:idx], {"href" : l[0:idx]})
                                    + l[idx:len(l)])
-                    if l.startswith("http"):
-                        print >>fj, '"' + l[0:idx] + '",'
                 else:
                     print xhtml.dd(xhtml.hyperlink(l, {"href" : l}))
-                    if l.startswith("http"):
-                        print >>fj, '"' + l[0:idx] + '",'
                 pass
             pass
         pass
 
-    print >>fj, "];"
     print xhtml.dl.fini()
     fp.close()
-    fj.close()
 
     return
 
diff --git a/programmatic/downloads/mirrorfmt_json.py b/programmatic/downloads/mirrorfmt_json.py
new file mode 100644
index 0000000..374e880
--- /dev/null
+++ b/programmatic/downloads/mirrorfmt_json.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env ${PYTHON}
+
+import sys
+import xhtml
+import time
+import string
+
+def do_file(filename):
+
+    fp = open(filename, "r")
+    print "<!-- This file automatically generated by mirrorfmt_json.py $Revision$ -->"
+    print "<!-- DO NOT EDIT THIS FILE - edit the master file MIRRORS.in instead -->"
+
+    print '"mirrors_http":[\n'
+
+    for l in fp:
+        l = l.rstrip()
+        if len(l) > 1:
+            if l[0] == "#":
+                pass
+            else:
+                l = l.lstrip()
+                idx = 0
+                while idx < len(l) and l[idx] not in string.whitespace:
+                    idx = idx + 1
+                if idx < len(l):
+                    # split the link (before whitespace) from the comment
+                    if l.startswith("http"):
+                        print '"' + l[0:idx] + '",'
+                else:
+                    if l.startswith("http"):
+                        print '"' + l[0:idx] + '",'
+                pass
+            pass
+        pass
+
+    print "];"
+    fp.close()
+
+    return
+
+def main(argv):
+    for a in argv:
+        do_file(a)
+        pass
+
+    return
+
+main(sys.argv[1:])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]