From 2731b33fe2d05fe3ebc3e2f98d39eacf7295d1e4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 16 Nov 2019 12:16:08 -0500 Subject: module & src renaming --- src/doc_reform/io_in/read_config_files.d | 155 +++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/doc_reform/io_in/read_config_files.d (limited to 'src/doc_reform/io_in/read_config_files.d') diff --git a/src/doc_reform/io_in/read_config_files.d b/src/doc_reform/io_in/read_config_files.d new file mode 100644 index 0000000..c0893de --- /dev/null +++ b/src/doc_reform/io_in/read_config_files.d @@ -0,0 +1,155 @@ +/++ + read configuration files
+ - read config files
+ meta_config_files.d ++/ +module doc_reform.io_in.read_config_files; + +static template readConfigSite() { + import + doc_reform.meta.rgx; + import + doc_reform.meta, + doc_reform.io_in.paths_source, + std.file, + std.path; + mixin spineRgxInit; + final auto readConfigSite(M,E)( + M _manifested, + E _env, + string _cli_config_path_set = "" + ) { + static auto rgx = Rgx(); + string config_file_str; + string conf_filename = "NONE"; + auto _conf_file_details = ConfigFilePaths!()(_manifested, _env, _cli_config_path_set); + string[] possible_config_path_locations = _conf_file_details.possible_config_path_locations.config_local_site; + foreach(conf_fn; [_conf_file_details.config_filename_site]) { + foreach(pth; possible_config_path_locations) { + char[] conf_file; + conf_filename = conf_fn; + if (exists(pth)) { + auto f_attrib = pth.getLinkAttributes; + if ( + possible_config_path_locations.length == 1 + && f_attrib.attrIsFile + ) { + conf_file = pth.to!(char[]); + conf_filename = pth.baseName; + } else if (f_attrib.attrIsDir) { + conf_file = ((chainPath(pth.to!string, conf_fn)).asNormalizedPath).array; + conf_filename = conf_fn; + } + try { + if (exists(conf_file)) { + if (conf_file.getLinkAttributes.attrIsFile) { + 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() { + string _ft = ""; + if (content.match(rgx.yaml_config)) { + _ft = "yaml"; + } + return _ft; + } + string content() { + return config_file_str; + } + } + return _ConfContent(); + } +} +static template readConfigDoc() { + import + doc_reform.meta.rgx; + import + doc_reform.meta, + doc_reform.io_in.paths_source, + std.file, + std.path; + mixin spineRgxInit; + final auto readConfigDoc(M,E)(M _manifested, E _env) { + static auto rgx = Rgx(); + string config_file_str; + string conf_filename = "NONE"; + auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); + string[] possible_config_path_locations = _conf_file_details.possible_config_path_locations.dr_document_make; + foreach(conf_fn; [_conf_file_details.config_filename_document]) { + foreach(pth; possible_config_path_locations) { + auto conf_file = ((chainPath(pth.to!string, conf_fn)).asNormalizedPath).array; + conf_filename = conf_fn; + if (config_file_str.length > 0) { + break; + } + try { + if (exists(conf_file)) { + if (conf_file.getLinkAttributes.attrIsFile) { + 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 content() { + return config_file_str; + } + string filetype() { + string _ft = ""; + if (content.match(rgx.yaml_config)) { + _ft = "yaml"; + } + return _ft; + } + } + return _ConfContent(); + } +} +static template configReadSiteYAML() { + import + doc_reform.meta, + doc_reform.io_in.paths_source, + std.file, + std.path; + final YAMLDocument configReadSiteYAML(M,E)(M _manifested, E _env) { + string _configuration = configReadInSiteYAML!()(_manifested, _env); + auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); + string _conf_yaml_fn = _conf_file_details.config_filename_site; + YAMLDocument _yaml_conf = configYAML!()(_configuration, _conf_yaml_fn); + return _yaml_conf; + } +} +static template configReadDocYAML() { + import + doc_reform.meta, + doc_reform.io_in.paths_source, + std.file, + std.path; + final YAMLDocument configReadDocYAML(M,E)(M _manifested, E _env) { + string _configuration = configReadInDocYAML!()(_manifested, _env); + auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); + string _conf_yaml_fn = _conf_file_details.config_filename_document; + YAMLDocument _yaml_conf = configYAML!()(_configuration, _conf_yaml_fn); + return _yaml_conf; + } +} -- cgit v1.2.3