From e8ab7ae50df39a8284823624d3fefdbb3a2c325b Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Mon, 13 Feb 2006 18:01:32 +0000 Subject: - added function mapurl, which maps(!) urls using a regexp defined in the option "url-map" in repsys.conf to allow changes like svn+ssh:// to file://.. --- RepSys/util.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'RepSys/util.py') diff --git a/RepSys/util.py b/RepSys/util.py index 0337bc1..c39d3ac 100644 --- a/RepSys/util.py +++ b/RepSys/util.py @@ -1,9 +1,16 @@ #!/usr/bin/python + from RepSys import Error, config + import getpass -import sys, os +import sys +import os +import re +import logging #import commands +log = logging.getLogger("repsys") + # Our own version of commands' getstatusoutput(). We have a commands # module directory, so we can't import Python's standard module def commands_getstatusoutput(cmd): @@ -51,4 +58,24 @@ def get_auth(username=None, password=None): config.set("auth", "password", password) return username, password + +def mapurl(url): + """Maps a url following the regexp provided by the option url-map in + repsys.conf + """ + urlmap = config.get("global", "url-map") + newurl = url + if urlmap: + try: + expr_, replace = urlmap.split()[:2] + except ValueError: + log.error("invalid url-map: %s", urlmap) + else: + try: + newurl = re.sub(expr_, replace, url) + except re.error, errmsg: + log.error("error in URL mapping regexp: %s", errmsg) + return newurl + + # vim:et:ts=4:sw=4 -- cgit v1.2.1