#NEWLINE# def restore_zk( handle , zk_persist_file ) : #NEWLINE# #INDENT# ' Restores Zookeeper data from a fixed file in the local FS.\n\n  Args:\n    handle: A Zookeeper client handler.\n    zk_persist_file: A file object containing the ZooKeeper data.\n  ' #NEWLINE# for line in zk_persist_file . readlines ( ) : #NEWLINE# #INDENT# pair = json . loads ( line ) #NEWLINE# path = pair . keys ( ) [ 0 ] #NEWLINE# value = pair . values ( ) [ 0 ] . decode ( 'base64' ) #NEWLINE# try : #NEWLINE# #INDENT# handle . create ( path , bytes ( value ) , makepath = True ) #NEWLINE# logging . debug ( "Created '{0}'" . format ( path ) ) #NEWLINE# #UNINDENT# except kazoo . exceptions . NodeExistsError : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# handle . set ( path , bytes ( value ) ) #NEWLINE# logging . debug ( "Updated '{0}'" . format ( path ) ) #NEWLINE# #UNINDENT# except kazoo . exceptions . BadArgumentsError : #NEWLINE# #INDENT# logging . warning ( "BadArgumentsError for path '{0}'" . format ( path ) ) #NEWLINE# #UNINDENT# #UNINDENT# except kazoo . exceptions . NoNodeError : #NEWLINE# #INDENT# logging . warning ( "NoNodeError for path '{0}'. Parent nodes are missing" . format ( path ) ) #NEWLINE# #UNINDENT# except kazoo . exceptions . ZookeeperError : #NEWLINE# #INDENT# logging . warning ( "ZookeeperError for path '{0}'" . format ( path ) )