* updated libkcddb (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / misc / lua / sde / pkgdb.lua
blobe83ce17f946aafa4184d9608bcaea8a23c4d22d3
1 -- --- T2-COPYRIGHT-NOTE-BEGIN ---
2 -- This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 --
4 -- T2 SDE: misc/lua/sde/pkgdb.lua
5 -- Copyright (C) 2005 - 2006 The T2 SDE Project
6 -- Copyright (C) 2005 - 2006 Valentin Ziegler, Juergen "George" Sawinski
7 --
8 -- More information can be found in the files COPYING and README.
9 --
10 -- This program is free software; you can redistribute it and/or modify
11 -- it under the terms of the GNU General Public License as published by
12 -- the Free Software Foundation; version 2 of the License. A copy of the
13 -- GNU General Public License can be found in the file COPYING.
14 -- --- T2-COPYRIGHT-NOTE-END ---
16 -- TODO:
17 -- - add "update-priority" (like "urgent,security,normal" etc)
18 -- (also needs to go into create_package_db and other places)
20 -- DESCRIPTION:
21 -- p = pkgdb.parse(line-iterator)
22 -- Parse the package.db (takes a line iterator as input)
24 require "sde/desc"
26 -- parse all packages.db information into tables
27 -- filelist saving commented out (eats another 30M)
29 local function block_lines()
30 local line = lines()
32 if (line == nil) or (line=="\023") then
33 return nil
34 end
36 return line
37 end
39 local function read_deps()
40 local deps={}
42 for line in block_lines do
43 _,_,dependency = string.find(line, "[^ ]* (.*)")
44 table.insert (deps, dependency)
45 end
47 return deps
48 end
50 local function read_flist()
51 local files={}
52 local cksums={}
53 local sizes={}
54 local usage=0
56 for line in block_lines do
57 _,_,cksum,size,file = string.find(line, "^([0-9]+) ([0-9]+) (.*)")
58 -- uncomment these lines if you want to save complete file list
59 -- table.insert (files, file);
60 -- table.insert (cksums, 1 * cksum);
61 -- table.insert (sizes, 1 * size);
62 usage = usage + size
63 end
65 return usage,files,cksums,sizes
66 end
68 local function parse(lines)
69 packages = {}
71 repeat -- parse packages
72 pkgname = lines()
74 if pkgname then
75 print(pkgname)
76 local pkg_data = {}
78 if lines() ~= "\023" then -- separator line
79 print ("terminating line missing\n")
80 end
82 pkg_data.desc = desc.parse (block_lines)
83 pkg_data.deps = read_deps ()
84 pkg_data.usage = read_flist ()
86 if lines() ~= "\004" then -- separator line
87 print ("terminating line missing\n")
88 end
90 packages[pkgname] = pkg_data
91 end
92 until pkgname == nil
94 return packages
95 end