def readContext(self, fileInstance, **kw): """Get a dictionary of attribute/value pairs from an open file. Returns a dictionary of attribute/value pairs, which are added to the handler context. fileInstance Format handler instance representing the opened file, an instance of FormatHandler or a subclass. kw Optional keyword arguments. """ result = IPCC5Handler.readContext(self, fileInstance, **kw) # Extract the project-related metadata from file. # For example, if fileInstance is an instance of esgcet.config.CdunifFormatHandler, # to read the 'title' attribute from the file: # # f = fileInstance.file # if hasattr(f, 'title'): # result['title'] = f.title # Return the attribute/value dictionary return result
def readContext(self, fileInstance, **kw): """Get a dictionary of attribute/value pairs from an open file. Returns a dictionary of attribute/value pairs, which are added to the handler context. fileInstance Format handler instance representing the opened file, an instance of FormatHandler or a subclass. kw Optional keyword arguments. """ result = {} f = fileInstance.file result = IPCC5Handler.readContext(self, fileInstance, **kw) if 'project' not in result: result['project'] = self.name # Parse CMOR table. if hasattr(f, 'table_id'): tableId = getattr(f, 'table_id') fields = tableId.split() # Assume table ID has the form 'Table table_id ...' if len(fields) > 1: table = fields[1] result['cmor_table'] = table else: result['cmor_table'] = 'noTable' # Read categories as file attributes, for values not already set for category in self.getFieldNames(): if category not in result and hasattr(f, category): result[category] = getattr(f, category) # Check if mandatory fields are set if self.isMandatory(category) and category not in result: warning( "Mandatory category %s not set for file %s, use -p option?" % (category, fileInstance.path)) # Check validity self.validateContext(result) # Return the attribute/value dictionary return result
def readContext(self, fileInstance, **kw): """Get a dictionary of attribute/value pairs from an open file. Returns a dictionary of attribute/value pairs, which are added to the handler context. fileInstance Format handler instance representing the opened file, an instance of FormatHandler or a subclass. kw Optional keyword arguments. """ result = {} f = fileInstance.file result = IPCC5Handler.readContext(self, fileInstance, **kw) if 'project' not in result: result['project'] = self.name # Parse CMOR table. if hasattr(f, 'table_id'): tableId = getattr(f, 'table_id') fields = tableId.split() # Assume table ID has the form 'Table table_id ...' if len(fields)>1: table = fields[1] result['cmor_table'] = table else: result['cmor_table'] = 'noTable' # Read categories as file attributes, for values not already set for category in self.getFieldNames(): if category not in result and hasattr(f, category): result[category] = getattr(f, category) # Check if mandatory fields are set if self.isMandatory(category) and category not in result: warning("Mandatory category %s not set for file %s, use -p option?"%(category, fileInstance.path)) # Check validity self.validateContext(result) # Return the attribute/value dictionary return result