Add normalize_name function

This will pave the way for .x86_64 architectures to be used in pkg
states.
This commit is contained in:
Erik Johnson 2014-03-09 03:14:14 -05:00
parent a91ec264d7
commit a516db971f

View File

@ -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