Example #1
0
 def test_check_metadata_version(self):
     """ Test check metadata version """       
     step1 = "mkdir foo; cd foo"
     
     GenericMetadata.appendProcessingHistoryItem(self.context, step1)
     GenericMetadata.checkMetadataVersion(self.context.projectDir)
     # For testing purposes only, users should not modify 
     #   GenericMetadata._ecohydrolibVersion
     _prevVersion = GenericMetadata._ecohydrolibVersion
     GenericMetadata._ecohydrolibVersion = '11'
     caughtMetadataVersionError = False
     try:
         GenericMetadata.checkMetadataVersion(self.context.projectDir)
     except MetadataVersionError:
         caughtMetadataVersionError = True
     self.assertTrue(caughtMetadataVersionError, "Expected metadata version mismatch, but none found.")
     GenericMetadata._ecohydrolibVersion = _prevVersion
     
     
Example #2
0
 def __init__(self, projectDir, configFile=None):
     """ Constructor for Context class
     
         @param projectDir Path of the project whose metadata store is to be read from
         @param configFile Path of ecohydrolib configuration file to use.  If none,
         will attempt to read configuration from a file named in the environment
         variable Context.CONFIG_FILE_ENV
         
         @raise IOError if project directory path is not a directory
         @raise IOError if project directory is not writable
         @raise MetadataVersionError if a version already exists in the 
         metadata store and is different than GenericMetadata._ecohydrolibVersion
         @raise EnvironmentError if configuration file name could not be read from the 
         environment
         @raise IOError if configuration file could not be read
     """
     if not os.path.isdir(projectDir):
         raise IOError(errno.ENOTDIR, "Specified project directory %s is not a directory" % \
                       (projectDir,))
     if not os.access(projectDir, os.W_OK):
         raise IOError(errno.EACCES, "Unable to write to project directory %s" % \
                       (projectDir,))
     self.projectDir = os.path.abspath(projectDir)
     
     # Make sure metadata version is compatible with this version of ecohydrolib
     #   will raise MetadataVersionError if there is a version mismatch
     GenericMetadata.checkMetadataVersion(projectDir)
     
     if not configFile:
         try:
             self._configFile = os.environ[CONFIG_FILE_ENV]
         except KeyError:
             raise EnvironmentError("Configuration file not specified via environmental variable %s" %\
                                    CONFIG_FILE_ENV)
     else:
         self._configFile = configFile
     
     if not os.access(self._configFile, os.R_OK):
         raise IOError(errno.EACCES, "Unable to read configuration file %s" %
                       self._configFile)
     self.config = ConfigParser.RawConfigParser()
     self.config.read(self._configFile)
Example #3
0
 def __init__(self, projectDir, configFile=None):
     """ Constructor for Context class
     
         @param projectDir Path of the project whose metadata store is to be read from
         @param configFile Path of ecohydrolib configuration file to use.  If none,
         will attempt to read configuration from a file named in the environment
         variable Context.CONFIG_FILE_ENV
         
         @raise IOError if project directory path is not a directory
         @raise IOError if project directory is not writable
         @raise MetadataVersionError if a version already exists in the 
         metadata store and is different than GenericMetadata._ecohydrolibVersion
         @raise EnvironmentError if configuration file name could not be read from the 
         environment
         @raise IOError if configuration file could not be read
     """
     if not os.path.isdir(projectDir):
         raise IOError(errno.ENOTDIR, "Specified project directory %s is not a directory" % \
                       (projectDir,))
     if not os.access(projectDir, os.W_OK):
         raise IOError(errno.EACCES, "Unable to write to project directory %s" % \
                       (projectDir,))
     self.projectDir = os.path.abspath(projectDir)
     
     # Make sure metadata version is compatible with this version of ecohydrolib
     #   will raise MetadataVersionError if there is a version mismatch
     GenericMetadata.checkMetadataVersion(projectDir)
     
     if not configFile:
         try:
             self._configFile = os.environ[CONFIG_FILE_ENV]
         except KeyError:
             raise EnvironmentError("Configuration file not specified via environmental variable %s" %\
                                    CONFIG_FILE_ENV)
     else:
         self._configFile = configFile
     
     if not os.access(self._configFile, os.R_OK):
         raise IOError(errno.EACCES, "Unable to read configuration file %s" %
                       self._configFile)
     self.config = configparser.RawConfigParser()
     self.config.read(self._configFile)