<s> """<STR_LIT>""" <EOL> from . . service import Service <EOL> __all__ = '<STR_LIT>' , <EOL> class PostgreSQLService ( Service ) : <EOL> @ property <EOL> def required_apt_packages ( self ) : <EOL> base = super ( PostgreSQLService , self ) . required_apt_packages <EOL> packages = frozenset ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> return packages . union ( base ) <EOL> @ property <EOL> def master_database ( self ) : <EOL> try : <EOL> return self . config [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> return self . app . repository . master_branch . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> @ property <EOL> def database ( self ) : <EOL> try : <EOL> fmt = self . config [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> return self . branch . label_ <EOL> return fmt . format ( branch = self . branch ) <EOL> @ property <EOL> def connection_info ( self ) : <EOL> cfg = self . config <EOL> kw_list = '<STR_LIT:user>' , '<STR_LIT:host>' , '<STR_LIT>' , '<STR_LIT:port>' , '<STR_LIT:password>' <EOL> return dict ( ( kw , cfg [ kw ] ) for kw in kw_list if kw in cfg ) <EOL> def install ( self , instance ) : <EOL> cfg = self . config <EOL> if self . database == self . master_database : <EOL> template = '<STR_LIT>' <EOL> else : <EOL> template = self . master_database <EOL> config_opt_map = dict ( <EOL> host = '<STR_LIT:host>' , <EOL> user = '<STR_LIT:username>' , <EOL> password = '<STR_LIT:password>' , <EOL> encoding = '<STR_LIT>' , <EOL> lc_collate = '<STR_LIT>' , <EOL> lc_ctype = '<STR_LIT>' , <EOL> tablespace = '<STR_LIT>' <EOL> ) <EOL> options = [ '<STR_LIT>' + opt + '<STR_LIT:=>' + str ( cfg [ cfg_name ] ) <EOL> for cfg_name , opt in config_opt_map . iteritems ( ) <EOL> if cfg_name in cfg ] <EOL> fail = instance . do ( [ '<STR_LIT>' , '<STR_LIT>' , template ] + options + <EOL> [ self . database ] ) <EOL> if fail : <EOL> instance . do ( [ <EOL> '<STR_LIT>' , '<STR_LIT>' , str ( cfg [ '<STR_LIT:host>' ] ) , '<STR_LIT>' , str ( cfg [ '<STR_LIT:user>' ] ) , <EOL> '<STR_LIT>' , str ( cfg [ '<STR_LIT>' ] ) , '<STR_LIT>' , '<STR_LIT>' + template + '<STR_LIT>' , <EOL> template <EOL> ] ) <EOL> instance . do ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] + options + <EOL> [ self . database ] ) <EOL> instance . do ( [ <EOL> '<STR_LIT>' , '<STR_LIT>' , str ( cfg [ '<STR_LIT:host>' ] ) , '<STR_LIT>' , str ( cfg [ '<STR_LIT:user>' ] ) , <EOL> '<STR_LIT>' , '<STR_LIT>' + template + '<STR_LIT>' , self . database <EOL> ] ) <EOL> info = self . connection_info <EOL> info [ '<STR_LIT>' ] = self . database <EOL> return info </s>
