Пример #1
0
 def test_delete(self):
     RHESSysMetadata.writeRHESSysEntry(self.context, "key1", "value_one")
     RHESSysMetadata.writeRHESSysEntry(self.context, "key2", "value_two")
     metadata = RHESSysMetadata.readRHESSysEntries(self.context)
     self.assertTrue(metadata["key1"] == "value_one")
     RHESSysMetadata.deleteRHESSysEntry(self.context, "key1")
     metadata = RHESSysMetadata.readRHESSysEntries(self.context)
     self.assertTrue(not 'key1' in metadata)
     # Delete and empty entry
     RHESSysMetadata.deleteRHESSysEntry(self.context, "not_in_store")
Пример #2
0
 def test_delete(self):
     RHESSysMetadata.writeRHESSysEntry(self.context, "key1", "value_one")
     RHESSysMetadata.writeRHESSysEntry(self.context, "key2", "value_two")
     metadata = RHESSysMetadata.readRHESSysEntries(self.context)
     self.assertTrue(metadata["key1"] == "value_one")    
     RHESSysMetadata.deleteRHESSysEntry(self.context, "key1")
     metadata = RHESSysMetadata.readRHESSysEntries(self.context)
     self.assertTrue(not 'key1' in metadata)
     # Delete and empty entry
     RHESSysMetadata.deleteRHESSysEntry(self.context, "not_in_store")
     
    
    modelSrc = os.path.join(args.sourceDir, 'rhessys')
    if not os.path.exists(modelSrc) or not os.path.isdir(modelSrc):
        sys.exit("The specified path of the RHESSys source directory, %s, does not seem to contain RHESSys model source code in a directory called 'rhessys'" %
                 (args.sourceDir,) )
    
    # Delete paths.RHESSYS_SRC so that we can use shutil.copytree (which will recreate paths.RHESSYS_SRC)
    sys.stdout.write("Copying RHESSys source from %s..." % (args.sourceDir,) )
    sys.stdout.flush()
    shutil.rmtree(paths.RHESSYS_SRC)
    shutil.copytree(args.sourceDir, paths.RHESSYS_SRC)
    sys.stdout.write('done\n')
    # Write metadata
    RHESSysMetadata.writeRHESSysEntry(context, 'rhessys_src', os.path.abspath(args.sourceDir) )
    # Remove information about RHESSys if previously fetched from the Git repository 
    RHESSysMetadata.deleteRHESSysEntry(context, 'rhessys_branch')
    RHESSysMetadata.deleteRHESSysEntry(context, 'rhessys_tag')
    RHESSysMetadata.deleteRHESSysEntry(context, 'rhessys_sha')
    
else:   
    # Import from GitHub
    gitCommand = "%s clone %s %s" % (gitPath, RHESSYS_REPO_URL, paths.RHESSYS_SRC)
    sha1Identifier = 'HEAD'
    returnCode = os.system(gitCommand)
    if returnCode != 0:
        sys.exit("Git command '%s' failed." % (gitCommand, ) )
    # Write metadata
    RHESSysMetadata.writeRHESSysEntry(context, 'rhessys_src', RHESSYS_REPO_URL)
    
    if args.branch or args.tag:
        gitCommand = None
            # Convert raster to integer
            sys.stdout.write(
                "Converting %s raster to integer using multiplier %s...\n" %
                (t, str(args.multiplier)))
            sys.stdout.flush()
            mapcalcCmd = "%s=int(%s * %s)" % (t, importName,
                                              str(args.multiplier))
            print(mapcalcCmd)
            result = grassLib.script.write_command('r.mapcalc',
                                                   stdin=mapcalcCmd)
            if result != 0:
                sys.exit("Integer conversion failed for raster %s of GRASS dataset %s/%s, result:\n%s" % \
                         (t, grassDbase, metadata['grass_location'], result) )
            result = grassLib.script.run_command('g.remove', rast=importName)
            if result != 0:
                sys.exit("Failed to delete temporary raster %s of GRASS dataset %s/%s, result:\n%s" % \
                         (importName, grassDbase, metadata['grass_location'], result) )

        grassEntryKey = "%s_rast" % (t, )
        RHESSysMetadata.writeGRASSEntry(context, grassEntryKey, t)
        sys.stdout.write('done\n')
        # Invalidate metadata as necessary
        if t == RHESSysMetadata.RASTER_TYPE_LC:
            RHESSysMetadata.deleteRHESSysEntry(context, 'stratum_defs')
            RHESSysMetadata.deleteRHESSysEntry(context, 'landuse_defs')
        elif t == RHESSysMetadata.RASTER_TYPE_SOIL:
            RHESSysMetadata.deleteRHESSysEntry(context, 'soil_defs')

