<s> from __future__ import print_function <EOL> import sys <EOL> from rospkg . os_detect import OS_DEBIAN , OS_LINARO , OS_UBUNTU , OS_ELEMENTARY , OsDetect <EOL> from . pip import PIP_INSTALLER <EOL> from . gem import GEM_INSTALLER <EOL> from . source import SOURCE_INSTALLER <EOL> from . . installers import PackageManagerInstaller <EOL> from . . shell_utils import read_stdout <EOL> APT_INSTALLER = '<STR_LIT>' <EOL> def register_installers ( context ) : <EOL> context . set_installer ( APT_INSTALLER , AptInstaller ( ) ) <EOL> def register_platforms ( context ) : <EOL> register_debian ( context ) <EOL> register_linaro ( context ) <EOL> register_ubuntu ( context ) <EOL> register_elementary ( context ) <EOL> def register_debian ( context ) : <EOL> context . add_os_installer_key ( OS_DEBIAN , APT_INSTALLER ) <EOL> context . add_os_installer_key ( OS_DEBIAN , PIP_INSTALLER ) <EOL> context . add_os_installer_key ( OS_DEBIAN , GEM_INSTALLER ) <EOL> context . add_os_installer_key ( OS_DEBIAN , SOURCE_INSTALLER ) <EOL> context . set_default_os_installer_key ( OS_DEBIAN , lambda self : APT_INSTALLER ) <EOL> context . set_os_version_type ( OS_DEBIAN , OsDetect . get_codename ) <EOL> def register_linaro ( context ) : <EOL> ( os_name , os_version ) = context . get_os_name_and_version ( ) <EOL> if os_name == OS_LINARO and not context . os_override : <EOL> print ( "<STR_LIT>" % ( OS_LINARO , OS_UBUNTU ) , file = sys . stderr ) <EOL> context . set_os_override ( OS_UBUNTU , context . os_detect . get_codename ( ) ) <EOL> def register_elementary ( context ) : <EOL> ( os_name , os_version ) = context . get_os_name_and_version ( ) <EOL> if os_name == OS_ELEMENTARY and not context . os_override : <EOL> print ( "<STR_LIT>" % ( OS_ELEMENTARY , OS_UBUNTU ) , file = sys . stderr ) <EOL> context . set_os_override ( OS_UBUNTU , context . os_detect . get_codename ( ) ) <EOL> def register_ubuntu ( context ) : <EOL> context . add_os_installer_key ( OS_UBUNTU , APT_INSTALLER ) <EOL> context . add_os_installer_key ( OS_UBUNTU , PIP_INSTALLER ) <EOL> context . add_os_installer_key ( OS_UBUNTU , GEM_INSTALLER ) <EOL> context . add_os_installer_key ( OS_UBUNTU , SOURCE_INSTALLER ) <EOL> context . set_default_os_installer_key ( OS_UBUNTU , lambda self : APT_INSTALLER ) <EOL> context . set_os_version_type ( OS_UBUNTU , OsDetect . get_codename ) <EOL> def dpkg_detect ( pkgs , exec_fn = None ) : <EOL> """<STR_LIT>""" <EOL> ret_list = [ ] <EOL> version_lock_map = { } <EOL> for p in pkgs : <EOL> if '<STR_LIT:=>' in p : <EOL> version_lock_map [ p . split ( '<STR_LIT:=>' ) [ <NUM_LIT:0> ] ] = p <EOL> else : <EOL> version_lock_map [ p ] = p <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> cmd . extend ( version_lock_map . keys ( ) ) <EOL> if exec_fn is None : <EOL> exec_fn = read_stdout <EOL> std_out = exec_fn ( cmd ) <EOL> std_out = std_out . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> pkg_list = std_out . split ( '<STR_LIT:\n>' ) <EOL> for pkg in pkg_list : <EOL> pkg_row = pkg . split ( ) <EOL> if len ( pkg_row ) == <NUM_LIT:4> and ( pkg_row [ <NUM_LIT:3> ] == '<STR_LIT>' ) : <EOL> ret_list . append ( pkg_row [ <NUM_LIT:0> ] ) <EOL> return [ version_lock_map [ r ] for r in ret_list ] <EOL> class AptInstaller ( PackageManagerInstaller ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( AptInstaller , self ) . __init__ ( dpkg_detect ) <EOL> def get_install_command ( self , resolved , interactive = True , reinstall = False , quiet = False ) : <EOL> packages = self . get_packages_to_install ( resolved , reinstall = reinstall ) <EOL> if not packages : <EOL> return [ ] <EOL> if not interactive and quiet : <EOL> return [ self . elevate_priv ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , p ] ) for p in packages ] <EOL> elif quiet : <EOL> return [ self . elevate_priv ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , p ] ) for p in packages ] <EOL> if not interactive : <EOL> return [ self . elevate_priv ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , p ] ) for p in packages ] <EOL> else : <EOL> return [ self . elevate_priv ( [ '<STR_LIT>' , '<STR_LIT>' , p ] ) for p in packages ] </s>
