summaryrefslogtreecommitdiff
path: root/web-server/home-wwwcvs/update-symlinks-xargs.py
diff options
context:
space:
mode:
Diffstat (limited to 'web-server/home-wwwcvs/update-symlinks-xargs.py')
-rwxr-xr-xweb-server/home-wwwcvs/update-symlinks-xargs.py122
1 files changed, 122 insertions, 0 deletions
diff --git a/web-server/home-wwwcvs/update-symlinks-xargs.py b/web-server/home-wwwcvs/update-symlinks-xargs.py
new file mode 100755
index 0000000..206fac6
--- /dev/null
+++ b/web-server/home-wwwcvs/update-symlinks-xargs.py
@@ -0,0 +1,122 @@
+#!/usr/bin/python
+# Use mod_rewrite as opposed to creating real symlinks.
+# (c) 2003, 2011, Free Software Foundation
+#
+# 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 Street, Suite 500, Boston, MA 02110-1335 USA
+
+# ChangeLog
+#
+# 2011.03.01 - Escape dots for Apache regexps. Exclude links for gnu
+# projects (they are regenerated with another script).
+#
+# 2007.11.08 - Change the script to accept more than one file at a time
+# as a commandline argument. This requires changing the order of the args
+# and I'm changing the calling shell script to reflect this
+#
+# 2005.08.23 - Change the script to support a command line argument of
+# {gnu|nongnu|nongnu-vhost}. These arguments change the form of the rewrite
+# rules output (and if they are output).
+# - baughj
+
+import sys
+import re
+from string import *
+from urllib import quote
+from os import lstat
+from stat import *
+from os.path import basename,dirname
+import os.path
+
+# escape dots in regexps
+def escape (str):
+ new_str = ''
+ for x in str:
+ if x == '.':
+ new_str = "%s\%s" % (new_str, x)
+ else:
+ new_str = "%s%s" % (new_str, x)
+ return new_str
+
+def create_rewrite_rule (links, cwd, type):
+ if len(links) != 2 or links[0][0] == '#':
+ return
+
+ # This is an ugly, horrid mess.
+
+ # Also, hilarity: We need to check for the existence of :// so we don't
+ # screw up offsite links that should Just Work.
+
+ external_link = re.compile('://').search(links[0])
+
+ if (type == 'nongnu-vhost'):
+ base = replace(cwd, '/var/www/savannah-checkouts/non-gnu/', '')
+ basedir = dirname(base)
+ if basedir:
+ relativepath = replace(base,basedir,'')
+ else:
+ relativepath = None
+
+ if ((links[1] == "index.html") or
+ (links[1] == "index.shtml") or
+ (links[1] == "index.xhtml")):
+ if (type == 'nongnu' or external_link):
+ print "RewriteRule ^[\./]*$ %s [L]" % (links[0],)
+ else:
+ if relativepath:
+ print "RewriteRule ^[\./]*$ %s/%s [L]" % (relativepath, links[0],)
+ else:
+ print "RewriteRule ^[\./]*$ /%s [L]" % (links[0])
+
+ if (type == 'nongnu' or external_link):
+ print "RewriteRule ^%s$ %s [L]" % (escape (links[1]), links[0])
+ print "RewriteRule ^%s/(.*)$ %s/$1 [L]" % (escape (links[1]), links[0])
+ else:
+ if relativepath:
+ print "RewriteRule ^%s$ %s/%s [L]" % (escape(links[1]), relativepath, links[0])
+ print "RewriteRule ^%s(.*)$ %s/%s/$1 [L]" % (escape(links[1]), relativepath, links[0])
+ else:
+ print "RewriteRule ^%s$ /%s [L]" % (escape (links[1]), links[0])
+ print "RewriteRule ^%s/(.*)$ /%s/$1 [L]" % (escape (links[1]), links[0])
+
+def main():
+ symlink_group = sys.argv[1]
+ for filename in sys.argv[2:]:
+ # print 'filename is ', filename
+ f = open(filename,'r')
+ cwd = os.path.split(filename)[0]
+ # print 'cwd is', cwd
+ nongnu = cwd.startswith('/var/www/savannah-checkouts/non-gnu/')
+ gnu = cwd.startswith('/var/www/savannah-checkouts/gnu/')
+ try:
+ if ((symlink_group == 'gnu') or gnu or \
+ (symlink_group == 'nongnu' and not nongnu) or \
+ (symlink_group == 'nongnu-vhost' and not nongnu)):
+ continue
+ except IndexError:
+ print "usage: update-symlinks.py <symlink file> [gnu|nongnu|nongnu-vhost]"
+ sys.exit(0)
+ # this is a nasty hack
+
+ print "<Directory %s>" % (cwd,)
+ print "RewriteEngine on"
+
+ for line in f.readlines():
+ create_rewrite_rule (split(line.strip()), cwd, symlink_group)
+
+ f.close ()
+ print "</Directory>"
+
+if __name__ == '__main__':
+ main()