Skip to content
Snippets Groups Projects
Commit 762c7062 authored by Florian Atteneder's avatar Florian Atteneder
Browse files

dg1d: Avoid generating nested output folders in case parameter file comes from...

dg1d: Avoid generating nested output folders in case parameter file comes from inside an output folder (!192)
parent 065b6e57
No related branches found
No related tags found
1 merge request!192dg1d: Avoid generating nested output folders in case parameter file comes from inside an output folder
Pipeline #7101 passed
......@@ -27,19 +27,7 @@ using WriteVTK
include("sandbox.jl")
export # parameter handling
query, splitallext, trim_keys, match_keys, prepend_keys,
# type utils
concretetypes,
# parameter files and file system operations
mk_outputdir, dirname_path, flatten,
# get_parameter_file, get_parameter_file_index,
# select_parameter_files, gather_output_directories, gather_parameter_files,
match_properties,
# find_duplicated_parameter_files,
# run_projects, analyze_projects,
TODO, @TODO, @stringify_names,
indent
export TODO, @TODO
include("utils.jl")
export Cartoon, DoubleCartoon
......
......@@ -20,24 +20,10 @@ end
function normalize_parfile(filename)
path = if startswith(filename, r"@test/")
fname, ext = splitext(replace(filename, "@test/" => ""))
path = normpath(joinpath(@__DIR__, "..", "test", "IntegrationTests", "refs", fname, "$fname.toml"))
if !isfile(path)
error("failed to locate test parfile $path")
end
path
else
nr = tryparse(Int64, filename)
if !isnothing(nr)
return parse_parfile(nr)
end
filename
if !isfile(filename)
error("Cannot locate parameter file '$filename'")
end
if !isfile(path)
error("Cannot locate parameter file '$path'")
end
return abspath(path)
return filename
end
function normalize_parfile(nr::Integer)
testpars = get_testparfiles()
......@@ -46,7 +32,7 @@ function normalize_parfile(nr::Integer)
end
parfile = testpars[nr]
path = normpath(joinpath(@__DIR__, "..", "test", "IntegrationTests", "refs", parfile, "$parfile.toml"))
return abspath(path)
return path
end
......@@ -56,17 +42,32 @@ end
Run program specified by a `parfile` in TOML format.
"""
function main(parfile)
env, project, bdryconds, prms = setup_env(parfile)
# backup any previous output dir and setup a fresh one
# TODO Rename this to make_outputdir
outputdir = mk_outputdir(parfile)
cp(parfile, joinpath(outputdir, basename(parfile)))
parfile = abspath(parfile)
dir = dirname(parfile)
dummy_parfile = parfile
if basename(dir) == splitext(basename(parfile))[1]
# we are running parameter file contained in an output folder
# so we backup that folder and run the parameter file one directory above
dummy_parfile = string(dir, ".toml")
end
# backup any previous output dir and set up a fresh one
outputdir = make_outputdir(dummy_parfile)
if dummy_parfile != parfile
# we moved the initial parfile with the backup of the output folder
cp(joinpath(string(dir,".previous"),string(basename(dir),".toml")),
joinpath(outputdir, basename(parfile)))
else
cp(parfile, joinpath(outputdir, basename(parfile)))
end
cp(joinpath(@__DIR__,"..","Manifest.toml"), joinpath(outputdir,"Manifest.toml"))
open(joinpath(outputdir, "dirty"), "w") do file
println(file, "git commit hash: $(githash())")
println(file, '='^100)
println(file, gitdirty())
end
env, project, bdryconds, prms = setup_env(parfile)
rhs_fn, timestep_fn = setup_callbacks(env, project, bdryconds, prms, outputdir)
# TODO Use PrettyTables.jl for summary
# TODO Dump versioninfo() to some file
......
......@@ -181,7 +181,7 @@ Generate an output directory in root directory of `path`. Directory is only crea
If a folder with the same name is already present, then it is backed up by moving it
and appending .previous to its name.
"""
function mk_outputdir(path)
function make_outputdir(path)
path = abspath(path)
# analyze extensions
......
import dg1d: make_outputdir, flatten, dirname_path, query,
splitallext, trim_keys, match_keys, prepend_keys,
concretetypes, match_properties, indent
@testset "Utilities" begin
......@@ -256,7 +261,7 @@ end
## flatten dicts
nested_dict = Dict("d1"=>Dict("a"=>1, "b"=>2),
"d2"=>Dict("c"=>3, "d"=>4))
flattened_dict = dg1d.flatten(nested_dict)
flattened_dict = flatten(nested_dict)
expected = Dict( "d1.a" => 1, "d1.b" => 2, "d2.c" => 3, "d2.d" => 4)
@test flattened_dict == expected
......@@ -332,21 +337,21 @@ end
dummyparfiles = [ dummyparfile1, dummyparfile2 ]
for dp in dummyparfiles
path = mk_outputdir(dp)
path = dg1d.make_outputdir(dp)
@test isdir(path)
# call to already existing should generate a backup at $path.previous
path = mk_outputdir(dp)
path = dg1d.make_outputdir(dp)
path_previous = "$(path).previous"
@test isdir(path)
@test isdir(path_previous)
end
nofilethere = joinpath(dir, "nofilethere.toml")
@test_throws ErrorException mk_outputdir(nofilethere)
@test_throws ErrorException dg1d.make_outputdir(nofilethere)
wrongextensionfile = joinpath(dir, "wrongextension.toml.blabla")
touch(wrongextensionfile)
@test_throws ErrorException mk_outputdir(wrongextensionfile)
@test_throws ErrorException dg1d.make_outputdir(wrongextensionfile)
#### mock a project directory
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment