savannah-hackers-public
[Top][All Lists]
Advanced

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

Re: [Savannah-hackers-public] [gnu.org #912039] Migrate gnu.org/nongnu.o


From: Lisa Maginnis via RT
Subject: Re: [Savannah-hackers-public] [gnu.org #912039] Migrate gnu.org/nongnu.org from CVS
Date: Tue, 06 May 2014 16:41:07 -0400

Please see attached /home/wwwcvs/update-symlinks-xargs.py

Thanks :)

-- 
~Lisa Marie Maginnis
Senior System Administrator
Free Software Foundation
http://fsf.org http://gnu.org
GPG Key: 61EEC710


#!/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()

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]