Skip to content
Snippets Groups Projects
Commit a23092d9 authored by Johannes Boog's avatar Johannes Boog
Browse files

[base] make file refs absolute when creating ogs6_obj from prj file

    When an ogs6_obj is created from a prj file, the prj file may contain
    references to external files. This makes shure file references (gml,
    meshes, dat, py) have absolute paths. Then it is more easy to handle
    file references when sim_path and prj_path differ.
parent cf49903a
No related branches found
No related tags found
1 merge request!41standardize files references during prj import/export (new MR)
......@@ -19,9 +19,11 @@ read_in_prj <- function(ogs6_obj,
read_in_vtu = FALSE){
assertthat::assert_that("OGS6" %in% class(ogs6_obj))
assertthat::assert_that(assertthat::is.string(prj_path))
assertthat::assert_that(assertthat::is.flag(read_in_vtu))
xml_doc <- validate_read_in_xml(prj_path)
assertthat::assert_that(assertthat::is.flag(read_in_vtu))
prj_base_path <- dirname(prj_path)
# Geometry reference
gml_ref_node <- xml2::xml_find_first(xml_doc, "/OpenGeoSysProject/geometry")
......@@ -30,8 +32,9 @@ read_in_prj <- function(ogs6_obj,
vtu_ref_nodes <- NULL
if(!any(grepl("xml_missing", class(gml_ref_node), fixed = TRUE))){
gml_path <- paste0(dirname(prj_path), "/",
xml2::xml_text(gml_ref_node))
gml_path <- xml2::xml_text(gml_ref_node)
gml_path <- make_abs_path(gml_path, prj_base_path)
# If read_in_gml isn't supplied, check number of lines in .gml file
# since string concatenation is slow
......@@ -56,7 +59,8 @@ read_in_prj <- function(ogs6_obj,
for(i in seq_along(vtu_ref_nodes)){
vtu_ref <- xml2::xml_text(vtu_ref_nodes[[i]])
vtu_path <- paste0(dirname(prj_path), "/", vtu_ref)
vtu_path <- make_abs_path(vtu_ref, prj_base_path)
# vtu_path <- paste0(dirname(prj_path), "/", vtu_ref)
axisym_val <- xml2::xml_attr(vtu_ref_nodes[[i]], "axially_symmetric")
......@@ -74,38 +78,35 @@ read_in_prj <- function(ogs6_obj,
prj_components <- ogs6_prj_top_level_classes()
# Include file reference
# Read include file reference
processes_include_node <-
xml2::xml_find_first(xml_doc,
"/OpenGeoSysProject/processes/include")
if(!any(grepl("xml_missing", class(processes_include_node), fixed = TRUE))){
file_reference <- xml2::xml_attrs(processes_include_node)[["file"]]
if(grepl("^\\.\\.", file_reference)){
file_reference <- gsub("^\\.\\.", "", file_reference)
file_reference <- paste0(dirname(dirname(prj_path)), file_reference)
}else{
file_reference <- paste0(dirname(prj_path), "/", file_reference)
}
file_reference <- make_abs_path(file_reference, prj_base_path)
ogs6_obj$processes <- file_reference
prj_components <- prj_components[names(prj_components) != "processes"]
}
# Check for python script
# Read python script references
python_script_node <-
xml2::xml_find_first(xml_doc,
"/OpenGeoSysProject/python_script")
if(!any(grepl("xml_missing", class(python_script_node), fixed = TRUE))){
ogs6_obj$python_script <- xml2::xml_text(python_script_node)
python_script_path <- xml2::xml_text(python_script_node)
python_script_path <- make_abs_path(python_script_path, prj_base_path)
ogs6_obj$python_script <- python_script_path
}
prj_components <-
prj_components[names(prj_components) != "python_script"]
# read additional prj file tags
for(i in seq_len(length(prj_components))){
class_tag_name <- get_tag_from_class(prj_components[[i]])
......@@ -121,4 +122,12 @@ read_in_prj <- function(ogs6_obj,
class_tag_name))
}
}
# update file references in wrapper lists of created ogs6_obj
if(!is.null(ogs6_obj$chemical_system)){
dbase_path <- ogs6_obj$chemical_system$database
ogs6_obj$chemical_system$database <- make_abs_path(dbase_path,
prj_base_path)
}
}
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