Commit 5a593a44 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

parser: Incorporate info from .control files

Also, import bunch of control & other files for testing for the three
packages we have „installed“ in the test system.
parent 7caed99e
......@@ -19,8 +19,10 @@ along with Updater. If not, see <http://www.gnu.org/licenses/>.
local error = error
local type = type
local pairs = pairs
local io = io
local DBG = DBG
local WARN = WARN
module "backend"
......@@ -140,6 +142,28 @@ function package_postprocess(status)
end
status_file = "/usr/lib/opkg/status"
info_dir = "/usr/lib/opkg/info/"
-- Read pkg_name's .control file and return it as a parsed block
local function pkg_control(pkg_name)
local fname = info_dir .. pkg_name .. ".control"
local f, err = io.open(fname)
if not f then
WARN("Could not read .control file of " .. pkg_name .. ": " .. err)
return nil
end
local content = f:read("*a")
f:close()
if not content then error("Could not read content of " .. fname) end
return block_parse(content)
end
-- Merge additions into target (both are tables)
local function merge(target, additions)
for n, v in pairs(additions) do
target[n] = v
end
end
function status_parse()
DBG("Parsing status file ", status_file)
......@@ -151,6 +175,8 @@ function status_parse()
if not content then error("Failed to read content of the status file") end
for block in block_split(content) do
local pkg = block_parse(block)
local control = pkg_control(pkg.Package)
if control then merge(pkg, control) end
-- TODO: merge other sources of information
pkg = package_postprocess(pkg)
result[pkg.Package] = pkg
......
......@@ -159,28 +159,50 @@ function test_status_parse()
Package = "kmod-usb-storage",
Version = "3.18.21+10-1-70ea6b9a4b789c558ac9d579b5c1022f-10",
Architecture = "mpc85xx",
Source = "package/kernel/linux",
License = "GPLv2",
Section = "kernel",
["Installed-Size"] = "22537",
Description = "Kernel support for USB Mass Storage devices",
["Installed-Time"] = "1453896142"}, {"kernel (=3.18.21-1-70ea6b9a4b789c558ac9d579b5c1022f-10)", "kmod-scsi-core", "kmod-usb-core"}, std_status)
status_check("terminfo", {
Package = "terminfo",
Version = "5.9-2",
Architecture = "mpc85xx",
Source = "package/libs/ncurses",
License = "MIT",
LicenseFiles = "README",
Section = "libs",
["Installed-Size"] = "5822",
Description = "Terminal Info Database (ncurses)",
["Installed-Time"] = "1453896265"}, {"libc"}, std_status)
status_check("dnsmasq-dhcpv6", {
Package = "dnsmasq-dhcpv6",
Version = "2.73-1",
Architecture = "mpc85xx",
Source = "package/network/services/dnsmasq",
License = "GPL-2.0",
LicenseFiles = "COPYING",
Section = "net",
["Installed-Size"] = "142254",
Description = [[It is intended to provide coupled DNS and DHCP service to a LAN.
This is a variant with DHCPv6 support]],
["Installed-Time"] = "1453896240"}, {"libc"}, std_status, {["/etc/config/dhcp"] = "f81fe9bd228dede2165be71e5c9dcf76cc", ["/etc/dnsmasq.conf"] = "1e6ab19c1ae5e70d609ac7b6246541d520"})
end
local orig_status_file = B.status_file
local orig_info_dir = B.info_dir
function setup()
local sdir = os.getenv("S") or "."
-- Use a shortened version of a real status file for tests
B.status_file = sdir .. "/tests/data/opkg/status"
B.info_dir = sdir .. "/tests/data/opkg/info/"
end
function teardown()
-- Clean up, return the original file name
B.status_file = orig_status_file
B.info_dir = orig_info_dir
end
/etc/config/dhcp
/etc/dnsmasq.conf
Package: dnsmasq-dhcpv6
Version: 2.73-1
Depends: libc
Source: package/network/services/dnsmasq
License: GPL-2.0
LicenseFiles: COPYING
Section: net
Architecture: mpc85xx
Installed-Size: 142254
Description: It is intended to provide coupled DNS and DHCP service to a LAN.
This is a variant with DHCPv6 support
/etc/dnsmasq.conf
/etc/hotplug.d/iface/25-dnsmasq
/etc/config/dhcp
/etc/init.d/dnsmasq
/usr/sbin/dnsmasq
#!/bin/sh
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
. ${IPKG_INSTROOT}/lib/functions.sh
( type default_postinst > /dev/null ) && default_postinst $0 $@ || true
#!/bin/sh
. ${IPKG_INSTROOT}/lib/functions.sh
( type default_prerm > /dev/null ) && default_prerm $0 $@ || true
Package: kmod-usb-storage
Version: 3.18.21+10-1-70ea6b9a4b789c558ac9d579b5c1022f-10
Depends: kernel (=3.18.21-1-70ea6b9a4b789c558ac9d579b5c1022f-10), kmod-scsi-core, kmod-usb-core
Source: package/kernel/linux
License: GPLv2
Section: kernel
Architecture: mpc85xx
Installed-Size: 22537
Description: Kernel support for USB Mass Storage devices
/lib/modules/3.18.21-70ea6b9a4b789c558ac9d579b5c1022f-10/usb-storage.ko
/etc/modules-boot.d/usb-storage
/etc/modules.d/usb-storage
#!/bin/sh
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
. ${IPKG_INSTROOT}/lib/functions.sh
( type default_postinst > /dev/null ) && default_postinst $0 $@ || true
#!/bin/sh
[ -z "$IPKG_INSTROOT" ] || exit 0
. /lib/functions.sh
insert_modules usb-storage
#!/bin/sh
. ${IPKG_INSTROOT}/lib/functions.sh
( type default_prerm > /dev/null ) && default_prerm $0 $@ || true
Package: terminfo
Version: 5.9-2
Depends: libc
Source: package/libs/ncurses
License: MIT
LicenseFiles: README
Section: libs
Architecture: mpc85xx
Installed-Size: 5822
Description: Terminal Info Database (ncurses)
/usr/share/terminfo/x/xterm
/usr/share/terminfo/r/rxvt-unicode
/usr/share/terminfo/d/dumb
/usr/share/terminfo/a/ansi
/usr/share/terminfo/x/xterm-color
/usr/share/terminfo/r/rxvt
/usr/share/terminfo/s/screen
/usr/share/terminfo/x/xterm-256color
/usr/share/terminfo/l/linux
/usr/share/terminfo/v/vt100
/usr/share/terminfo/v/vt102
#!/bin/sh
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
. ${IPKG_INSTROOT}/lib/functions.sh
( type default_postinst > /dev/null ) && default_postinst $0 $@ || true
#!/bin/sh
. ${IPKG_INSTROOT}/lib/functions.sh
( type default_prerm > /dev/null ) && default_prerm $0 $@ || true
......@@ -10,9 +10,7 @@ function assert_table_equal(t1, t2)
lunit.assert_table(t2)
local function cmp(t1, t2, name)
for k, v in pairs(t1) do
local v2 = t2[k]
if v2 == nil then v2 = "nil" end
lunit.assert_equal(v, t2[k], "Values for key '" .. k .. "' differ: '" .. tostring(v) .. "' vs '" .. tostring(v2) .. "'" .. name)
lunit.assert_equal(v, t2[k], "Values for key '" .. k .. "' differ, " .. name)
end
end
cmp(t1, t2, " pass 1")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment