tools/migration/prosody-migrator.lua
author Matthew Wild <mwild1@gmail.com>
Tue, 05 Apr 2011 14:11:25 +0100
changeset 4239 69fe5fd861e7
parent 4235 899ffc1674b5
child 4240 b3d9063aad4d
permissions -rw-r--r--
tools/migration: Support for ~/ in paths
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4216
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4214
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: 4214
diff changeset
     2
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4214
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: 4214
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: 4214
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: 4214
diff changeset
    15
local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua";
4214
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    16
4213
8f169a92b4ba 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: 4197
diff changeset
    17
-- Command-line parsing
8f169a92b4ba 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: 4197
diff changeset
    18
local options = {};
8f169a92b4ba 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: 4197
diff changeset
    19
local handled_opts = 0;
8f169a92b4ba 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: 4197
diff changeset
    20
for i = 1, #arg do
8f169a92b4ba 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: 4197
diff changeset
    21
	if arg[i]:sub(1,2) == "--" then
8f169a92b4ba 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: 4197
diff changeset
    22
		local opt, val = arg[i]:match("([%w-]+)=?(.*)");
8f169a92b4ba 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: 4197
diff changeset
    23
		if opt then
8f169a92b4ba 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: 4197
diff changeset
    24
			options[(opt:sub(3):gsub("%-", "_"))] = #val > 0 and val or true;
8f169a92b4ba 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: 4197
diff changeset
    25
		end
8f169a92b4ba 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: 4197
diff changeset
    26
		handled_opts = i;
8f169a92b4ba 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: 4197
diff changeset
    27
	else
8f169a92b4ba 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: 4197
diff changeset
    28
		break;
8f169a92b4ba 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: 4197
diff changeset
    29
	end
8f169a92b4ba 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: 4197
diff changeset
    30
end
8f169a92b4ba 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: 4197
diff changeset
    31
table.remove(arg, handled_opts);
4197
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
    32
4213
8f169a92b4ba 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: 4197
diff changeset
    33
-- Load config file
4214
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    34
local function loadfilein(file, env)
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    35
	if loadin then
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    36
		return loadin(env, io.open(file):read("*a"));
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    37
	else
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    38
		local chunk, err = loadfile(file);
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    39
		if chunk then
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    40
			setfenv(chunk, env);
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    41
		end
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    42
		return chunk, err;
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    43
	end
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    44
end
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    45
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    46
local config_file = options.config or default_config;
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    47
local from_store = arg[1] or "input";
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    48
local to_store = arg[2] or "output";
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    49
4197
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
    50
config = {};
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
    51
local config_env = setmetatable({}, { __index = function(t, k) return function(tbl) config[k] = tbl; end; end });
4214
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    52
local config_chunk, err = loadfilein(config_file, config_env);
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    53
if not config_chunk then
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    54
	print("There was an error loading the config file, check the file exists");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    55
	print("and that the syntax is correct:");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    56
	print("", err);
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    57
	os.exit(1);
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    58
end
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    59
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    60
config_chunk();
4197
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
    61
4216
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4214
diff changeset
    62
if CFG_SOURCEDIR then
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4214
diff changeset
    63
	package.path = CFG_SOURCEDIR.."/?.lua;"..package.path;
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4214
diff changeset
    64
	package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath;
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4214
diff changeset
    65
elseif not package.loaded["util.json"] then
4213
8f169a92b4ba 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: 4197
diff changeset
    66
	package.path = "../../?.lua;"..package.path
4216
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4214
diff changeset
    67
	package.cpath = "../../?.so;"..package.cpath
4213
8f169a92b4ba 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: 4197
diff changeset
    68
end
4197
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
    69
4214
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    70
local have_err;
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    71
if #arg > 0 and #arg ~= 2 then
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    72
	have_err = true;
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    73
	print("Error: Incorrect number of parameters supplied.");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    74
end
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    75
if not config[from_store] then
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    76
	have_err = true;
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    77
	print("Error: Input store '"..from_store.."' not found in the config file.");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    78
end
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    79
if not config[to_store] then
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    80
	have_err = true;
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    81
	print("Error: Output store '"..to_store.."' not found in the config file.");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
    82
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
    83
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
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
    85
	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
    86
	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
    87
		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
    88
		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
    89
	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
    90
		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
    91
		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
    92
			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
    93
				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
    94
					: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
    95
			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
    96
				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
    97
					: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
    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
			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
   100
		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
   101
	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
   102
	return true;
4214
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   103
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
   104
899ffc1674b5 tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents: 4229
diff changeset
   105
have_err = have_err or not(load_store_handler(from_store, "input") and load_store_handler(to_store, "output"));
4213
8f169a92b4ba 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: 4197
diff changeset
   106
4214
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   107
if have_err then
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   108
	print("");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   109
	print("Usage: "..arg[0].." FROM_STORE TO_STORE");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   110
	print("If no stores are specified, 'input' and 'output' are used.");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   111
	print("");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   112
	print("The available stores in your migrator config are:");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   113
	print("");
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   114
	for store in pairs(config) do
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   115
		print("", store);
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   116
	end
4216
ff80a8471e86 tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents: 4214
diff changeset
   117
	print("");
4214
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   118
	os.exit(1);
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   119
end
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   120
	
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   121
local itype = config[from_store].type;
1674cd17557c tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents: 4213
diff changeset
   122
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: 4214
diff changeset
   123
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: 4214
diff changeset
   124
local writer = require("migrator."..otype).writer(config[to_store]);
4197
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
   125
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
   126
local json = require "util.json";
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
   127
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
   128
for x in reader do
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
   129
	--print(json.encode(x))
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
   130
	writer(x);
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
   131
end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
   132
writer(nil); -- close
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
   133