Mercurial > prosody-hg
comparison tools/migration/main.lua @ 4216:ff80a8471e86
tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 26 Feb 2011 00:23:48 +0000 |
| parents | 1674cd17557c |
| children |
comparison
equal
deleted
inserted
replaced
| 4214:1674cd17557c | 4216:ff80a8471e86 |
|---|---|
| 1 local default_config = "./migrator.cfg.lua"; | 1 #!/usr/bin/env lua |
| 2 | |
| 3 CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR"); | |
| 4 CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR"); | |
| 5 | |
| 6 local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua"; | |
| 2 | 7 |
| 3 -- Command-line parsing | 8 -- Command-line parsing |
| 4 local options = {}; | 9 local options = {}; |
| 5 local handled_opts = 0; | 10 local handled_opts = 0; |
| 6 for i = 1, #arg do | 11 for i = 1, #arg do |
| 43 os.exit(1); | 48 os.exit(1); |
| 44 end | 49 end |
| 45 | 50 |
| 46 config_chunk(); | 51 config_chunk(); |
| 47 | 52 |
| 48 if not package.loaded["util.json"] then | 53 if CFG_SOURCEDIR then |
| 54 package.path = CFG_SOURCEDIR.."/?.lua;"..package.path; | |
| 55 package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath; | |
| 56 elseif not package.loaded["util.json"] then | |
| 49 package.path = "../../?.lua;"..package.path | 57 package.path = "../../?.lua;"..package.path |
| 50 package.cpath = "../../?.dll;"..package.cpath | 58 package.cpath = "../../?.so;"..package.cpath |
| 51 end | 59 end |
| 52 | 60 |
| 53 local have_err; | 61 local have_err; |
| 54 if #arg > 0 and #arg ~= 2 then | 62 if #arg > 0 and #arg ~= 2 then |
| 55 have_err = true; | 63 have_err = true; |
| 64 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."); |
| 65 end | 73 end |
| 66 if not config[from_store].type then | 74 if not config[from_store].type then |
| 67 have_err = true; | 75 have_err = true; |
| 68 print("Error: Input store type not specified in the config file"); | 76 print("Error: Input store type not specified in the config file"); |
| 69 elseif not pcall(require, config[from_store].type) then | 77 elseif not pcall(require, "migrator."..config[from_store].type) then |
| 70 have_err = true; | 78 have_err = true; |
| 71 print("Error: Unrecognised store type for '"..from_store.."': "..config[from_store].type); | 79 print("Error: Unrecognised store type for '"..from_store.."': "..config[from_store].type); |
| 72 end | 80 end |
| 73 if not config[to_store].type then | 81 if not config[to_store].type then |
| 74 have_err = true; | 82 have_err = true; |
| 75 print("Error: Output store type not specified in the config file"); | 83 print("Error: Output store type not specified in the config file"); |
| 76 elseif not pcall(require, config[to_store].type) then | 84 elseif not pcall(require, "migrator."..config[to_store].type) then |
| 77 have_err = true; | 85 have_err = true; |
| 78 print("Error: Unrecognised store type for '"..to_store.."': "..config[to_store].type); | 86 print("Error: Unrecognised store type for '"..to_store.."': "..config[to_store].type); |
| 79 end | 87 end |
| 80 | 88 |
| 81 if have_err then | 89 if have_err then |
| 86 print("The available stores in your migrator config are:"); | 94 print("The available stores in your migrator config are:"); |
| 87 print(""); | 95 print(""); |
| 88 for store in pairs(config) do | 96 for store in pairs(config) do |
| 89 print("", store); | 97 print("", store); |
| 90 end | 98 end |
| 99 print(""); | |
| 91 os.exit(1); | 100 os.exit(1); |
| 92 end | 101 end |
| 93 | 102 |
| 94 local itype = config[from_store].type; | 103 local itype = config[from_store].type; |
| 95 local otype = config[to_store].type; | 104 local otype = config[to_store].type; |
| 96 local reader = require(itype).reader(config[from_store]); | 105 local reader = require("migrator."..itype).reader(config[from_store]); |
| 97 local writer = require(otype).writer(config[to_store]); | 106 local writer = require("migrator."..otype).writer(config[to_store]); |
| 98 | 107 |
| 99 local json = require "util.json"; | 108 local json = require "util.json"; |
| 100 | 109 |
| 101 for x in reader do | 110 for x in reader do |
| 102 --print(json.encode(x)) | 111 --print(json.encode(x)) |
