<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import os <EOL> import salt . version <EOL> import salt . utils <EOL> from salt . exceptions import CommandNotFoundError <EOL> from salt . ext import six <EOL> log = logging . getLogger ( __name__ ) <EOL> __virtualname__ = '<STR_LIT>' <EOL> def __virtual__ ( ) : <EOL> return __virtualname__ <EOL> def managed ( name , <EOL> venv_bin = None , <EOL> requirements = None , <EOL> system_site_packages = False , <EOL> distribute = False , <EOL> use_wheel = False , <EOL> clear = False , <EOL> python = None , <EOL> extra_search_dir = None , <EOL> never_download = None , <EOL> prompt = None , <EOL> user = None , <EOL> no_chown = False , <EOL> cwd = None , <EOL> index_url = None , <EOL> extra_index_url = None , <EOL> pre_releases = False , <EOL> no_deps = False , <EOL> pip_download = None , <EOL> pip_download_cache = None , <EOL> pip_exists_action = None , <EOL> pip_ignore_installed = False , <EOL> proxy = None , <EOL> use_vt = False , <EOL> env_vars = None , <EOL> no_use_wheel = False , <EOL> pip_upgrade = False , <EOL> pip_pkgs = None ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , '<STR_LIT:result>' : True , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : { } } <EOL> if '<STR_LIT>' not in __salt__ : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return ret <EOL> if salt . utils . is_windows ( ) : <EOL> venv_py = os . path . join ( name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> venv_py = os . path . join ( name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> venv_exists = os . path . exists ( venv_py ) <EOL> if requirements and requirements . startswith ( '<STR_LIT>' ) : <EOL> cached_requirements = __salt__ [ '<STR_LIT>' ] ( requirements , __env__ ) <EOL> if not cached_requirements : <EOL> cached_requirements = __salt__ [ '<STR_LIT>' ] ( <EOL> requirements , __env__ <EOL> ) <EOL> if __salt__ [ '<STR_LIT>' ] ( requirements , __env__ ) != __salt__ [ '<STR_LIT>' ] ( cached_requirements , __env__ ) : <EOL> cached_requirements = __salt__ [ '<STR_LIT>' ] ( <EOL> requirements , __env__ <EOL> ) <EOL> if not cached_requirements : <EOL> ret . update ( { <EOL> '<STR_LIT:result>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( <EOL> requirements <EOL> ) <EOL> } ) <EOL> return ret <EOL> requirements = cached_requirements <EOL> if venv_exists and clear : <EOL> ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] = __salt__ [ '<STR_LIT>' ] ( bin_env = name ) <EOL> ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' . format ( venv_py ) ) . strip ( '<STR_LIT:\n>' ) <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> if venv_exists and clear : <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> if venv_exists and not clear : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> if not venv_exists or ( venv_exists and clear ) : <EOL> try : <EOL> _ret = __salt__ [ '<STR_LIT>' ] ( <EOL> name , <EOL> venv_bin = venv_bin , <EOL> system_site_packages = system_site_packages , <EOL> distribute = distribute , <EOL> clear = clear , <EOL> python = python , <EOL> extra_search_dir = extra_search_dir , <EOL> never_download = never_download , <EOL> prompt = prompt , <EOL> user = user , <EOL> use_vt = use_vt , <EOL> ) <EOL> except CommandNotFoundError as err : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . formar ( err ) <EOL> return ret <EOL> if _ret [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = _ret [ '<STR_LIT>' ] + _ret [ '<STR_LIT>' ] <EOL> return ret <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] = __salt__ [ '<STR_LIT>' ] ( <EOL> '<STR_LIT>' . format ( venv_py ) ) . strip ( '<STR_LIT:\n>' ) <EOL> if clear : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> elif venv_exists : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if use_wheel : <EOL> min_version = '<STR_LIT>' <EOL> cur_version = __salt__ [ '<STR_LIT>' ] ( bin_env = name ) <EOL> if not salt . utils . compare_versions ( ver1 = cur_version , oper = '<STR_LIT>' , <EOL> ver2 = min_version ) : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( min_version , cur_version ) <EOL> return ret <EOL> if no_use_wheel : <EOL> min_version = '<STR_LIT>' <EOL> cur_version = __salt__ [ '<STR_LIT>' ] ( bin_env = name ) <EOL> if not salt . utils . compare_versions ( ver1 = cur_version , oper = '<STR_LIT>' , <EOL> ver2 = min_version ) : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( min_version , <EOL> cur_version ) <EOL> return ret <EOL> if requirements or pip_pkgs : <EOL> before = set ( __salt__ [ '<STR_LIT>' ] ( bin_env = name , user = user , use_vt = use_vt ) ) <EOL> if requirements : <EOL> if isinstance ( requirements , six . string_types ) : <EOL> req_canary = requirements . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:0> ] <EOL> elif isinstance ( requirements , list ) : <EOL> req_canary = requirements [ <NUM_LIT:0> ] <EOL> else : <EOL> raise TypeError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> if req_canary != os . path . abspath ( req_canary ) : <EOL> cwd = os . path . dirname ( os . path . abspath ( req_canary ) ) <EOL> _ret = __salt__ [ '<STR_LIT>' ] ( <EOL> pkgs = pip_pkgs , <EOL> requirements = requirements , <EOL> bin_env = name , <EOL> use_wheel = use_wheel , <EOL> no_use_wheel = no_use_wheel , <EOL> user = user , <EOL> cwd = cwd , <EOL> index_url = index_url , <EOL> extra_index_url = extra_index_url , <EOL> download = pip_download , <EOL> download_cache = pip_download_cache , <EOL> no_chown = no_chown , <EOL> pre_releases = pre_releases , <EOL> exists_action = pip_exists_action , <EOL> ignore_installed = pip_ignore_installed , <EOL> upgrade = pip_upgrade , <EOL> no_deps = no_deps , <EOL> proxy = proxy , <EOL> use_vt = use_vt , <EOL> env_vars = env_vars <EOL> ) <EOL> ret [ '<STR_LIT:result>' ] &= _ret [ '<STR_LIT>' ] == <NUM_LIT:0> <EOL> if _ret [ '<STR_LIT>' ] > <NUM_LIT:0> : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( ret [ '<STR_LIT>' ] , <EOL> _ret [ '<STR_LIT>' ] , <EOL> _ret [ '<STR_LIT>' ] ) <EOL> after = set ( __salt__ [ '<STR_LIT>' ] ( bin_env = name ) ) <EOL> new = list ( after - before ) <EOL> old = list ( before - after ) <EOL> if new or old : <EOL> ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : new if new else '<STR_LIT>' , <EOL> '<STR_LIT>' : old if old else '<STR_LIT>' } <EOL> return ret <EOL> manage = salt . utils . alias_function ( managed , '<STR_LIT>' ) </s>
