[Inteproxy-commits] r230 - in trunk: . inteproxy_server
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Mar 18 13:51:40 CET 2010
Author: bjoern
Date: 2010-03-18 13:51:39 +0100 (Thu, 18 Mar 2010)
New Revision: 230
Added:
trunk/create-rewrite-rules.py
Removed:
trunk/inteproxy_server/create-rewrite-rules.py
Log:
Moved create-rewrite-rules script back, because of hardwired inteproxy python
dependencies.
Copied: trunk/create-rewrite-rules.py (from rev 227, trunk/inteproxy_server/create-rewrite-rules.py)
Deleted: trunk/inteproxy_server/create-rewrite-rules.py
===================================================================
--- trunk/inteproxy_server/create-rewrite-rules.py 2010-03-18 12:47:16 UTC (rev 229)
+++ trunk/inteproxy_server/create-rewrite-rules.py 2010-03-18 12:51:39 UTC (rev 230)
@@ -1,84 +0,0 @@
-#! /usr/bin/env python
-
-"""
-Usage:
- create-rewrite-rules.py --config-file=... [-o outfile]
-
-Script to convert InteProxy's configuration to Apache RewriteRule
-definitions. The script reads the InteProxy configuration file
-specified with --config-file and writes a RewriteRule for all entries in
-the configuration file for which credentials are specified. The output
-is written to outfile. If no outfile is specified, the output is
-written to stdout.
-"""
-
-import sys
-import optparse
-import re
-from urllib import quote_plus
-
-import inteproxy.resources
-import inteproxy.config
-from inteproxy.transcoder import pattern_to_regex
-
-
-def read_config(config_filename):
- return inteproxy.config.read_config(config_filename)
-
-
-def rule_for_owsproxy(rule):
- orig_url = "/" + rule.host + rule.path
- if rule.user is None or rule.password is None:
- print >>sys.stderr, ("Missing credentials for url %r"
- % orig_url)
- return None
- host_regex = pattern_to_regex(rule.host, character_set="[^/]")
- path_regex = pattern_to_regex(rule.path, character_set=".")
- port_regex = ""
- if rule.port is not None:
- port_regex = re.escape(":%d" % rule.port)
- return ("RewriteRule ^/%s%s%s$ https:/$0?user=%s&password=%s [QSA,P]\n"
- % (host_regex, port_regex, path_regex,
- re.escape(quote_plus(rule.user)),
- re.escape(quote_plus(rule.password))))
-
-
-def create_rewrite_rules(config, outfile):
- """Writes the RewriteRules from config to outfile"""
- for rule in config.rules:
- if rule.scheme != "owsproxy":
- print >>sys.stderr, ("Unsupported scheme %r for %s/%s"
- % (rule.scheme, rule.host, rule.path))
- continue
- rewrite_rule = rule_for_owsproxy(rule)
- if rewrite_rule:
- outfile.write(rewrite_rule)
-
-
-def create_config_parser():
- """Creates an OptionParser instance for the script"""
- parser = optparse.OptionParser()
- parser.set_defaults(
- config_file=inteproxy.resources.default_config_file(),
- credentials_file=inteproxy.resources.default_credentials_file())
- parser.add_option("--config-file", help=("InteProxy configuration file"))
- parser.add_option("--output-file", "-o",
- help=("Output file (by default output is written to"
- " stdout)"))
- return parser
-
-
-def main():
- parser = create_config_parser()
- opts, rest = parser.parse_args()
- config = read_config(opts.config_file)
-
- outfile = sys.stdout
- if opts.output_file:
- outfile = open(opts.output_file, "w")
-
- create_rewrite_rules(config, outfile)
-
-
-if __name__ == "__main__":
- main()
More information about the Inteproxy-commits
mailing list