2010-12-13 14:14:06 +00:00
|
|
|
module(..., package.seeall)
|
|
|
|
|
2011-08-04 12:21:32 +00:00
|
|
|
local function split_subpkgs(str)
|
2010-12-13 14:14:06 +00:00
|
|
|
local t = {}
|
|
|
|
local e
|
|
|
|
if (str == nil) then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
for e in string.gmatch(str, "%S+") do
|
|
|
|
t[#t + 1] = string.gsub(e, ":.*", "")
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2011-08-04 12:21:32 +00:00
|
|
|
local function split(str)
|
|
|
|
local t = {}
|
|
|
|
local e
|
|
|
|
if (str == nil) then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
for e in string.gmatch(str, "%S+") do
|
|
|
|
t[#t + 1] = e
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2011-06-15 08:24:31 +00:00
|
|
|
local function split_apkbuild(line)
|
2010-12-13 14:14:06 +00:00
|
|
|
local r = {}
|
2011-08-04 12:21:32 +00:00
|
|
|
local dir,pkgname, pkgver, pkgrel, arch, depends, makedepends, subpackages, source = string.match(line, "([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)")
|
2010-12-13 14:14:06 +00:00
|
|
|
r.dir = dir
|
|
|
|
r.pkgname = pkgname
|
|
|
|
r.pkgver = pkgver
|
|
|
|
r.pkgrel = pkgrel
|
|
|
|
r.depends = split(depends)
|
|
|
|
r.makedepends = split(makedepends)
|
2011-08-04 12:21:32 +00:00
|
|
|
r.subpackages = split_subpkgs(subpackages)
|
2010-12-13 14:14:06 +00:00
|
|
|
r.source = split(source)
|
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
|
|
|
-- parse the APKBUILDs and return an iterator
|
2011-06-15 08:24:31 +00:00
|
|
|
local function parse_apkbuilds(dirs)
|
2010-12-13 14:14:06 +00:00
|
|
|
local i,v, p
|
|
|
|
local str=""
|
|
|
|
if dirs == nil then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
--expand repos
|
|
|
|
for i,v in ipairs(dirs) do
|
|
|
|
str = str..v.."/*/APKBUILD "
|
|
|
|
end
|
|
|
|
|
|
|
|
local p = io.popen([[
|
|
|
|
for i in ]]..str..[[; do
|
|
|
|
pkgname=
|
|
|
|
pkgver=
|
|
|
|
pkgrel=
|
|
|
|
arch=
|
|
|
|
depends=
|
|
|
|
makedepends=
|
|
|
|
subpackages=
|
|
|
|
source=
|
|
|
|
dir="${i%/APKBUILD}"
|
|
|
|
cd "$dir"
|
|
|
|
. ./APKBUILD
|
|
|
|
echo $dir\|$pkgname\|$pkgver\|$pkgrel\|$arch\|$depends\|$makedepends\|$subpackages\|$source
|
|
|
|
done
|
|
|
|
]])
|
|
|
|
return function()
|
|
|
|
local line = p:read("*line")
|
|
|
|
if line == nil then
|
|
|
|
p:close()
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return split_apkbuild(line)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-06-15 08:24:31 +00:00
|
|
|
|
|
|
|
-- return a key list with makedepends and depends
|
|
|
|
function all_deps(p)
|
|
|
|
local m = {}
|
|
|
|
local k,v
|
|
|
|
if p == nil then
|
|
|
|
return m
|
2010-12-13 14:14:06 +00:00
|
|
|
end
|
2011-06-15 08:24:31 +00:00
|
|
|
if type(p.depends) == "table" then
|
|
|
|
for k,v in pairs(p.depends) do
|
|
|
|
m[v] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if type(p.makedepends) == "table" then
|
|
|
|
for k,v in pairs(p.makedepends) do
|
|
|
|
m[v] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return m
|
2010-12-13 14:14:06 +00:00
|
|
|
end
|
|
|
|
|
2011-08-04 12:21:32 +00:00
|
|
|
function is_remote(url)
|
|
|
|
local _,pref
|
|
|
|
for _,pref in pairs{ "^http://", "^ftp://", "^https://" } do
|
|
|
|
if string.match(url, pref) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
-- iterate over all entries in source and execute the function for remote
|
|
|
|
function foreach_remote_source(p, func)
|
|
|
|
local _,s
|
|
|
|
if p == nil or type(p.source) ~= "table" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for _,url in pairs(p.source) do
|
|
|
|
if is_remote(url) then
|
|
|
|
func(url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-24 18:15:53 +00:00
|
|
|
function get_maintainer(pkg)
|
|
|
|
if pkg == nil or pkg.dir == nil then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
local f = io.open(pkg.dir.."/APKBUILD")
|
|
|
|
if f == nil then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
local line
|
|
|
|
for line in f:lines() do
|
|
|
|
local maintainer = line:match("^%s*#%s*Maintainer:%s*(.*)")
|
|
|
|
if maintainer then
|
|
|
|
f:close()
|
|
|
|
return maintainer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
f:close()
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2011-06-15 08:24:31 +00:00
|
|
|
local function init_apkdb(repodirs)
|
2010-12-13 14:14:06 +00:00
|
|
|
local pkgdb = {}
|
|
|
|
local revdeps = {}
|
|
|
|
local a
|
|
|
|
for a in parse_apkbuilds(repodirs) do
|
|
|
|
-- io.write(a.pkgname.." "..a.pkgver.."\t"..a.dir.."\n")
|
|
|
|
if pkgdb[a.pkgname] == nil then
|
|
|
|
pkgdb[a.pkgname] = {}
|
|
|
|
end
|
2011-06-15 08:24:31 +00:00
|
|
|
a.all_deps = all_deps
|
2010-12-13 14:14:06 +00:00
|
|
|
table.insert(pkgdb[a.pkgname], a)
|
|
|
|
-- add subpackages to package db
|
|
|
|
local k,v
|
|
|
|
for k,v in pairs(a.subpackages) do
|
|
|
|
if pkgdb[v] == nil then
|
|
|
|
pkgdb[v] = {}
|
|
|
|
end
|
|
|
|
table.insert(pkgdb[v], a)
|
|
|
|
end
|
|
|
|
-- add to reverse dependencies
|
2011-06-15 08:24:31 +00:00
|
|
|
for v in pairs(all_deps(a)) do
|
2010-12-13 14:14:06 +00:00
|
|
|
if revdeps[v] == nil then
|
|
|
|
revdeps[v] = {}
|
|
|
|
end
|
|
|
|
table.insert(revdeps[v], a)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return pkgdb, revdeps
|
|
|
|
end
|
|
|
|
|
2011-06-15 08:24:31 +00:00
|
|
|
local Aports = {}
|
|
|
|
function Aports:recurs_until(pn, func)
|
2011-03-30 11:10:06 +00:00
|
|
|
local visited={}
|
2011-06-15 08:24:31 +00:00
|
|
|
local apkdb = self.apks
|
2011-03-30 11:10:06 +00:00
|
|
|
function recurs(pn)
|
|
|
|
if pn == nil or visited[pn] or apkdb[pn] == nil then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
visited[pn] = true
|
|
|
|
local _, p
|
|
|
|
for _, p in pairs(apkdb[pn]) do
|
|
|
|
local d
|
|
|
|
for d in pairs(all_deps(p)) do
|
|
|
|
if recurs(d) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return func(pn)
|
|
|
|
end
|
|
|
|
return recurs(pn)
|
|
|
|
end
|
|
|
|
|
2011-06-15 08:24:31 +00:00
|
|
|
function Aports:target_packages(pkgname)
|
|
|
|
local i,v
|
|
|
|
local t = {}
|
|
|
|
for k,v in pairs(self.apks[pkgname]) do
|
|
|
|
table.insert(t, pkgname.."-"..v.pkgver.."-r"..v.pkgrel..".apk")
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
|
|
|
function Aports:foreach(f)
|
|
|
|
local k,v
|
|
|
|
for k,v in pairs(self.apks) do
|
|
|
|
f(k,v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Aports:foreach_revdep(pkg, f)
|
|
|
|
local k,v
|
|
|
|
for k,v in pairs(self.revdeps[pkg] or {}) do
|
|
|
|
f(k,v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Aports:foreach_pkg(pkg, f)
|
|
|
|
local k,v
|
2011-07-06 06:29:12 +00:00
|
|
|
if self.apks[pkg] == nil then
|
|
|
|
io.stderr:write("WARNING: "..pkg.." has no data\n")
|
|
|
|
end
|
2011-06-15 08:24:31 +00:00
|
|
|
for k,v in pairs(self.apks[pkg]) do
|
|
|
|
f(k,v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-22 09:28:40 +00:00
|
|
|
function Aports:foreach_aport(f)
|
|
|
|
self:foreach(function(pkgname)
|
|
|
|
self:foreach_pkg(pkgname, function(i, pkg)
|
|
|
|
if pkgname == pkg.pkgname then
|
|
|
|
f(pkg)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2011-06-15 08:24:31 +00:00
|
|
|
function new(repodirs)
|
|
|
|
local h = Aports
|
|
|
|
h.repodirs = repodirs
|
|
|
|
h.apks, h.revdeps = init_apkdb(repodirs)
|
|
|
|
return h
|
|
|
|
end
|
|
|
|
|