Comparison

tools/cfgdump.lua @ 11569:08dab7df152b

tools/cfgdump: Iterate in sort order to give stable output Should allow using this tool for comparing configs without hash table order messing things up.
author Kim Alvefur <zash@zash.se>
date Mon, 17 May 2021 16:33:44 +0200
parent 11192:11f285a439a4
child 11570:c3896c714a83
comparison
equal deleted inserted replaced
11568:d5360307a99d 11569:08dab7df152b
2 2
3 -- cfgdump.lua prosody.cfg.lua [[host] option] 3 -- cfgdump.lua prosody.cfg.lua [[host] option]
4 4
5 local s_format, print = string.format, print; 5 local s_format, print = string.format, print;
6 local printf = function(fmt, ...) return print(s_format(fmt, ...)); end 6 local printf = function(fmt, ...) return print(s_format(fmt, ...)); end
7 local it = require "util.iterators";
7 local serialization = require"util.serialization"; 8 local serialization = require"util.serialization";
8 local serialize = serialization.new and serialization.new({ unquoted = true }) or serialization.serialize; 9 local serialize = serialization.new and serialization.new({ unquoted = true }) or serialization.serialize;
9 local configmanager = require"core.configmanager"; 10 local configmanager = require"core.configmanager";
10 local startup = require "util.startup"; 11 local startup = require "util.startup";
11 12
35 end 36 end
36 37
37 local config = configmanager.getconfig(); 38 local config = configmanager.getconfig();
38 39
39 40
40 for host, hostcfg in pairs(config) do 41 for host, hostcfg in it.sorted_pairs(config) do
41 local fixed = {}; 42 local fixed = {};
42 for option, value in pairs(hostcfg) do 43 for option, value in it.sorted_pairs(hostcfg) do
43 fixed[option] = value; 44 fixed[option] = value;
44 if option:match("ports?$") or option:match("interfaces?$") then 45 if option:match("ports?$") or option:match("interfaces?$") then
45 if option:match("s$") then 46 if option:match("s$") then
46 if type(value) ~= "table" then 47 if type(value) ~= "table" then
47 fixed[option] = { value }; 48 fixed[option] = { value };
59 60
60 local globals = config["*"]; config["*"] = nil; 61 local globals = config["*"]; config["*"] = nil;
61 62
62 local function printsection(section) 63 local function printsection(section)
63 local out, n = {}, 1; 64 local out, n = {}, 1;
64 for k,v in pairs(section) do 65 for k,v in it.sorted_pairs(section) do
65 out[n], n = s_format("%s = %s", k, serialize(v)), n + 1; 66 out[n], n = s_format("%s = %s", k, serialize(v)), n + 1;
66 end 67 end
67 table.sort(out); 68 table.sort(out);
68 print(table.concat(out, "\n")); 69 print(table.concat(out, "\n"));
69 end 70 end
77 78
78 local has_components = nil; 79 local has_components = nil;
79 80
80 print("------------------------ Virtual hosts -------------------------"); 81 print("------------------------ Virtual hosts -------------------------");
81 82
82 for host, hostcfg in pairs(config) do 83 for host, hostcfg in it.sorted_pairs(config) do
83 setmetatable(hostcfg, nil); 84 setmetatable(hostcfg, nil);
84 hostcfg.defined = nil; 85 hostcfg.defined = nil;
85 86
86 if hostcfg.component_module == nil then 87 if hostcfg.component_module == nil then
87 print(); 88 print();
95 print(); 96 print();
96 97
97 if has_components then 98 if has_components then
98 print("------------------------- Components ---------------------------"); 99 print("------------------------- Components ---------------------------");
99 100
100 for host, hostcfg in pairs(config) do 101 for host, hostcfg in it.sorted_pairs(config) do
101 local component_module = hostcfg.component_module; 102 local component_module = hostcfg.component_module;
102 hostcfg.component_module = nil; 103 hostcfg.component_module = nil;
103 104
104 if component_module then 105 if component_module then
105 print(); 106 print();