Software /
code /
prosody
Annotate
tools/migration/main.lua @ 4166:3ac90743039b
tools/migration/*.lua: Convert to unix line endings
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 23 Feb 2011 18:31:48 +0000 |
parent | 4162:af720a91aa19 |
child | 4210:4583473dcce4 |
rev | line source |
---|---|
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
1 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
2 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
3 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
4 local function loadfilein(file, env) return loadin and loadin(env, io.open(file):read("*a")) or setfenv(loadfile(file), env); end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
5 config = {}; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
6 local config_env = setmetatable({}, { __index = function(t, k) return function(tbl) config[k] = tbl; end; end }); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
7 loadfilein("config.lua", config_env)(); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
8 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
9 package.path = "../../?.lua;"..package.path |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
10 package.cpath = "../../?.dll;"..package.cpath |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
11 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
12 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
13 assert(config.input, "no input specified") |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
14 assert(config.output, "no output specified") |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
15 local itype = assert(config.input.type, "no input.type specified"); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
16 local otype = assert(config.output.type, "no output.type specified"); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
17 local reader = require(itype).reader(config.input); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
18 local writer = require(otype).writer(config.output); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
19 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
20 local json = require "util.json"; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
21 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
22 for x in reader do |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
23 --print(json.encode(x)) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
24 writer(x); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
25 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
26 writer(nil); -- close |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
27 |