<s> class Distro ( object ) : <EOL> def __init__ ( self , name , install_cmd , version_separator ) : <EOL> self . _name = name <EOL> self . _install_command = install_cmd <EOL> self . _version_separator = version_separator <EOL> @ property <EOL> def name ( self ) : <EOL> return self . _name <EOL> @ property <EOL> def install_command ( self ) : <EOL> return self . _install_command <EOL> @ property <EOL> def version_separator ( self ) : <EOL> return self . _version_separator <EOL> def create_install_cmd ( self , packages ) : <EOL> s = self . version_separator <EOL> def join_package_version ( pv_item ) : <EOL> p , v = pv_item if len ( pv_item ) > <NUM_LIT:1> else ( pv_item [ <NUM_LIT:0> ] , None ) <EOL> return p + s + v + '<STR_LIT:*>' if v else p <EOL> packages = '<STR_LIT:U+0020>' . join ( map ( join_package_version , packages ) ) <EOL> command = '<STR_LIT>' <EOL> args = { '<STR_LIT>' : self . install_command , '<STR_LIT>' : packages } <EOL> return command % args <EOL> UBUNTU = Distro ( <EOL> name = '<STR_LIT>' , <EOL> install_cmd = '<STR_LIT>' , <EOL> version_separator = '<STR_LIT:=>' , <EOL> ) <EOL> CENTOS = Distro ( <EOL> name = '<STR_LIT>' , <EOL> install_cmd = '<STR_LIT>' , <EOL> version_separator = '<STR_LIT:->' , <EOL> ) <EOL> RHEL = Distro ( <EOL> name = '<STR_LIT>' , <EOL> install_cmd = '<STR_LIT>' , <EOL> version_separator = '<STR_LIT:->' , <EOL> ) <EOL> SUSE = Distro ( <EOL> name = '<STR_LIT>' , <EOL> install_cmd = '<STR_LIT>' , <EOL> version_separator = '<STR_LIT::>' , <EOL> ) <EOL> def get_all ( ) : <EOL> return [ UBUNTU , CENTOS , RHEL , SUSE ] <EOL> def get ( instance ) : <EOL> with instance . remote ( ) as r : <EOL> name = r . execute_command ( '<STR_LIT>' , run_as_root = True ) [ <NUM_LIT:1> ] <EOL> for d in get_all ( ) : <EOL> if d . name in name : <EOL> return d </s>
