svn commit: samba-web r447 - in trunk/scripts: .

deryck at samba.org deryck at samba.org
Thu Dec 2 17:05:41 GMT 2004


Author: deryck
Date: 2004-12-02 17:05:36 +0000 (Thu, 02 Dec 2004)
New Revision: 447

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba-web&rev=447

Log:

Updating the script that writes mirrors list to javascript. 
news.samba.org's js redirect is now handled here.  Also, this
handles the drop-down menu options now.  In short, all of the
mirrors lists used on samba.org are created with this script
by reading web_hosts.html.

--deryck


Modified:
   trunk/scripts/js_redirect.py


Changeset:
Modified: trunk/scripts/js_redirect.py
===================================================================
--- trunk/scripts/js_redirect.py	2004-12-02 15:28:11 UTC (rev 446)
+++ trunk/scripts/js_redirect.py	2004-12-02 17:05:36 UTC (rev 447)
@@ -6,23 +6,48 @@
 
 os.chdir('/data/httpd/html/samba')
 hosts = open('web_hosts.html', 'r').readlines()
-fluff = re.compile('(<li><a href=)|(samba.html)|(>.+)|(\n)')
-urls = []
+mirrors = {}  
 
 for line in hosts:
     if line[:4] == '<li>':
-        nline = fluff.sub('', line)
-        urls.append(nline)
+        parts = re.match('<li><a href=(.*)samba.html">(.*)</a>', line)
+        # Store as url/mirror_name pairs
+        mirrors[parts.group(1)] = parts.group(2)
 
+mlist = mirrors.keys()
+mlist.sort()
+
+# For main samba.org redirect
 js = open('redirect_include.html', 'w')
 js.write('<script language="Javascript" type="text/javascript">\n')
 js.write('<!-- Hide from old browsers\n')
 js.write('randomMirror = new Array;\n')
-for i in range(len(urls)):
-    js.write('randomMirror[' + str(i) + '] = ' + urls[i] + '\n')
+for i in range(len(mlist)):
+    js.write('randomMirror[' + str(i) + '] = ' + mlist[i] + '"\n')
 js.write('\n')
-js.write('n = Math.floor(Math.random()*' + str(len(urls)) + ')\n')
+js.write('n = Math.floor(Math.random()*' + str(len(mirrors.keys())) + ')\n')
 js.write('// end hide -->\n')
 js.write('</script>')
 js.close() 
 
+# For drop-down mirror selection list
+menu = open('menu_options.html', 'w')
+for m in mlist:
+    menu.write('<option value=' + m + '">' + mirrors[m] + '</option>\n')
+menu.close()
+
+# For news redirect
+jsnews = open('redirect_news.html', 'w')
+jsnews.write('<script language="Javascript" type="text/javascript">\n')
+jsnews.write('<!-- Hide from old browsers\n')
+jsnews.write('newsMirrors = new Array\n')
+for i in range(len(mlist)):
+    jsnews.write('newsMirrors[' + str(i) + '] = ' + mlist[i] + 'news/"\n')
+jsnews.write('\n')
+jsnews.write('n = Math.floor(Math.random()*' + str(len(mirrors.keys())) + ')\n\n')
+jsnews.write('if (document.location == "http://samba.org/samba/news/" || document.location == "http://www.samba.org/samba/news/") {\n\n')
+jsnews.write('    document.location = newsMirrors[n]\n}\n')
+jsnews.write('// end hide -->\n')
+jsnews.write('</script>')
+jsnews.close() 
+ 



More information about the samba-cvs mailing list