diff options
author | Ralph Amissah <ralph.amissah@gmail.com> | 2018-09-10 18:15:02 -0400 |
---|---|---|
committer | Ralph Amissah <ralph.amissah@gmail.com> | 2019-04-10 15:14:15 -0400 |
commit | e95c49b76f4ac7bf72c383ee43a0567dfcbf1603 (patch) | |
tree | b3aec9058f69be0047bb526052f8deefb5d97463 /src/doc_reform/source/read_config_files.d | |
parent | maker, subprojects arrange, minor (diff) |
0.1.0 renamed doc-reform, doc_reform (& rad)
- from sdp
Diffstat (limited to 'src/doc_reform/source/read_config_files.d')
-rw-r--r-- | src/doc_reform/source/read_config_files.d | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/src/doc_reform/source/read_config_files.d b/src/doc_reform/source/read_config_files.d new file mode 100644 index 0000000..fc5ce2f --- /dev/null +++ b/src/doc_reform/source/read_config_files.d @@ -0,0 +1,218 @@ +/++ + read configuration files<BR> + - read config files<BR> + meta_config_files.d ++/ +module doc_reform.source.read_config_files; +static template configReadInSiteTOML() { + import + doc_reform.meta, + doc_reform.source.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(pth.to!string, 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 + doc_reform.meta, + doc_reform.source.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(pth.to!string, 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 configTOML() { + import toml; // + import + doc_reform.meta, + doc_reform.source.paths_source, + std.file, + std.path; + 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 + doc_reform.meta, + doc_reform.source.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]) { + foreach(pth; possible_config_path_locations) { + auto conf_file = asNormalizedPath(chainPath(pth.to!string, 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 readConfigDoc() { + import + doc_reform.meta, + doc_reform.source.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]) { + foreach(pth; possible_config_path_locations) { + auto conf_file = asNormalizedPath(chainPath(pth.to!string, 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 configReadSiteTOML() { + import + doc_reform.meta, + doc_reform.source.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 + doc_reform.meta, + doc_reform.source.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; + } +} |