#NEWLINE# def watch( self , key , recurse = False , timeout = 0 , index = None ) : #NEWLINE# #INDENT# ret = { #NEWLINE# #INDENT# 'key' : key , #NEWLINE# 'value' : None , #NEWLINE# 'changed' : False , #NEWLINE# 'mIndex' : 0 , #NEWLINE# 'dir' : False , #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# result = self . read ( key , recursive = recurse , wait = True , timeout = timeout , waitIndex = index ) #NEWLINE# #UNINDENT# except EtcdUtilWatchTimeout : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# result = self . read ( key ) #NEWLINE# #UNINDENT# except etcd . EtcdKeyNotFound : #NEWLINE# #INDENT# log . debug ( 'etcd: key was not created while watching' ) #NEWLINE# return ret #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( result and getattr ( result , 'dir' ) ) : #NEWLINE# #INDENT# ret [ 'dir' ] = True #NEWLINE# #UNINDENT# ret [ 'value' ] = getattr ( result , 'value' ) #NEWLINE# ret [ 'mIndex' ] = getattr ( result , 'modifiedIndex' ) #NEWLINE# return ret #NEWLINE# #UNINDENT# except ( etcd . EtcdConnectionFailed , MaxRetryError ) : #NEWLINE# #INDENT# log . error ( "etcd: failed to perform 'watch' operation on key {0} due to connection error" . format ( key ) ) #NEWLINE# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if recurse : #NEWLINE# #INDENT# ret [ 'key' ] = getattr ( result , 'key' , None ) #NEWLINE# #UNINDENT# ret [ 'value' ] = getattr ( result , 'value' , None ) #NEWLINE# ret [ 'dir' ] = getattr ( result , 'dir' , None ) #NEWLINE# ret [ 'changed' ] = True #NEWLINE# ret [ 'mIndex' ] = getattr ( result , 'modifiedIndex' ) #NEWLINE# return ret