aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/meta/read_config_files.d
blob: 554f740cea8ef96ee7fe9acad1d40a63f4831f37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/++
  read configuration files<BR>
  - read config files<BR>
  meta_config_files.d
+/
module sdp.meta.read_config_files;
static template configReadInSiteSDL() {
  import
    sdp.meta,
    sdp.output.paths_source,
    std.file,
    std.path;
  final string configReadInSiteSDL(M,E)(M manifest, E env) {
    auto conf_file_details = ConfigFilePaths!()(manifest, env);
    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);
      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_sdl)).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 configReadInDocSDL() {
  import
    sdp.meta,
    sdp.output.paths_source,
    std.file,
    std.path;
  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_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);
      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_sdl)).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 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) {
    Tag sdl_root_conf;
    try {
      sdl_root_conf = parseSource(configuration);
    }
    catch(ParseException e) {
      stderr.writeln("SDLang problem with content for ", conf_sdl_filename);
      stderr.writeln(e.msg);
    }
    return sdl_root_conf;
  }
}
static template configTOML() {
  import toml; //
  import
    sdp.meta,
    sdp.output.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
    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.config_filename_site_sdl;
    auto sdl_root = configSDLang!()(configuration, conf_sdl);
    return sdl_root;
  }
}
static template configReadDocSDLang() {
  import
    sdp.meta,
    sdp.output.paths_source,
    std.file,
    std.path;
  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_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;
  }
}