Annotate

tools/migration/migrator/mtools.lua @ 4953:24c2150cc8b0

Merge 0.9->trunk
author Matthew Wild <mwild1@gmail.com>
date Mon, 09 Jul 2012 02:36:09 +0100
parent 4216:ff80a8471e86
child 7881:4e3067272fae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4197
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
1
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
2
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
3 local print = print;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
4 local t_insert = table.insert;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
5 local t_sort = table.sort;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
6
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
7 module "mtools"
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
8
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
9 function sorted(params)
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
10
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
11 local reader = params.reader; -- iterator to get items from
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
12 local sorter = params.sorter; -- sorting function
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
13 local filter = params.filter; -- filter function
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
14
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
15 local cache = {};
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
16 for item in reader do
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
17 if filter then item = filter(item); end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
18 if item then t_insert(cache, item); end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
19 end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
20 if sorter then
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
21 t_sort(cache, sorter);
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
22 end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
23 local i = 0;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
24 return function()
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
25 i = i + 1;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
26 return cache[i];
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
27 end;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
28
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
29 end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
30
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
31 function merged(reader, merger)
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
32
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
33 local item1 = reader();
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
34 local merged = { item1 };
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
35 return function()
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
36 while true do
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
37 if not item1 then return nil; end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
38 local item2 = reader();
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
39 if not item2 then item1 = nil; return merged; end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
40 if merger(item1, item2) then
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
41 --print("merged")
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
42 item1 = item2;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
43 t_insert(merged, item1);
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
44 else
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
45 --print("unmerged", merged)
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
46 item1 = item2;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
47 local tmp = merged;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
48 merged = { item1 };
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
49 return tmp;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
50 end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
51 end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
52 end;
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
53
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
54 end
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
55
bef732980436 tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4193
diff changeset
56 return _M;