[Kimchi-devel] [PATCH 1/3] Implement a method to expand variables in a url
Jose Ricardo Ziviani
joserz at linux.vnet.ibm.com
Thu Sep 10 19:23:26 UTC 2015
- creates a generic function to expand variables from a
given string and makes specialized methods to get the name to
display and the repo url.
Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
src/kimchi/yumparser.py | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/kimchi/yumparser.py b/src/kimchi/yumparser.py
index 0c9de77..a481ac2 100644
--- a/src/kimchi/yumparser.py
+++ b/src/kimchi/yumparser.py
@@ -249,21 +249,33 @@ def _get_all_yum_vars():
return variables
-def get_display_name(name):
- if not name:
- return ''
-
+def _expand_variables(stringvar, split_char=' '):
yum_variables = _get_all_yum_vars()
yum_variables['releasever'] = _get_releasever()
yum_variables['basearch'] = _get_basearch()
- name_vars = [var for var in name.split()
+ name_vars = [var for var in stringvar.split(split_char)
if var.startswith('$') and var.strip('$') in yum_variables]
return reduce(lambda nm, var:
nm.replace(var, yum_variables[var.strip('$')]),
name_vars,
- name)
+ stringvar)
+
+
+def get_display_name(name):
+ if not name or '$' not in name:
+ return name
+
+ return _expand_variables(name)
+
+
+def get_expanded_url(url):
+ url_path = url.split('://')
+ if len(url_path) != 2 or '$' not in url:
+ return url
+
+ return _expand_variables(url, '/')
class YumUpdatePackageObject(object):
--
1.9.1
More information about the Kimchi-devel
mailing list