def getContext(self, **context): """ Read all metadata fields from the file associated with the handler. Typically this is the first file encountered in processing. The assumption is that all files contain the global metadata to be associated with the project. The file path is in self.path, and may be changed if necessary. Calls ``readContext`` to read the file. Returns a context dictionary of fields discovered in the file. context Dictionary of initial field values, keyed on field names. If a field is initialized, it is not overwritten. """ # If the first processed file does not contain the correct metadata, # reset self.path to the correct path # # self.path = the_correct_metadata_file_path # # Call readContext to read the metadata into self.context IPCC5Handler.getContext(self, **context) # Add attribute/value pairs not contained in the file. For example, # to add an attribute 'creation_time' whose value is the current time (string): # # if self.context.get('creation_time', '')=='': # self.context['creation_time'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") # Return the context dictionary return self.context
def getContext(self, **context): """ Read all metadata fields from the file associated with the handler. Typically this is the first file encountered in processing. The assumption is that all files contain the global metadata to be associated with the project. The file path is in self.path, and may be changed if necessary. Calls ``readContext`` to read the file. Returns a context dictionary of fields discovered in the file. context Dictionary of initial field values, keyed on field names. If a field is initialized, it is not overwritten. """ # If the first processed file does not contain the correct metadata, # reset self.path to the correct path # # self.path = the_correct_metadata_file_path # # Call readContext to read the metadata into self.context IPCC5Handler.getContext(self, **context) # Add attribute/value pairs not contained in the file. For example, # to add an attribute 'creation_time' whose value is the current time (string): # # if self.context.get('creation_time', '')=='': # self.context['creation_time'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") # Return the context dictionary return self.context
def getContext(self, **context): """ Read all metadata fields from the file associated with the handler. Typically this is the first file encountered in processing. The assumption is that all files contain the global metadata to be associated with the project. The file path is in self.path, and may be changed if necessary. Calls ``readContext`` to read the file. Returns a context dictionary of fields discovered in the file. context Dictionary of initial field values, keyed on field names. If a field is initialized, it is not overwritten. """ IPCC5Handler.getContext(self, **context) return self.context
def getContext(self, **context): """ Read all metadata fields from the file associated with the handler. Typically this is the first file encountered in processing. The assumption is that all files contain the global metadata to be associated with the project. The file path is in self.path, and may be changed if necessary. Calls ``readContext`` to read the file. Returns a context dictionary of fields discovered in the file. context Dictionary of initial field values, keyed on field names. If a field is initialized, it is not overwritten. """ IPCC5Handler.getContext(self, **context) return self.context
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 = 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