<s> """<STR_LIT>""" <EOL> from fabric . api import hide , run , settings <EOL> from fabtools . files import is_file <EOL> from fabtools . utils import read_lines , run_as_root <EOL> class UnsupportedFamily ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , supported ) : <EOL> self . supported = supported <EOL> self . distrib = distrib_id ( ) <EOL> self . family = distrib_family ( ) <EOL> msg = "<STR_LIT>" % ( self . family , self . distrib , '<STR_LIT:U+002CU+0020>' . join ( supported ) ) <EOL> super ( UnsupportedFamily , self ) . __init__ ( msg ) <EOL> def distrib_id ( ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> kernel = run ( '<STR_LIT>' ) <EOL> if kernel == '<STR_LIT>' : <EOL> if is_file ( '<STR_LIT>' ) : <EOL> id_ = run ( '<STR_LIT>' ) <EOL> if id in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> id_ = '<STR_LIT>' <EOL> return id_ <EOL> else : <EOL> if is_file ( '<STR_LIT>' ) : <EOL> return "<STR_LIT>" <EOL> elif is_file ( '<STR_LIT>' ) : <EOL> return "<STR_LIT>" <EOL> elif is_file ( '<STR_LIT>' ) : <EOL> return "<STR_LIT>" <EOL> elif is_file ( '<STR_LIT>' ) : <EOL> release = run ( '<STR_LIT>' ) <EOL> if release . startswith ( '<STR_LIT>' ) : <EOL> return "<STR_LIT>" <EOL> elif release . startswith ( '<STR_LIT>' ) : <EOL> return "<STR_LIT>" <EOL> elif release . startswith ( '<STR_LIT>' ) : <EOL> return "<STR_LIT>" <EOL> elif is_file ( '<STR_LIT>' ) : <EOL> return "<STR_LIT>" <EOL> elif kernel == "<STR_LIT>" : <EOL> return "<STR_LIT>" <EOL> def distrib_release ( ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> kernel = run ( '<STR_LIT>' ) <EOL> if kernel == '<STR_LIT>' : <EOL> return run ( '<STR_LIT>' ) <EOL> elif kernel == '<STR_LIT>' : <EOL> return run ( '<STR_LIT>' ) <EOL> def distrib_codename ( ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> return run ( '<STR_LIT>' ) <EOL> def distrib_desc ( ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> if not is_file ( '<STR_LIT>' ) : <EOL> return run ( '<STR_LIT>' ) <EOL> return run ( '<STR_LIT>' ) <EOL> def distrib_family ( ) : <EOL> """<STR_LIT>""" <EOL> distrib = distrib_id ( ) <EOL> if distrib in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return '<STR_LIT>' <EOL> elif distrib in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return '<STR_LIT>' <EOL> elif distrib in [ '<STR_LIT>' ] : <EOL> return '<STR_LIT>' <EOL> elif distrib in [ '<STR_LIT>' ] : <EOL> return '<STR_LIT>' <EOL> elif distrib in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def get_hostname ( ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> return run ( '<STR_LIT>' ) <EOL> def set_hostname ( hostname , persist = True ) : <EOL> """<STR_LIT>""" <EOL> run_as_root ( '<STR_LIT>' % hostname ) <EOL> if persist : <EOL> run_as_root ( '<STR_LIT>' % hostname ) <EOL> def get_sysctl ( key ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> return run_as_root ( '<STR_LIT>' % locals ( ) ) <EOL> def set_sysctl ( key , value ) : <EOL> """<STR_LIT>""" <EOL> run_as_root ( '<STR_LIT>' % locals ( ) ) <EOL> def supported_locales ( ) : <EOL> """<STR_LIT>""" <EOL> family = distrib_family ( ) <EOL> if family == '<STR_LIT>' : <EOL> return _parse_locales ( '<STR_LIT>' ) <EOL> elif family == '<STR_LIT>' : <EOL> return _parse_locales ( '<STR_LIT>' ) <EOL> elif family == '<STR_LIT>' : <EOL> return _supported_locales_redhat ( ) <EOL> else : <EOL> raise UnsupportedFamily ( supported = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def _parse_locales ( path ) : <EOL> lines = read_lines ( path ) <EOL> return list ( _split_on_spaces ( _strip ( _remove_comments ( lines ) ) ) ) <EOL> def _split_on_spaces ( lines ) : <EOL> return ( line . split ( '<STR_LIT:U+0020>' ) for line in lines ) <EOL> def _strip ( lines ) : <EOL> return ( line . strip ( ) for line in lines ) <EOL> def _remove_comments ( lines ) : <EOL> return ( line for line in lines if not line . startswith ( '<STR_LIT:#>' ) ) <EOL> def _supported_locales_redhat ( ) : <EOL> res = run ( '<STR_LIT>' ) <EOL> return [ ( locale , None ) for locale in res . splitlines ( ) ] <EOL> def get_arch ( ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> arch = run ( '<STR_LIT>' ) <EOL> return arch <EOL> def cpus ( ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> res = run ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return int ( res ) <EOL> def using_systemd ( ) : <EOL> """<STR_LIT>""" <EOL> return run ( '<STR_LIT>' , quiet = True ) . succeeded <EOL> def time ( ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> return int ( run ( '<STR_LIT>' ) ) </s>
