aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdano Arendartchuk <bogdano@mandriva.org>2006-02-13 18:01:32 +0000
committerBogdano Arendartchuk <bogdano@mandriva.org>2006-02-13 18:01:32 +0000
commite8ab7ae50df39a8284823624d3fefdbb3a2c325b (patch)
tree23172c17229b78112fd8dbe4195fc721c9275867
parentc5ff7a193d30a6828ef9b86c27beddb093db00cd (diff)
downloadmgarepo-e8ab7ae50df39a8284823624d3fefdbb3a2c325b.tar
mgarepo-e8ab7ae50df39a8284823624d3fefdbb3a2c325b.tar.gz
mgarepo-e8ab7ae50df39a8284823624d3fefdbb3a2c325b.tar.bz2
mgarepo-e8ab7ae50df39a8284823624d3fefdbb3a2c325b.tar.xz
mgarepo-e8ab7ae50df39a8284823624d3fefdbb3a2c325b.zip
- 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://..
-rw-r--r--RepSys/util.py29
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