Skip to content
Snippets Groups Projects
Commit 854b17c4 authored by Wouter Deconinck's avatar Wouter Deconinck
Browse files

Resolve "Allow for FileLoader to parse environment variables as part of the cache path"

parent 01e51f9f
No related branches found
No related tags found
2 merge requests!329Master into deathvalley,!319Resolve "Allow for FileLoader to parse environment variables as part of the cache path"
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
</documentation> </documentation>
<plugins> <plugins>
<plugin name="FileLoader"> <plugin name="FileLoader">
<arg value="cache:$DETECTOR_PATH"/>
<arg value="file:calibrations/materials-map.cbor"/> <arg value="file:calibrations/materials-map.cbor"/>
<arg value="url:https://eicweb.phy.anl.gov/EIC/detectors/athena/uploads/4a4e7c8eb6089b634d762d112c89bd5d/material-maps.cbor"/> <arg value="url:https://eicweb.phy.anl.gov/EIC/detectors/athena/uploads/4a4e7c8eb6089b634d762d112c89bd5d/material-maps.cbor"/>
</plugin> </plugin>
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <filesystem> #include <filesystem>
#include <iostream> #include <iostream>
#include <cstdlib>
#include <string> #include <string>
namespace fs = std::filesystem; namespace fs = std::filesystem;
...@@ -57,6 +58,24 @@ long load_file( ...@@ -57,6 +58,24 @@ long load_file(
return 0; return 0;
} }
// parse cache for environment variables
auto pos = std::string::npos;
while ((pos = cache.find('$')) != std::string::npos) {
auto after = cache.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789"
"_",
pos + 1);
if (after == std::string::npos) after = cache.size(); // cache ends on env var
auto env_name = cache.substr(pos + 1, after - pos - 1);
auto env_value = std::getenv(env_name.c_str());
if (env_value == nullptr) env_value = "";
cache.erase(pos, after - pos);
cache.insert(pos, env_value);
printout(INFO, "FileLoader", "$" + env_name + " -> " + env_value);
}
// create file path // create file path
fs::path file_path(file); fs::path file_path(file);
......
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