# Write processing history
RHESSysMetadata.appendProcessingHistoryItem(context, cmdline)
            if result != 0:
                sys.exit("Failed to resample imported raster %s of GRASS dataset %s/%s, result:\n%s" % \
                         (t, grassDbase, metadata['grass_location'], result) )
        if args.integer:
            # Convert raster to integer
            sys.stdout.write("Converting %s raster to integer using multiplier %s...\n" % (t, str(args.multiplier)) )
            sys.stdout.flush()
            mapcalcCmd = "%s=int(%s * %s)" % (t, importName, str(args.multiplier) )
            print(mapcalcCmd)
            result = grassLib.script.write_command('r.mapcalc', stdin=mapcalcCmd)
            if result != 0:
                sys.exit("Integer conversion failed for raster %s of GRASS dataset %s/%s, result:\n%s" % \
                         (t, grassDbase, metadata['grass_location'], result) )
            result = grassLib.script.run_command('g.remove', rast=importName)
            if result != 0:
                sys.exit("Failed to delete temporary raster %s of GRASS dataset %s/%s, result:\n%s" % \
                         (importName, grassDbase, metadata['grass_location'], result) )
        
        grassEntryKey = "%s_rast" % (t,)
        RHESSysMetadata.writeGRASSEntry(context, grassEntryKey, t)
        sys.stdout.write('done\n')
        # Invalidate metadata as necessary
        if t == RHESSysMetadata.RASTER_TYPE_LC:
            RHESSysMetadata.deleteRHESSysEntry(context, 'stratum_defs')
            RHESSysMetadata.deleteRHESSysEntry(context, 'landuse_defs')
        elif t == RHESSysMetadata.RASTER_TYPE_SOIL:
            RHESSysMetadata.deleteRHESSysEntry(context, 'soil_defs')

# Write processing history
RHESSysMetadata.appendProcessingHistoryItem(context, cmdline)
    if not os.path.exists(modelSrc) or not os.path.isdir(modelSrc):
        sys.exit(
            "The specified path of the RHESSys source directory, %s, does not seem to contain RHESSys model source code in a directory called 'rhessys'"
            % (args.sourceDir, ))

    # Delete paths.RHESSYS_SRC so that we can use shutil.copytree (which will recreate paths.RHESSYS_SRC)
    sys.stdout.write("Copying RHESSys source from %s..." % (args.sourceDir, ))
    sys.stdout.flush()
    shutil.rmtree(paths.RHESSYS_SRC)
    shutil.copytree(args.sourceDir, paths.RHESSYS_SRC)
    sys.stdout.write('done\n')
    # Write metadata
    RHESSysMetadata.writeRHESSysEntry(context, 'rhessys_src',
                                      os.path.abspath(args.sourceDir))
    # Remove information about RHESSys if previously fetched from the Git repository
    RHESSysMetadata.deleteRHESSysEntry(context, 'rhessys_branch')
    RHESSysMetadata.deleteRHESSysEntry(context, 'rhessys_tag')
    RHESSysMetadata.deleteRHESSysEntry(context, 'rhessys_sha')

else:
    # Import from GitHub
    gitCommand = "%s clone %s %s" % (gitPath, RHESSYS_REPO_URL,
                                     paths.RHESSYS_SRC)
    sha1Identifier = 'HEAD'
    returnCode = os.system(gitCommand)
    if returnCode != 0:
        sys.exit("Git command '%s' failed." % (gitCommand, ))
    # Write metadata
    RHESSysMetadata.writeRHESSysEntry(context, 'rhessys_src', RHESSYS_REPO_URL)

    if args.branch or args.tag: