#!/usr/bin/env python2 # Copyright © 1999, 2000 Progiciels Bourbeau-Pinard inc. # François Pinard , 1999. """\ Create relocating pages to lauch CGI scripts for the Translation Project. Usage: html-to-cgi [OPTION]... -C HTMLDIR Create HTML files within HTMLDIR (mandatory option) -D Process all domains from registry data -T Process all teams from registry data """ import getopt, re, sys import registry def main(*arguments): if not arguments: sys.stdout.write(__doc__) sys.exit(0) # Decode options. htmldir = None domain_option = team_option = 0 options, arguments = getopt.getopt(arguments, 'C:DT') for option, value in options: if option == '-C': htmldir = value elif option == '-D': domain_option = 1 elif option == '-T': team_option = 1 assert htmldir, "`-C HTMLDIR' is mandatory" if domain_option: relocate(htmldir and '%s/domains.html' % htmldir, 'the textual domain index', 'domain=index') for domain in registry.domain_list(): relocate(htmldir and '%s/domain-%s.html' % (htmldir, domain.name), 'the %s textual domain' % domain.name, 'domain=%s' % domain.name) if team_option: relocate(htmldir and '%s/teams.html' % htmldir, 'the national team index', 'team=index') for team in registry.team_list(): relocate(htmldir and '%s/team-%s.html' % (htmldir, team.name), 'the %s national team' % team.language, 'team=%s' % team.name) def relocate(name, description, params): if name: write = open(name, 'w').write else: write = sys.stdout.write # This would be simpler if only I could force it instead of HTTP headers. #write('Status: 302 Redirected\r\n' # 'Location: %s/registry.cgi?%s\r\n' # '\r\n' # % (registry.cgiurl, params)) # Some write `302 Moved\n' instead. write(""" Redirection page

Computing an HTML page for %s.

If your browser supports page redirection, this page should disappear within a few seconds. Otherwise, you may click here to launch the generation of the results. """ % (registry.cgiurl, params, description, registry.cgiurl, params)) if __name__ == '__main__': apply(main, tuple(sys.argv[1:]))