Annotate

tools/migration/prosody-migrator.lua @ 6118:aae3d6daa50d

plugins/muc/muc.lib: Fetch config via accessors instead of using `_data`
author daurnimator <quae@daurnimator.com>
date Wed, 19 Mar 2014 14:39:31 -0400
parent 5776:bd0ff8ae98a8
child 7880:1d998891c967
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4216
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4211
diff changeset
1 #!/usr/bin/env lua
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4211
diff changeset
2
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4211
diff changeset
3 CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR");
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4211
diff changeset
4 CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR");
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4211
diff changeset
5
4239
69fe5fd861e7 tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents: 4235
diff changeset
6 -- Substitute ~ with path to home directory in paths
69fe5fd861e7 tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents: 4235
diff changeset
7 if CFG_CONFIGDIR then
69fe5fd861e7 tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents: 4235
diff changeset
8 CFG_CONFIGDIR = CFG_CONFIGDIR:gsub("^~", os.getenv("HOME"));
69fe5fd861e7 tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents: 4235
diff changeset
9 end
69fe5fd861e7 tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents: 4235
diff changeset
10
69fe5fd861e7 tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents: 4235
diff changeset
11 if CFG_SOURCEDIR then
69fe5fd861e7 tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents: 4235
diff changeset
12 CFG_SOURCEDIR = CFG_SOURCEDIR:gsub("^~", os.getenv("HOME"));
69fe5fd861e7 tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents: 4235
diff changeset
13 end
69fe5fd861e7 tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents: 4235
diff changeset
14
4216
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4211
diff changeset
15 local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua";
4211
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
16
4210
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
17 -- Command-line parsing
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
18 local options = {};
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
19 local handled_opts = 0;
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
20 for i = 1, #arg do
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
21 if arg[i]:sub(1,2) == "--" then
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
22 local opt, val = arg[i]:match("([%w-]+)=?(.*)");
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
23 if opt then
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
24 options[(opt:sub(3):gsub("%-", "_"))] = #val > 0 and val or true;
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
25 end
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
26 handled_opts = i;
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
27 else
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
28 break;
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
29 end
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
30 end
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
31 table.remove(arg, handled_opts);
4166
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
32
5021
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
33 if CFG_SOURCEDIR then
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
34 package.path = CFG_SOURCEDIR.."/?.lua;"..package.path;
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
35 package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath;
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
36 else
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
37 package.path = "../../?.lua;"..package.path
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
38 package.cpath = "../../?.so;"..package.cpath
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
39 end
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
40
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
41 local envloadfile = require "util.envload".envloadfile;
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
42
4210
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
43 -- Load config file
4211
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
44 local function loadfilein(file, env)
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
45 if loadin then
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
46 return loadin(env, io.open(file):read("*a"));
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
47 else
5021
85b2689dbcfe Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents: 4240
diff changeset
48 return envloadfile(file, env);
4211
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
49 end
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
50 end
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
51
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
52 local config_file = options.config or default_config;
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
53 local from_store = arg[1] or "input";
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
54 local to_store = arg[2] or "output";
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
55
4166
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
56 config = {};
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
57 local config_env = setmetatable({}, { __index = function(t, k) return function(tbl) config[k] = tbl; end; end });
4211
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
58 local config_chunk, err = loadfilein(config_file, config_env);
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
59 if not config_chunk then
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
60 print("There was an error loading the config file, check the file exists");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
61 print("and that the syntax is correct:");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
62 print("", err);
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
63 os.exit(1);
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
64 end
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
65
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
66 config_chunk();
4166
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
67
4211
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
68 local have_err;
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
69 if #arg > 0 and #arg ~= 2 then
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
70 have_err = true;
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
71 print("Error: Incorrect number of parameters supplied.");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
72 end
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
73 if not config[from_store] then
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
74 have_err = true;
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
75 print("Error: Input store '"..from_store.."' not found in the config file.");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
76 end
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
77 if not config[to_store] then
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
78 have_err = true;
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
79 print("Error: Output store '"..to_store.."' not found in the config file.");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
80 end
4235
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
81
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
82 function load_store_handler(name)
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
83 local store_type = config[name].type;
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
84 if not store_type then
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
85 print("Error: "..name.." store type not specified in the config file");
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
86 return false;
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
87 else
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
88 local ok, err = pcall(require, "migrator."..store_type);
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
89 if not ok then
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
90 if package.loaded["migrator."..store_type] then
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
91 print(("Error: Failed to initialize '%s' store:\n\t%s")
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
92 :format(name, err));
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
93 else
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
94 print(("Error: Unrecognised store type for '%s': %s")
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
95 :format(from_store, store_type));
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
96 end
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
97 return false;
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
98 end
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
99 end
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
100 return true;
4211
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
101 end
4235
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
102
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
103 have_err = have_err or not(load_store_handler(from_store, "input") and load_store_handler(to_store, "output"));
4210
4583473dcce4 tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents: 4166
diff changeset
104
4211
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
105 if have_err then
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
106 print("");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
107 print("Usage: "..arg[0].." FROM_STORE TO_STORE");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
108 print("If no stores are specified, 'input' and 'output' are used.");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
109 print("");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
110 print("The available stores in your migrator config are:");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
111 print("");
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
112 for store in pairs(config) do
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
113 print("", store);
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
114 end
4216
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4211
diff changeset
115 print("");
4211
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
116 os.exit(1);
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
117 end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5021
diff changeset
118
4211
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
119 local itype = config[from_store].type;
9a12fc2baa37 tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4210
diff changeset
120 local otype = config[to_store].type;
4216
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4211
diff changeset
121 local reader = require("migrator."..itype).reader(config[from_store]);
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4211
diff changeset
122 local writer = require("migrator."..otype).writer(config[to_store]);
4166
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
123
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
124 local json = require "util.json";
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
125
4240
b3d9063aad4d tools/migration/prosody-migrator.lua: Add messages to show when migration is in progress
Matthew Wild <mwild1@gmail.com>
parents: 4239
diff changeset
126 io.stderr:write("Migrating...\n");
4166
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
127 for x in reader do
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
128 --print(json.encode(x))
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
129 writer(x);
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
130 end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
131 writer(nil); -- close
4240
b3d9063aad4d tools/migration/prosody-migrator.lua: Add messages to show when migration is in progress
Matthew Wild <mwild1@gmail.com>
parents: 4239
diff changeset
132 io.stderr:write("Done!\n");