summaryrefslogtreecommitdiff
path: root/ap.in
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2011-06-15 10:24:31 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2011-06-15 10:32:36 +0200
commit48884b4eb8fcc8c63b45b72e364cc10ef74086d3 (patch)
treeca3c7196621e40d8e1210a170b299b61998c0dfe /ap.in
parentac830aeb8747b0bf255de3a4de330140d2f9b9a9 (diff)
downloadabuild-48884b4eb8fcc8c63b45b72e364cc10ef74086d3.tar.gz
abuild-48884b4eb8fcc8c63b45b72e364cc10ef74086d3.tar.bz2
abuild-48884b4eb8fcc8c63b45b72e364cc10ef74086d3.tar.xz
abuild-48884b4eb8fcc8c63b45b72e364cc10ef74086d3.zip
aports.lua: make api more object oriented
- provide a handle with aports.new(dir) - provide foreach() helper functions
Diffstat (limited to 'ap.in')
-rwxr-xr-xap.in32
1 files changed, 14 insertions, 18 deletions
diff --git a/ap.in b/ap.in
index 7b69e05..bc9d075 100755
--- a/ap.in
+++ b/ap.in
@@ -2,6 +2,8 @@
require("aports")
+local db
+
-- subcommands -----------------------
subcmd = {}
subcmd.revdep = {
@@ -9,13 +11,10 @@ subcmd.revdep = {
usage = "PKG...",
run = function(opts)
local i
- local apkdb, rev = aports.init_apkdb(repodirs)
for i = 2, #opts do
- local pkg = opts[i]
- local _,p
- for _,p in pairs(rev[pkg] or {}) do
- print(p.pkgname)
- end
+ db:foreach_revdep(opts[i], function (k,p)
+ print(p.pkgname)
+ end)
end
end
}
@@ -24,11 +23,9 @@ subcmd.list = {
desc = "Print all packages built from aports tree",
usage = "",
run = function()
- local apkdb = aports.init_apkdb(repodirs)
- local k,v
- for k,v in pairs(apkdb) do
+ db:foreach(function (k)
print(k)
- end
+ end)
end
}
@@ -36,9 +33,8 @@ subcmd.recursdeps = {
desc = "Recursively print all make dependencies for given packages",
usage = "PKG...",
run = function (opts)
- local db, rev = aports.init_apkdb(repodirs)
for i = 2, #opts do
- aports.recurs_until(db, opts[i], function(pn)
+ db:recurs_until(opts[i], function(pn)
print(pn)
end)
end
@@ -51,22 +47,21 @@ subcmd.builddirs = {
run = function(opts)
local i, p, _
local visited = {}
- local db, rev = aports.init_apkdb(repodirs)
local to_print = {}
for i = 2, #opts do
- for _,p in pairs(db[opts[i]]) do
+ db:foreach_pkg(opts[i], function(_, p)
to_print[p.dir] = true
- end
+ end)
end
for i = 2, #opts do
- aports.recurs_until(db, opts[i], function(pn)
+ db:recurs_until(opts[i], function(pn)
local j,p
- for j, p in pairs(db[pn]) do
+ db:foreach_pkg(pn, function(j, p)
if to_print[p.dir] then
print(p.dir)
to_print[p.dir] = nil
end
- end
+ end)
end)
end
end
@@ -111,6 +106,7 @@ if cmd == nil then
end
if subcmd[cmd] and type(subcmd[cmd].run) == "function" then
+ db = aports.new(repodirs)
subcmd[cmd].run(opts)
else
io.stderr:write(cmd..": invalid subcommand\n")