tools: Update imports to use new prosody.* namespace

This commit is contained in:
Kim Alvefur 2023-06-08 09:37:01 +02:00
parent 0d6c625f93
commit 1541284108
9 changed files with 59 additions and 29 deletions

View file

@ -1,21 +1,24 @@
#!/usr/bin/env lua #!/usr/bin/env lua
-- cfgdump.lua prosody.cfg.lua [[host] option] -- cfgdump.lua prosody.cfg.lua [[host] option]
if not pcall(require, "prosody.loader") then
pcall(require, "loader");
end
local s_format, print = string.format, print; local s_format, print = string.format, print;
local printf = function(fmt, ...) return print(s_format(fmt, ...)); end local printf = function(fmt, ...) return print(s_format(fmt, ...)); end
local it = require "util.iterators"; local it = require "prosody.util.iterators";
local function sort_anything(a, b) local function sort_anything(a, b)
local typeof_a, typeof_b = type(a), type(b); local typeof_a, typeof_b = type(a), type(b);
if typeof_a ~= typeof_b then return typeof_a < typeof_b end if typeof_a ~= typeof_b then return typeof_a < typeof_b end
return a < b -- should work for everything in a config file return a < b -- should work for everything in a config file
end end
local serialization = require "util.serialization"; local serialization = require "prosody.util.serialization";
local serialize = serialization.new and serialization.new({ local serialize = serialization.new and serialization.new({
unquoted = true, table_iterator = function(t) return it.sorted_pairs(t, sort_anything); end, unquoted = true, table_iterator = function(t) return it.sorted_pairs(t, sort_anything); end,
}) or serialization.serialize; }) or serialization.serialize;
local configmanager = require"core.configmanager"; local configmanager = require"prosody.core.configmanager";
local startup = require "util.startup"; local startup = require "prosody.util.startup";
startup.set_function_metatable(); startup.set_function_metatable();
local config_filename, onlyhost, onlyoption = ...; local config_filename, onlyhost, onlyoption = ...;

View file

@ -1,5 +1,8 @@
-- Generate util/dnsregistry.lua from IANA HTTP status code registry -- Generate util/dnsregistry.lua from IANA HTTP status code registry
local xml = require "util.xml"; if not pcall(require, "prosody.loader") then
pcall(require, "loader");
end
local xml = require "prosody.util.xml";
local registries = xml.parse(io.read("*a"), { allow_processing_instructions = true }); local registries = xml.parse(io.read("*a"), { allow_processing_instructions = true });
print("-- Source: https://www.iana.org/assignments/dns-parameters/dns-parameters.xml"); print("-- Source: https://www.iana.org/assignments/dns-parameters/dns-parameters.xml");

View file

@ -16,13 +16,16 @@ if my_name:match("[/\\]") then
package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua"); package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua");
package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so"); package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so");
end end
if not pcall(require, "prosody.loader") then
pcall(require, "loader");
end
local serialize = require "util.serialization".serialize; local serialize = require "prosody.util.serialization".serialize;
local st = require "util.stanza"; local st = require "prosody.util.stanza";
local parse_xml = require "util.xml".parse; local parse_xml = require "prosody.util.xml".parse;
package.loaded["util.logger"] = {init = function() return function() end; end} package.loaded["prosody.util.logger"] = {init = function() return function() end; end}
local dm = require "util.datamanager" local dm = require "prosody.util.datamanager"
dm.set_data_path("data"); dm.set_data_path("data");
function parseFile(filename) function parseFile(filename)

View file

