Software /
code /
prosody
Annotate
tools/migration/prosody_files.lua @ 4162:af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 23 Feb 2011 02:16:19 +0500 |
child | 4166:3ac90743039b |
rev | line source |
---|---|
4162
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 local print = print; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 local assert = assert; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 local setmetatable = setmetatable; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 local tonumber = tonumber; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 local char = string.char; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 local coroutine = coroutine; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local lfs = require "lfs"; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 local loadfile = loadfile; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local setfenv = setfenv; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local pcall = pcall; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local mtools = require "mtools"; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 local next = next; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 local pairs = pairs; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 local json = require "util.json"; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 prosody = {}; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 local dm = require "util.datamanager" |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 module "prosody_files" |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 local function is_dir(path) return lfs.attributes(path, "mode") == "directory"; end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 local function is_file(path) return lfs.attributes(path, "mode") == "file"; end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 local function clean_path(path) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 return path:gsub("\\", "/"):gsub("//+", "/"); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 local encode, decode; do |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end }); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 decode = function (s) return s and (s:gsub("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", urlcodes)); end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 encode = function (s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 local function decode_dir(x) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 if x:gsub("%%%x%x", ""):gsub("[a-zA-Z0-9]", "") == "" then |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 return decode(x); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 local function decode_file(x) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 if x:match(".%.dat$") and x:gsub("%.dat$", ""):gsub("%%%x%x", ""):gsub("[a-zA-Z0-9]", "") == "" then |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 return decode(x:gsub("%.dat$", "")); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 local function prosody_dir(path, ondir, onfile, ...) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 for x in lfs.dir(path) do |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 local xpath = path.."/"..x; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 if decode_dir(x) and is_dir(xpath) then |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 ondir(xpath, x, ...); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 elseif decode_file(x) and is_file(xpath) then |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 onfile(xpath, x, ...); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 local function handle_root_file(path, name) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 --print("root file: ", decode_file(name)) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 coroutine.yield { user = nil, host = nil, store = decode_file(name) }; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 local function handle_host_file(path, name, host) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 --print("host file: ", decode_dir(host).."/"..decode_file(name)) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 coroutine.yield { user = nil, host = decode_dir(host), store = decode_file(name) }; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 local function handle_store_file(path, name, store, host) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 --print("store file: ", decode_file(name).."@"..decode_dir(host).."/"..decode_dir(store)) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 coroutine.yield { user = decode_file(name), host = decode_dir(host), store = decode_dir(store) }; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 local function handle_host_store(path, name, host) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 prosody_dir(path, function() end, handle_store_file, name, host); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 local function handle_host_dir(path, name) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 prosody_dir(path, handle_host_store, handle_host_file, name); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
70 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 local function handle_root_dir(path) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
72 prosody_dir(path, handle_host_dir, handle_root_file); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
73 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
74 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 local function decode_user(item) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 local userdata = { |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 user = item[1].user; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 host = item[1].host; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 stores = {}; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 }; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 for i=1,#item do -- loop over stores |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 local result = {}; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
83 local store = item[i]; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
84 userdata.stores[store.store] = store.data; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 store.user = nil; store.host = nil; store.store = nil; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 return userdata; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
90 function reader(input) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 local path = clean_path(assert(input.path, "no input.path specified")); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 assert(is_dir(path), "input.path is not a directory"); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 local iter = coroutine.wrap(function()handle_root_dir(path);end); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
94 -- get per-user stores, sorted |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 local iter = mtools.sorted { |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 reader = function() |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 local x = iter(); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
98 if x then |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
99 dm.set_data_path(path); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
100 x.data = assert(dm.load(x.user, x.host, x.store)); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
101 return x; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
102 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
103 end; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
104 sorter = function(a, b) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
105 local a_host, a_user, a_store = a.host or "", a.user or "", a.store or ""; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
106 local b_host, b_user, b_store = b.host or "", b.user or "", b.store or ""; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
107 return a_host > b_host or (a_host==b_host and a_user > b_user) or (a_host==b_host and a_user==b_user and a_store > b_store); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
108 end; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
109 }; |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 -- merge stores to get users |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
111 iter = mtools.merged(iter, function(a, b) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
112 return (a.host == b.host and a.user == b.user); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
113 end); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
114 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 return function() |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
116 local x = iter(); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
117 return x and decode_user(x); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
118 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
119 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
120 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
121 function writer(output) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
122 local path = clean_path(assert(output.path, "no output.path specified")); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 assert(is_dir(path), "output.path is not a directory"); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
124 return function(item) |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
125 if not item then return; end -- end of input |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
126 dm.set_data_path(path); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
127 for store, data in pairs(item.stores) do |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
128 assert(dm.store(item.user, item.host, store, data)); |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
129 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
131 end |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
132 |
af720a91aa19
tools/migration/*: Initial commit of a new migration tool. Currently supports Prosody files and Prosody SQL as input and output.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 return _M; |