diff options
-rw-r--r-- | RepSys/util.py | 29 |
1 files changed, 28 insertions, 1 deletions
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 |