Annotate

tools/migration/migrator/mtools.lua @ 8681:0c077800cd70

util.async: Make parameters to async.runner() optional
author Matthew Wild <mwild1@gmail.com>
date Fri, 23 Mar 2018 14:02:33 +0000
parent 7881:4e3067272fae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 local print = print;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
4 local t_insert = table.insert;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
5 local t_sort = table.sort;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
6
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
7
7881
4e3067272fae tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents: 4216
diff changeset
8 local function sorted(params)
4166
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
9
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
10 local reader = params.reader; -- iterator to get items from
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
11 local sorter = params.sorter; -- sorting function
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
12 local filter = params.filter; -- filter function
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
13
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
14 local cache = {};
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
15 for item in reader do
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
16 if filter then item = filter(item); end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
17 if item then t_insert(cache, item); end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
18 end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
19 if sorter then
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
20 t_sort(cache, sorter);
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
21 end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
22 local i = 0;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
23 return function()
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
24 i = i + 1;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
25 return cache[i];
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
26 end;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
27
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
28 end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
29
7881
4e3067272fae tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents: 4216
diff changeset
30 local function merged(reader, merger)
4166
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
31
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
32 local item1 = reader();
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
33 local merged = { item1 };
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
34 return function()
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
35 while true do
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
36 if not item1 then return nil; end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
37 local item2 = reader();
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
38 if not item2 then item1 = nil; return merged; end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
39 if merger(item1, item2) then
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
40 --print("merged")
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
41 item1 = item2;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
42 t_insert(merged, item1);
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
43 else
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
44 --print("unmerged", merged)
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
45 item1 = item2;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
46 local tmp = merged;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
47 merged = { item1 };
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
48 return tmp;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
49 end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
50 end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
51 end;
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
52
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
53 end
3ac90743039b tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 4162
diff changeset
54
7881
4e3067272fae tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents: 4216
diff changeset
55 return {
4e3067272fae tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents: 4216
diff changeset
56 sorted = sorted;
4e3067272fae tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents: 4216
diff changeset
57 merged = merged;
4e3067272fae tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents: 4216
diff changeset
58 }