From 4fb20198db256fb8c7cd9588cd26611354e97e49 Mon Sep 17 00:00:00 2001 From: Lubos Kocman Date: Thu, 27 Aug 2015 11:02:37 +0200 Subject: [PATCH] Add translate path support. Useful for passing pungi repos to image-build Signed-off-by: Lubos Kocman --- pungi/paths.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pungi/paths.py b/pungi/paths.py index a8157a4a..02b9d083 100644 --- a/pungi/paths.py +++ b/pungi/paths.py @@ -25,6 +25,21 @@ import os from pungi.util import makedirs +def translate_path(compose, path): + """ + @param compose - required for access to config + @param path + """ + normpath = os.path.normpath(path) + mapping = compose.conf.get("translate_paths", []) + + for prefix, newvalue in mapping: + prefix = os.path.normpath(prefix) + if normpath.startswith(prefix): + # don't call os.path.normpath on result since that would break http:// -> http:/ and so on + return normpath.replace(prefix, newvalue, 1) # replace only 1 occurance + + return normpath class Paths(object): def __init__(self, compose):