aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/meta/read_config_files.d
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2018-02-09 22:03:10 -0500
committerRalph Amissah <ralph@amissah.com>2019-04-10 15:14:14 -0400
commit1c73ddf3894085c646b55d63e61a2483e03a3b4d (patch)
tree34e3a837d0e0d224008ff380055ea263a03d3c14 /src/sdp/meta/read_config_files.d
parentpaths, further adjustments (diff)
0.24.0 toml or sdlang for configuration
Diffstat (limited to 'src/sdp/meta/read_config_files.d')
-rw-r--r--src/sdp/meta/read_config_files.d271
1 files changed, 244 insertions, 27 deletions
diff --git a/src/sdp/meta/read_config_files.d b/src/sdp/meta/read_config_files.d
index 15a7a67..554f740 100644
--- a/src/sdp/meta/read_config_files.d
+++ b/src/sdp/meta/read_config_files.d
@@ -4,16 +4,16 @@
meta_config_files.d
+/
module sdp.meta.read_config_files;
-static template configInSite() {
+static template configReadInSiteSDL() {
import
sdp.meta,
sdp.output.paths_source,
std.file,
std.path;
- final string configInSite(M,E)(M manifest, E env) {
+ final string configReadInSiteSDL(M,E)(M manifest, E env) {
auto conf_file_details = ConfigFilePaths!()(manifest, env);
- string conf_sdl = conf_file_details.possible_config_path_locations.config_filename_site;
- auto possible_config_path_locations = conf_file_details.possible_config_path_locations.local_site;
+ string conf_sdl = conf_file_details.config_filename_site_sdl;
+ auto possible_config_path_locations = conf_file_details.possible_config_path_locations.config_local_site;
string config_file_str;
debug(io) {
writeln("WARNING (io debug) in config filename: ", conf_sdl);
@@ -41,16 +41,16 @@ static template configInSite() {
return config_file_str;
}
}
-static template configInDoc() {
+static template configReadInDocSDL() {
import
sdp.meta,
sdp.output.paths_source,
std.file,
std.path;
- final string configInDoc(M,E)(M manifest, E env) {
+ final string configReadInDocSDL(M,E)(M manifest, E env) {
auto conf_file_details = ConfigFilePaths!()(manifest, env);
- string conf_sdl = conf_file_details.config_filename_document;
- auto possible_config_path_locations = conf_file_details.possible_config_path_locations.document;
+ string conf_sdl = conf_file_details.config_filename_document_sdl;
+ auto possible_config_path_locations = conf_file_details.possible_config_path_locations.sisu_document_make;
string config_file_str;
debug(io) {
writeln("WARNING (io debug) in config filename: ", conf_sdl);
@@ -78,17 +78,88 @@ static template configInDoc() {
return config_file_str;
}
}
-/+
-
-+/
-static template ConfigSDLang() {
+static template configReadInSiteTOML() {
+ import
+ sdp.meta,
+ sdp.output.paths_source,
+ std.file,
+ std.path;
+ final string configReadInSiteTOML(M,E)(M manifest, E env) {
+ auto conf_file_details = ConfigFilePaths!()(manifest, env);
+ string conf_toml = conf_file_details.config_filename_site_toml;
+ auto possible_config_path_locations = conf_file_details.possible_config_path_locations.config_local_site;
+ string config_file_str;
+ debug(io) {
+ writeln("WARNING (io debug) in config filename: ", conf_toml);
+ writeln("WARNING (io debug) in config possible path locations: ", possible_config_path_locations);
+ }
+ foreach(pth; possible_config_path_locations) {
+ auto conf_file = asNormalizedPath(chainPath(to!string(pth), conf_toml)).array;
+ if (config_file_str.length > 0) {
+ break;
+ }
+ try {
+ if (exists(conf_file)) {
+ debug(io) {
+ writeln("WARNING (io debug) in config file found: ", conf_file);
+ }
+ config_file_str = conf_file.readText;
+ break;
+ }
+ }
+ catch (ErrnoException ex) {
+ }
+ catch (FileException ex) {
+ }
+ }
+ return config_file_str;
+ }
+}
+static template configReadInDocTOML() {
+ import
+ sdp.meta,
+ sdp.output.paths_source,
+ std.file,
+ std.path;
+ final string configReadInDocTOML(M,E)(M manifest, E env) {
+ auto conf_file_details = ConfigFilePaths!()(manifest, env);
+ string conf_toml = conf_file_details.config_filename_document_toml;
+ auto possible_config_path_locations = conf_file_details.possible_config_path_locations.sisu_document_make;
+ string config_file_str;
+ debug(io) {
+ writeln("WARNING (io debug) in config filename: ", conf_toml);
+ writeln("WARNING (io debug) in config possible path locations: ", possible_config_path_locations);
+ }
+ foreach(pth; possible_config_path_locations) {
+ auto conf_file = asNormalizedPath(chainPath(to!string(pth), conf_toml)).array;
+ if (config_file_str.length > 0) {
+ break;
+ }
+ try {
+ if (exists(conf_file)) {
+ debug(io) {
+ writeln("WARNING (io debug) in config file found: ", conf_file);
+ }
+ config_file_str = conf_file.readText;
+ break;
+ }
+ }
+ catch (ErrnoException ex) {
+ }
+ catch (FileException ex) {
+ }
+ }
+ return config_file_str;
+ }
+}
+static template configSDLang() {
import sdlang;
import
sdp.meta,
sdp.output.paths_source,
std.file,
std.path;
- auto ConfigSDLang(string configuration, string conf_sdl_filename) {
+ auto configSDLang(string configuration, string conf_sdl_filename) {
Tag sdl_root_conf;
try {
sdl_root_conf = parseSource(configuration);
@@ -100,35 +171,181 @@ static template ConfigSDLang() {
return sdl_root_conf;
}
}
-/+
-+/
-static template configReadSite() {
+static template configTOML() {
+ import toml; //
import
sdp.meta,
sdp.output.paths_source,
std.file,
std.path;
-
- final auto configReadSite(M,E)(M manifest, E env) {
- auto configuration = configInSite!()(manifest, env);
+ auto configTOML(string configuration, string conf_toml_filename) {
+ TOMLDocument _toml_conf;
+ try {
+ _toml_conf = parseTOML(configuration); // parseTOML(cast(string)(configuration));
+ }
+ catch(ErrnoException e) {
+ stderr.writeln("Toml problem with content for ", conf_toml_filename);
+ stderr.writeln(e.msg);
+ }
+ return _toml_conf;
+ }
+}
+static template readConfigSite() {
+ import
+ sdp.meta,
+ sdp.output.paths_source,
+ std.file,
+ std.path;
+ final auto readConfigSite(M,E)(M _manifest, E _env) {
+ string config_file_str;
+ string conf_filename = "NONE";
+ auto _conf_file_details = ConfigFilePaths!()(_manifest, _env);
+ auto possible_config_path_locations = _conf_file_details.possible_config_path_locations.config_local_site;
+ foreach(conf_fn; [_conf_file_details.config_filename_site_toml, _conf_file_details.config_filename_site_sdl]) {
+ foreach(pth; possible_config_path_locations) {
+ auto conf_file = asNormalizedPath(chainPath(to!string(pth), conf_fn)).array;
+ conf_filename = conf_fn;
+ if (config_file_str.length > 0) {
+ // conf_filename = conf_fn;
+ break;
+ }
+ try {
+ if (exists(conf_file)) {
+ debug(io) {
+ writeln("WARNING (io debug) in config file found: ", conf_file);
+ // writeln(__LINE__, ": found: ", conf_file, " in ", pth);
+ }
+ config_file_str = conf_file.readText;
+ break;
+ }
+ }
+ catch (ErrnoException ex) {
+ }
+ catch (FileException ex) {
+ }
+ }
+ if (config_file_str.length > 0) { break; }
+ }
+ struct _ConfContent {
+ string filename() {
+ return conf_filename;
+ }
+ string filetype() {
+ return conf_filename.extension.chompPrefix(".");
+ }
+ auto content() {
+ return config_file_str;
+ }
+ }
+ return _ConfContent();
+ }
+}
+static template readConfigDoc() {
+ import
+ sdp.meta,
+ sdp.output.paths_source,
+ std.file,
+ std.path;
+ final auto readConfigDoc(M,E)(M _manifest, E _env) {
+ string config_file_str;
+ string conf_filename = "NONE";
+ auto _conf_file_details = ConfigFilePaths!()(_manifest, _env);
+ auto possible_config_path_locations = _conf_file_details.possible_config_path_locations.sisu_document_make;
+ foreach(conf_fn; [_conf_file_details.config_filename_document_toml, _conf_file_details.config_filename_document_sdl]) {
+ foreach(pth; possible_config_path_locations) {
+ auto conf_file = asNormalizedPath(chainPath(to!string(pth), conf_fn)).array;
+ conf_filename = conf_fn;
+ if (config_file_str.length > 0) {
+ // conf_filename = conf_fn;
+ break;
+ }
+ try {
+ if (exists(conf_file)) {
+ debug(io) {
+ writeln("WARNING (io debug) in config file found: ", conf_file);
+ }
+ config_file_str = conf_file.readText;
+ break;
+ }
+ }
+ catch (ErrnoException ex) {
+ }
+ catch (FileException ex) {
+ }
+ }
+ if (config_file_str.length > 0) { break; }
+ }
+ struct _ConfContent {
+ string filename() {
+ return conf_filename;
+ }
+ string filetype() {
+ return conf_filename.extension.chompPrefix(".");
+ }
+ auto content() {
+ return config_file_str;
+ }
+ }
+ return _ConfContent();
+ }
+}
+static template configReadSiteSDLang() {
+ import
+ sdp.meta,
+ sdp.output.paths_source,
+ std.file,
+ std.path;
+ import sdlang;
+ final auto configReadSiteSDLang(M,E)(M manifest, E env) {
+ auto configuration = configReadInSiteSDL!()(manifest, env);
auto conf_file_details = ConfigFilePaths!()(manifest, env);
- string conf_sdl = conf_file_details.possible_config_path_locations.config_filename_site;
- auto sdl_root = ConfigSDLang!()(configuration, conf_sdl);
+ string conf_sdl = conf_file_details.config_filename_site_sdl;
+ auto sdl_root = configSDLang!()(configuration, conf_sdl);
return sdl_root;
}
}
-static template configReadDoc() {
+static template configReadDocSDLang() {
import
sdp.meta,
sdp.output.paths_source,
std.file,
std.path;
-
- final auto configReadDoc(M,E)(M manifest, E env) {
- auto configuration = configInDoc!()(manifest, env);
+ import sdlang;
+ final auto configReadDocSDLang(M,E)(M manifest, E env) {
+ auto configuration = configReadInDocSDL!()(manifest, env);
auto conf_file_details = ConfigFilePaths!()(manifest, env);
- string conf_sdl = conf_file_details.config_filename_document;
- auto sdl_root = ConfigSDLang!()(configuration, conf_sdl);
+ string conf_sdl = conf_file_details.config_filename_document_sdl;
+ auto sdl_root = configSDLang!()(configuration, conf_sdl);
return sdl_root;
}
}
+static template configReadSiteTOML() {
+ import
+ sdp.meta,
+ sdp.output.paths_source,
+ std.file,
+ std.path;
+ import toml;
+ final auto configReadSiteTOML(M,E)(M _manifest, E _env) {
+ auto _configuration = configReadInSiteTOML!()(_manifest, _env);
+ auto _conf_file_details = ConfigFilePaths!()(_manifest, _env);
+ string _conf_toml = _conf_file_details.config_filename_site_toml;
+ auto _toml_conf = configTOML!()(_configuration, _conf_toml);
+ return _toml_conf;
+ }
+}
+static template configReadDocTOML() {
+ import
+ sdp.meta,
+ sdp.output.paths_source,
+ std.file,
+ std.path;
+ import toml;
+ final auto configReadDocTOML(M,E)(M _manifest, E _env) {
+ auto _configuration = configReadInDocTOML!()(_manifest, _env);
+ auto _conf_file_details = ConfigFilePaths!()(_manifest, _env);
+ string _conf_toml = _conf_file_details.config_filename_document_toml;
+ auto _toml_conf = configTOML!()(_configuration, _conf_toml);
+ return _toml_conf;
+ }
+}