69 end |
69 end |
70 if not config[to_store] then |
70 if not config[to_store] then |
71 have_err = true; |
71 have_err = true; |
72 print("Error: Output store '"..to_store.."' not found in the config file."); |
72 print("Error: Output store '"..to_store.."' not found in the config file."); |
73 end |
73 end |
74 if not config[from_store].type then |
74 |
75 have_err = true; |
75 function load_store_handler(name) |
76 print("Error: Input store type not specified in the config file"); |
76 local store_type = config[name].type; |
77 elseif not pcall(require, "migrator."..config[from_store].type) then |
77 if not store_type then |
78 have_err = true; |
78 print("Error: "..name.." store type not specified in the config file"); |
79 print("Error: Unrecognised store type for '"..from_store.."': "..config[from_store].type); |
79 return false; |
|
80 else |
|
81 local ok, err = pcall(require, "migrator."..store_type); |
|
82 if not ok then |
|
83 if package.loaded["migrator."..store_type] then |
|
84 print(("Error: Failed to initialize '%s' store:\n\t%s") |
|
85 :format(name, err)); |
|
86 else |
|
87 print(("Error: Unrecognised store type for '%s': %s") |
|
88 :format(from_store, store_type)); |
|
89 end |
|
90 return false; |
|
91 end |
|
92 end |
|
93 return true; |
80 end |
94 end |
81 if not config[to_store].type then |
95 |
82 have_err = true; |
96 have_err = have_err or not(load_store_handler(from_store, "input") and load_store_handler(to_store, "output")); |
83 print("Error: Output store type not specified in the config file"); |
|
84 elseif not pcall(require, "migrator."..config[to_store].type) then |
|
85 have_err = true; |
|
86 print("Error: Unrecognised store type for '"..to_store.."': "..config[to_store].type); |
|
87 end |
|
88 |
97 |
89 if have_err then |
98 if have_err then |
90 print(""); |
99 print(""); |
91 print("Usage: "..arg[0].." FROM_STORE TO_STORE"); |
100 print("Usage: "..arg[0].." FROM_STORE TO_STORE"); |
92 print("If no stores are specified, 'input' and 'output' are used."); |
101 print("If no stores are specified, 'input' and 'output' are used."); |