#NEWLINE# def save_connection( name , engine , overwrite = False ) : #NEWLINE# #INDENT# 'Saves a connection configuration to ~/.db-connections.' #NEWLINE# cp = getconfigparser ( ) #NEWLINE# try : #NEWLINE# #INDENT# cp . add_section ( name ) #NEWLINE# #UNINDENT# except DuplicateSectionError : #NEWLINE# #INDENT# if overwrite : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# url = engine . url #NEWLINE# cp . set ( name , 'type' , ( url . drivername or '' ) ) #NEWLINE# cp . set ( name , 'username' , ( url . username or '' ) ) #NEWLINE# cp . set ( name , 'password' , ( url . password or '' ) ) #NEWLINE# cp . set ( name , 'host' , ( url . host or '' ) ) #NEWLINE# cp . set ( name , 'database' , ( url . database or '' ) ) #NEWLINE# cp . set ( name , 'port' , ( url . port or '' ) ) #NEWLINE# cp . set ( name , 'query' , ( url . query or '' ) ) #NEWLINE# with open ( CONFIG_FILE , 'w' ) as fout : #NEWLINE# #INDENT# cp . write ( fout )