From a516db971fc7d488244a5adef0a7929234c69ae8 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Sun, 9 Mar 2014 03:14:14 -0500 Subject: [PATCH] Add normalize_name function This will pave the way for .x86_64 architectures to be used in pkg states. --- salt/modules/yumpkg.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py index 7e7d5db8cf..19e9ef35d5 100644 --- a/salt/modules/yumpkg.py +++ b/salt/modules/yumpkg.py @@ -143,6 +143,28 @@ def _get_repo_options(**kwargs): return repo_arg +def normalize_name(name): + ''' + Strips the architecture from the specified package name, if necessary (in + other words, if the arch matches the OS arch, or is ``noarch``. + + CLI Example: + + .. code-block:: bash + + salt '*' pkg.normalize_name zsh.x86_64 + ''' + try: + arch = name.rsplit('.', 1)[-1] + if arch not in __ARCHES + ('noarch',): + return name + except ValueError: + return name + if arch in (__grains__['osarch'], 'noarch'): + return name[:-(len(arch) + 1)] + return name + + def latest_version(*names, **kwargs): ''' Return the latest version of the named package available for upgrade or