<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import fnmatch <EOL> import logging <EOL> import os <EOL> import pprint <EOL> import yaml <EOL> import salt . ext . six as six <EOL> import salt . utils <EOL> from salt . exceptions import SaltInvocationError <EOL> log = logging . getLogger ( __name__ ) <EOL> __SUFFIX_NOT_NEEDED = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _repack_pkgs ( pkgs , normalize = True ) : <EOL> '''<STR_LIT>''' <EOL> if normalize and '<STR_LIT>' in __salt__ : <EOL> _normalize_name = __salt__ [ '<STR_LIT>' ] <EOL> else : <EOL> _normalize_name = lambda pkgname : pkgname <EOL> return dict ( <EOL> [ <EOL> ( _normalize_name ( str ( x ) ) , str ( y ) if y is not None else y ) <EOL> for x , y in six . iteritems ( salt . utils . repack_dictlist ( pkgs ) ) <EOL> ] <EOL> ) <EOL> def pack_sources ( sources , normalize = True ) : <EOL> '''<STR_LIT>''' <EOL> if normalize and '<STR_LIT>' in __salt__ : <EOL> _normalize_name = __salt__ [ '<STR_LIT>' ] <EOL> else : <EOL> _normalize_name = lambda pkgname : pkgname <EOL> if isinstance ( sources , six . string_types ) : <EOL> try : <EOL> sources = yaml . safe_load ( sources ) <EOL> except yaml . parser . ParserError as err : <EOL> log . error ( err ) <EOL> return { } <EOL> ret = { } <EOL> for source in sources : <EOL> if ( not isinstance ( source , dict ) ) or len ( source ) != <NUM_LIT:1> : <EOL> log . error ( '<STR_LIT>' . format ( pprint . pformat ( sources ) ) ) <EOL> log . error ( '<STR_LIT>' ) <EOL> return { } <EOL> else : <EOL> key = next ( iter ( source ) ) <EOL> ret [ _normalize_name ( key ) ] = source [ key ] <EOL> return ret <EOL> def parse_targets ( name = None , <EOL> pkgs = None , <EOL> sources = None , <EOL> saltenv = '<STR_LIT>' , <EOL> normalize = True , <EOL> ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in kwargs : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> kwargs . pop ( '<STR_LIT>' ) <EOL> if __grains__ [ '<STR_LIT>' ] == '<STR_LIT>' and sources : <EOL> log . warning ( '<STR_LIT>' ) <EOL> if pkgs and sources : <EOL> log . error ( '<STR_LIT>' ) <EOL> return None , None <EOL> elif pkgs : <EOL> pkgs = _repack_pkgs ( pkgs , normalize = normalize ) <EOL> if not pkgs : <EOL> return None , None <EOL> else : <EOL> return pkgs , '<STR_LIT>' <EOL> elif sources and __grains__ [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> sources = pack_sources ( sources , normalize = normalize ) <EOL> if not sources : <EOL> return None , None <EOL> srcinfo = [ ] <EOL> for pkg_name , pkg_src in six . iteritems ( sources ) : <EOL> if __salt__ [ '<STR_LIT>' ] ( pkg_src ) : <EOL> srcinfo . append ( __salt__ [ '<STR_LIT>' ] ( pkg_src , saltenv ) ) <EOL> else : <EOL> if not os . path . isabs ( pkg_src ) : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( pkg_src , pkg_name ) <EOL> ) <EOL> srcinfo . append ( pkg_src ) <EOL> return srcinfo , '<STR_LIT:file>' <EOL> elif name : <EOL> if normalize : <EOL> _normalize_name = __salt__ . get ( '<STR_LIT>' , lambda pkgname : pkgname ) <EOL> packed = dict ( [ ( _normalize_name ( x ) , None ) for x in name . split ( '<STR_LIT:U+002C>' ) ] ) <EOL> else : <EOL> packed = dict ( [ ( x , None ) for x in name . split ( '<STR_LIT:U+002C>' ) ] ) <EOL> return packed , '<STR_LIT>' <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> return None , None <EOL> def version ( * names , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> versions_as_list = salt . utils . is_true ( kwargs . pop ( '<STR_LIT>' , False ) ) <EOL> pkg_glob = False <EOL> if len ( names ) != <NUM_LIT:0> : <EOL> pkgs = __salt__ [ '<STR_LIT>' ] ( versions_as_list = True , ** kwargs ) <EOL> for name in names : <EOL> if '<STR_LIT:*>' in name : <EOL> pkg_glob = True <EOL> for match in fnmatch . filter ( pkgs , name ) : <EOL> ret [ match ] = pkgs . get ( match , [ ] ) <EOL> else : <EOL> ret [ name ] = pkgs . get ( name , [ ] ) <EOL> if not versions_as_list : <EOL> __salt__ [ '<STR_LIT>' ] ( ret ) <EOL> if len ( ret ) == <NUM_LIT:1> and not pkg_glob : <EOL> try : <EOL> return next ( six . itervalues ( ret ) ) <EOL> except StopIteration : <EOL> return '<STR_LIT>' <EOL> return ret <EOL> def add_pkg ( pkgs , name , pkgver ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> pkgs . setdefault ( name , [ ] ) . append ( pkgver ) <EOL> except AttributeError as exc : <EOL> log . exception ( exc ) <EOL> def sort_pkglist ( pkgs ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> for key in pkgs : <EOL> pkgs [ key ] = sorted ( set ( pkgs [ key ] ) ) <EOL> except AttributeError as exc : <EOL> log . exception ( exc ) <EOL> def stringify ( pkgs ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> for key in pkgs : <EOL> pkgs [ key ] = '<STR_LIT:U+002C>' . join ( pkgs [ key ] ) <EOL> except AttributeError as exc : <EOL> log . exception ( exc ) <EOL> def version_clean ( verstr ) : <EOL> '''<STR_LIT>''' <EOL> if verstr and '<STR_LIT>' in __salt__ : <EOL> return __salt__ [ '<STR_LIT>' ] ( verstr ) <EOL> return verstr <EOL> def check_extra_requirements ( pkgname , pkgver ) : <EOL> '''<STR_LIT>''' <EOL> if pkgver and '<STR_LIT>' in __salt__ : <EOL> return __salt__ [ '<STR_LIT>' ] ( pkgname , pkgver ) <EOL> return True </s>
