author | Waqas Hussain <waqas20@gmail.com> |
Wed, 23 Feb 2011 02:16:19 +0500 | |
changeset 4162 | af720a91aa19 |
child 4166 | 3ac90743039b |
permissions | -rw-r--r-- |
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 |
|
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 |
|
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 function loadfilein(file, env) return loadin and loadin(env, io.open(file):read("*a")) or setfenv(loadfile(file), env); 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
|
5 |
config = {}; |
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 config_env = setmetatable({}, { __index = function(t, k) return function(tbl) config[k] = tbl; 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
|
7 |
loadfilein("config.lua", config_env)(); |
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 |
|
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 |
package.path = "../../?.lua;"..package.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
|
10 |
package.cpath = "../../?.dll;"..package.cpath |
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 |
|
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 |
|
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 |
assert(config.input, "no input 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
|
14 |
assert(config.output, "no output 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
|
15 |
local itype = assert(config.input.type, "no input.type 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
|
16 |
local otype = assert(config.output.type, "no output.type 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
|
17 |
local reader = require(itype).reader(config.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
|
18 |
local writer = require(otype).writer(config.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
|
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 |
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
|
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 |
for x in reader 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
|
23 |
--print(json.encode(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
|
24 |
writer(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
|
25 |
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
|
26 |
writer(nil); -- close |
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 |