@ -1,4 +1,7 @@
-- Read an XML dataform and spit out a serialized Lua table of it -- Read an XML dataform and spit out a serialized Lua table of it
if not pcall(require, "prosody.loader") then
pcall(require, "loader");
end
local function from_stanza(stanza) local function from_stanza(stanza)
local layout = { local layout = {
@ -45,4 +48,5 @@ local function from_stanza(stanza)
return layout; return layout;
end end
print("dataforms.new " .. require "util.serialization".serialize(from_stanza(require "util.xml".parse(io.read("*a"))), { unquoted = true })) print("dataforms.new " .. require"prosody.util.serialization".serialize(from_stanza(require"prosody.util.xml".parse(io.read("*a"))),
{ unquoted = true }))

View file

@ -1,6 +1,9 @@
-- Generate net/http/codes.lua from IANA HTTP status code registry -- Generate net/http/codes.lua from IANA HTTP status code registry
if not pcall(require, "prosody.loader") then
pcall(require, "loader");
end
local xml = require "util.xml"; local xml = require "prosody.util.xml";
local registry = xml.parse(io.read("*a"), { allow_processing_instructions = true }); local registry = xml.parse(io.read("*a"), { allow_processing_instructions = true });
io.write([[ io.write([[

View file

@ -1,4 +1,7 @@
#!/usr/bin/env lua #!/usr/bin/env lua
if not pcall(require, "prosody.loader") then
pcall(require, "loader");
end
do do
@ -447,13 +450,13 @@ elseif package.config:sub(1,1) == "/" then
end end
package.loaded["util.logger"] = {init = function() return function() end; end} package.loaded["util.logger"] = {init = function() return function() end; end}
local dm = require "util.datamanager"; local dm = require "prosody.util.datamanager";
dm.set_data_path("data"); dm.set_data_path("data");
local datetime = require "util.datetime"; local datetime = require "prosody.util.datetime";
local st = require "util.stanza"; local st = require "prosody.util.stanza";
local parse_xml = require "util.xml".parse; local parse_xml = require "prosody.util.xml".parse;
function store_password(username, host, password) function store_password(username, host, password)
-- create or update account for username@host -- create or update account for username@host

View file

@ -1,7 +1,10 @@
if not pcall(require, "prosody.loader") then
pcall(require, "loader");
end
local lfs = require "lfs"; local lfs = require "lfs";
local st = require "util.stanza"; local st = require "prosody.util.stanza";
local parse_xml = require "util.xml".parse; local parse_xml = require "prosody.util.xml".parse;
local os_getenv = os.getenv; local os_getenv = os.getenv;
local io_open = io.open; local io_open = io.open;
local assert = assert; local assert = assert;

View file

@ -43,7 +43,11 @@ local function usage()
print("If no stores are specified, 'input' and 'output' are used."); print("If no stores are specified, 'input' and 'output' are used.");
end end
local startup = require "util.startup"; if not pcall(require, "prosody.loader") then
pcall(require, "loader");
end
local startup = require "prosody.util.startup";
do do
startup.parse_args({ startup.parse_args({
short_params = { v = "verbose", h = "help", ["?"] = "help" }; short_params = { v = "verbose", h = "help", ["?"] = "help" };
@ -79,7 +83,7 @@ end
-- Command-line parsing -- Command-line parsing
local options = prosody.opts; local options = prosody.opts;
local envloadfile = require "util.envload".envloadfile; local envloadfile = require "prosody.util.envload".envloadfile;
local config_file = options.config or default_config; local config_file = options.config or default_config;
local from_store = arg[1] or "input"; local from_store = arg[1] or "input";
@ -132,8 +136,8 @@ if have_err then
os.exit(1); os.exit(1);
end end
local async = require "util.async"; local async = require "prosody.util.async";
local server = require "net.server"; local server = require "prosody.net.server";
local watchers = { local watchers = {
error = function (_, err) error = function (_, err)
error(err); error(err);
@ -143,10 +147,10 @@ local watchers = {
end; end;
}; };
local cm = require "core.configmanager"; local cm = require "prosody.core.configmanager";
local hm = require "core.hostmanager"; local hm = require "prosody.core.hostmanager";
local sm = require "core.storagemanager"; local sm = require "prosody.core.storagemanager";
local um = require "core.usermanager"; local um = require "prosody.core.usermanager";
local function users(store, host) local function users(store, host)
if store.users then if store.users then
@ -200,7 +204,7 @@ migrate_once.pubsub = function(origin, destination, user, prefix, input_driver,
end end
if options["keep-going"] then if options["keep-going"] then
local xpcall = require "util.xpcall".xpcall; local xpcall = require "prosody.util.xpcall".xpcall;
for t, f in pairs(migrate_once) do for t, f in pairs(migrate_once) do
migrate_once[t] = function (origin, destination, user, ...) migrate_once[t] = function (origin, destination, user, ...)
local function log_err(err) local function log_err(err)

View file

@ -15,6 +15,10 @@ if my_name:match("[/\\]") then
package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so"); package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so");
end end
if not pcall(require, "prosody.loader") then
pcall(require, "loader");
end
-- ugly workaround for getting datamanager to work outside of prosody :( -- ugly workaround for getting datamanager to work outside of prosody :(
prosody = { }; prosody = { };
prosody.platform = "unknown"; prosody.platform = "unknown";
@ -24,12 +28,12 @@ elseif package.config:sub(1,1) == "/" then
prosody.platform = "posix"; prosody.platform = "posix";
end end
local parse_xml = require "util.xml".parse; local parse_xml = require "prosody.util.xml".parse;
----------------------------------------------------------------------- -----------------------------------------------------------------------
package.loaded["util.logger"] = {init = function() return function() end; end} package.loaded["util.logger"] = {init = function() return function() end; end}
local dm = require "util.datamanager" local dm = require "prosody.util.datamanager"
dm.set_data_path("data"); dm.set_data_path("data");
local arg = ...; local arg = ...;