#NEWLINE# def read_stored_info( target , field = None , timestamped = False ) : #NEWLINE# #INDENT# 'Read information about an image.\n\n    Returns an empty dictionary if there is no info, just the field value if\n    a field is requested, or the entire dictionary otherwise.\n    ' #NEWLINE# info_file = get_info_filename ( target ) #NEWLINE# if ( not os . path . exists ( info_file ) ) : #NEWLINE# #INDENT# old_filename = ( target + '.sha1' ) #NEWLINE# if ( ( field == 'sha1' ) and os . path . exists ( old_filename ) ) : #NEWLINE# #INDENT# with open ( old_filename ) as hash_file : #NEWLINE# #INDENT# hash_value = hash_file . read ( ) #NEWLINE# #UNINDENT# write_stored_info ( target , field = field , value = hash_value ) #NEWLINE# os . remove ( old_filename ) #NEWLINE# d = { #NEWLINE# #INDENT# field : hash_value , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# d = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# lock_name = ( 'info-%s' % os . path . split ( target ) [ ( - 1 ) ] ) #NEWLINE# lock_path = os . path . join ( CONF . instances_path , 'locks' ) #NEWLINE# @ utils . synchronized ( lock_name , external = True , lock_path = lock_path ) #NEWLINE# def read_file( info_file ) : #NEWLINE# #INDENT# LOG . debug ( 'Reading image info file: %s' , info_file ) #NEWLINE# with open ( info_file , 'r' ) as f : #NEWLINE# #INDENT# return f . read ( ) . rstrip ( ) #NEWLINE# #UNINDENT# #UNINDENT# serialized = read_file ( info_file ) #NEWLINE# d = _read_possible_json ( old_filename , info_file ) #NEWLINE# #UNINDENT# if field : #NEWLINE# #INDENT# if timestamped : #NEWLINE# #INDENT# return ( d . get ( field , None ) , d . get ( ( '%s-timestamp' % field ) , None ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return d . get ( field , None ) #NEWLINE# #UNINDENT# #UNINDENT# return d