Annotate

tools/migration/mtools.lua @ 4165:9864f1375f3d

net.httpserver: Removed an unused function.
author Waqas Hussain <waqas20@gmail.com>
date Wed, 23 Feb 2011 07:26:54 +0500
parent 4162:af720a91aa19
child 4166:3ac90743039b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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 local print = print;
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 t_insert = table.insert;
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 local t_sort = table.sort;
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
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 module "mtools"
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 function sorted(params)
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
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 local reader = params.reader; -- iterator to get items from
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 local sorter = params.sorter; -- sorting function
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 local filter = params.filter; -- filter function
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
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 cache = {};
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 for item 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
17 if filter then item = filter(item); 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
18 if item then t_insert(cache, item); 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
19 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
20 if sorter then
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 t_sort(cache, sorter);
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 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
23 local i = 0;
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 return function()
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 i = i + 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
26 return cache[i];
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 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
28
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
29 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
30
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
31 function merged(reader, merger)
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
32
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
33 local item1 = reader();
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
34 local merged = { item1 };
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
35 return function()
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
36 while true 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
37 if not item1 then return nil; 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
38 local item2 = reader();
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
39 if not item2 then item1 = nil; return merged; 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
40 if merger(item1, item2) then
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
41 --print("merged")
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
42 item1 = item2;
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
43 t_insert(merged, item1);
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
44 else
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
45 --print("unmerged", merged)
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
46 item1 = item2;
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
47 local tmp = merged;
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
48 merged = { item1 };
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
49 return tmp;
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
50 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
51 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
52 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
53
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
54 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
55
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
56 return _M;