#NEWLINE# @ staticmethod #NEWLINE# def _extract_from_file( file_pattern , file_description , extract_function ) : #NEWLINE# #INDENT# 'Extract metadata from a file.\n\n        Returns the result of running extract_function on the opened\n        file, or None if the file cannot be found. file_pattern is a\n        glob pattern for the file: the first file found is used.\n        file_description is a description of the file for logging and\n        error messages.' #NEWLINE# try : #NEWLINE# #INDENT# md_path = glob . glob ( file_pattern ) [ 0 ] #NEWLINE# md_file = open ( md_path ) #NEWLINE# metadata = extract_function ( md_file ) #NEWLINE# md_file . close ( ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# metadata = None #NEWLINE# LOGGER . debug ( 'No %s file found.' , file_description ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# raise DatasetError ( ( 'Unable to open %s file.' % file_description ) ) #NEWLINE# #UNINDENT# return metadata