<s> """<STR_LIT>""" <EOL> from fabric . api import cd , hide , sudo , settings <EOL> def _run_as_pg ( command ) : <EOL> """<STR_LIT>""" <EOL> with cd ( '<STR_LIT>' ) : <EOL> return sudo ( command , user = '<STR_LIT>' ) <EOL> def user_exists ( name ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> warn_only = True ) : <EOL> res = _run_as_pg ( '''<STR_LIT>''' % locals ( ) ) <EOL> return ( res == "<STR_LIT:1>" ) <EOL> def create_user ( name , password , superuser = False , createdb = False , <EOL> createrole = False , inherit = True , login = True , <EOL> connection_limit = None , encrypted_password = False ) : <EOL> """<STR_LIT>""" <EOL> options = [ <EOL> '<STR_LIT>' if superuser else '<STR_LIT>' , <EOL> '<STR_LIT>' if createdb else '<STR_LIT>' , <EOL> '<STR_LIT>' if createrole else '<STR_LIT>' , <EOL> '<STR_LIT>' if inherit else '<STR_LIT>' , <EOL> '<STR_LIT>' if login else '<STR_LIT>' , <EOL> ] <EOL> if connection_limit is not None : <EOL> options . append ( '<STR_LIT>' % connection_limit ) <EOL> password_type = '<STR_LIT>' if encrypted_password else '<STR_LIT>' <EOL> options . append ( "<STR_LIT>" % ( password_type , password ) ) <EOL> options = '<STR_LIT:U+0020>' . join ( options ) <EOL> _run_as_pg ( '''<STR_LIT>''' % locals ( ) ) <EOL> def drop_user ( name ) : <EOL> """<STR_LIT>""" <EOL> _run_as_pg ( '''<STR_LIT>''' % locals ( ) ) <EOL> def database_exists ( name ) : <EOL> """<STR_LIT>""" <EOL> with settings ( hide ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> warn_only = True ) : <EOL> return _run_as_pg ( '''<STR_LIT>''' % locals ( ) ) . succeeded <EOL> def create_database ( name , owner , template = '<STR_LIT>' , encoding = '<STR_LIT>' , <EOL> locale = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> _run_as_pg ( '''<STR_LIT>''' % locals ( ) ) <EOL> def drop_database ( name ) : <EOL> """<STR_LIT>""" <EOL> _run_as_pg ( '''<STR_LIT>''' % locals ( ) ) <EOL> def create_schema ( name , database , owner = None ) : <EOL> """<STR_LIT>""" <EOL> if owner : <EOL> _run_as_pg ( '''<STR_LIT>''' % locals ( ) ) <EOL> else : <EOL> _run_as_pg ( '''<STR_LIT>''' % locals ( ) ) </s>
