<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import os <EOL> import logging <EOL> import shlex <EOL> try : <EOL> import pipes <EOL> HAS_DEPS = True <EOL> except ImportError : <EOL> HAS_DEPS = False <EOL> import salt . utils <EOL> log = logging . getLogger ( __name__ ) <EOL> __virtualname__ = '<STR_LIT>' <EOL> if hasattr ( shlex , '<STR_LIT>' ) : <EOL> _quote = shlex . quote <EOL> elif HAS_DEPS and hasattr ( pipes , '<STR_LIT>' ) : <EOL> _quote = pipes . quote <EOL> else : <EOL> _quote = None <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if salt . utils . is_darwin ( ) and _quote is not None : <EOL> return __virtualname__ <EOL> return False <EOL> def install ( pkg , target = '<STR_LIT>' , store = False , allow_untrusted = False ) : <EOL> '''<STR_LIT>''' <EOL> pkg = _quote ( pkg ) <EOL> target = _quote ( target ) <EOL> cmd = '<STR_LIT>' . format ( pkg , target ) <EOL> if store : <EOL> cmd += '<STR_LIT>' <EOL> if allow_untrusted : <EOL> cmd += '<STR_LIT>' <EOL> python_shell = False <EOL> if '<STR_LIT>' in cmd : <EOL> python_shell = True <EOL> return __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = python_shell ) <EOL> def install_app ( app , target = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> app = _quote ( app ) <EOL> target = _quote ( target ) <EOL> if not target [ - <NUM_LIT:4> : ] == '<STR_LIT>' : <EOL> if app [ - <NUM_LIT:1> : ] == '<STR_LIT:/>' : <EOL> base_app = os . path . basename ( app [ : - <NUM_LIT:1> ] ) <EOL> else : <EOL> base_app = os . path . basename ( app ) <EOL> target = os . path . join ( target , base_app ) <EOL> if not app [ - <NUM_LIT:1> ] == '<STR_LIT:/>' : <EOL> app += '<STR_LIT:/>' <EOL> cmd = '<STR_LIT>' . format ( app , target ) <EOL> return __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> def uninstall_app ( app ) : <EOL> '''<STR_LIT>''' <EOL> return __salt__ [ '<STR_LIT>' ] ( app ) <EOL> def mount ( dmg ) : <EOL> '''<STR_LIT>''' <EOL> temp_dir = __salt__ [ '<STR_LIT>' ] ( prefix = '<STR_LIT>' ) <EOL> cmd = '<STR_LIT>' . format ( temp_dir , dmg ) <EOL> return __salt__ [ '<STR_LIT>' ] ( cmd ) , temp_dir <EOL> def unmount ( mountpoint ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' . format ( mountpoint ) <EOL> return __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> def installed_pkgs ( ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' <EOL> return __salt__ [ '<STR_LIT>' ] ( cmd ) . split ( '<STR_LIT:\n>' ) <EOL> def get_pkg_id ( pkg ) : <EOL> '''<STR_LIT>''' <EOL> pkg = _quote ( pkg ) <EOL> package_ids = [ ] <EOL> temp_dir = __salt__ [ '<STR_LIT>' ] ( prefix = '<STR_LIT>' ) <EOL> try : <EOL> cmd = '<STR_LIT>' . format ( pkg ) <EOL> out = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = True , output_loglevel = '<STR_LIT>' ) <EOL> files = out . split ( '<STR_LIT:\n>' ) <EOL> if '<STR_LIT>' not in out : <EOL> cmd = '<STR_LIT>' . format ( pkg , '<STR_LIT:U+0020>' . join ( files ) ) <EOL> __salt__ [ '<STR_LIT>' ] ( cmd , cwd = temp_dir , output_loglevel = '<STR_LIT>' ) <EOL> for f in files : <EOL> i = _get_pkg_id_from_pkginfo ( os . path . join ( temp_dir , f ) ) <EOL> if len ( i ) : <EOL> package_ids . extend ( i ) <EOL> else : <EOL> package_ids = _get_pkg_id_dir ( pkg ) <EOL> finally : <EOL> __salt__ [ '<STR_LIT>' ] ( temp_dir ) <EOL> return package_ids <EOL> def get_mpkg_ids ( mpkg ) : <EOL> '''<STR_LIT>''' <EOL> mpkg = _quote ( mpkg ) <EOL> package_infos = [ ] <EOL> base_path = os . path . dirname ( mpkg ) <EOL> cmd = '<STR_LIT>' . format ( base_path ) <EOL> out = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = True ) <EOL> pkg_files = out . split ( '<STR_LIT:\n>' ) <EOL> for p in pkg_files : <EOL> package_infos . extend ( get_pkg_id ( p ) ) <EOL> return package_infos <EOL> def _get_pkg_id_from_pkginfo ( pkginfo ) : <EOL> pkginfo = _quote ( pkginfo ) <EOL> cmd = '<STR_LIT>' . format ( pkginfo ) <EOL> out = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = True ) <EOL> if '<STR_LIT>' not in out : <EOL> return out . split ( '<STR_LIT:\n>' ) <EOL> return [ ] <EOL> def _get_pkg_id_dir ( path ) : <EOL> path = _quote ( os . path . join ( path , '<STR_LIT>' ) ) <EOL> cmd = '<STR_LIT>' . format ( path ) <EOL> python_shell = False <EOL> if '<STR_LIT>' in cmd : <EOL> python_shell = True <EOL> out = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = python_shell ) <EOL> if '<STR_LIT>' not in out : <EOL> return [ out ] <EOL> return [ ] </s>
