abuild/ap.in
Natanael Copa 781a453734 ap: set default repodir
if there are an APKBUILD in current dir, then use ../ as repodir.
Otherwise, use cwd as repodir.

Introduces requirement of lua-filesystem
2011-07-06 06:30:42 +00:00

124 lines
2.1 KiB
Lua
Executable File

#!/usr/bin/lua
require("aports")
require("lfs")
local db
-- subcommands -----------------------
subcmd = {}
subcmd.revdep = {
desc = "Print reverse dependencies",
usage = "PKG...",
run = function(opts)
local i
for i = 2, #opts do
db:foreach_revdep(opts[i], function (k,p)
print(p.pkgname)
end)
end
end
}
subcmd.list = {
desc = "Print all packages built from aports tree",
usage = "",
run = function()
db:foreach(function (k)
print(k)
end)
end
}
subcmd.recursdeps = {
desc = "Recursively print all make dependencies for given packages",
usage = "PKG...",
run = function (opts)
for i = 2, #opts do
db:recurs_until(opts[i], function(pn)
print(pn)
end)
end
end
}
subcmd.builddirs = {
desc = "Print the build dirs for given packages in build order",
usage = "PKG...",
run = function(opts)
local i, p, _
local visited = {}
local to_print = {}
for i = 2, #opts do
db:foreach_pkg(opts[i], function(_, p)
to_print[p.dir] = true
end)
end
for i = 2, #opts do
db:recurs_until(opts[i], function(pn)
local j,p
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
}
function print_usage()
io.write("usage: ap -d <DIR> SUBCOMMAND [options]\n\nSubcommands are:\n")
local k,v
for k in pairs(subcmd) do
print(" "..k)
end
end
-- those should be read from some config file
repodirs = {}
-- parse args
i = 1
opts = {}
help = false
while i <= #arg do
if arg[i] == "-d" then
i = i + 1
repodirs[#repodirs + 1] = arg[i]
elseif arg[i] == "-h" then
help = true
else
opts[#opts + 1] = arg[i]
end
i = i + 1
end
cmd = opts[1]
if cmd == nil then
print_usage()
-- usage
return
end
if #repodirs == 0 then
if lfs.attributes("APKBUILD") then
repodirs[1] = string.gsub(lfs.currentdir(), "(.*)/.*", "%1")
else
repodirs[1] = lfs.currentdir()
end
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")
end