summaryrefslogtreecommitdiffstats
path: root/aports
diff options
context:
space:
mode:
Diffstat (limited to 'aports')
-rw-r--r--aports/db.lua100
-rw-r--r--aports/pkg.lua101
2 files changed, 106 insertions, 95 deletions
diff --git a/aports/db.lua b/aports/db.lua
index 9f8769f..009520b 100644
--- a/aports/db.lua
+++ b/aports/db.lua
@@ -1,6 +1,7 @@
-local abuild = require('aports.abuild')
local M = {}
+local abuild = require('aports.abuild')
+local pkg = require('aports.pkg')
local function split_subpkgs(str)
local t = {}
@@ -81,97 +82,6 @@ local function parse_apkbuilds(dirs)
end
end
-
-
--- return a key list with makedepends and depends
-function M.all_deps(p)
- local m = {}
- local k,v
- if p == nil then
- return m
- end
- 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
-end
-
-function M.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
-
--- iterator for all remote sources of given pkg/aport
-function M.remote_sources(p)
- if p == nil or type(p.source) ~= "table" then
- return nil
- end
- return coroutine.wrap(function()
- for _,url in pairs(p.source) do
- if M.is_remote(url) then
- coroutine.yield(url)
- end
- end
- end)
-end
-
-function M.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
-
-function M.get_repo_name(pkg)
- if pkg == nil or pkg.dir == nil then
- return nil
- end
- return string.match(pkg.dir, ".*/(.*)/.*")
-end
-
-function M.get_apk_filename(pkg)
- return pkg.pkgname.."-"..pkg.pkgver.."-r"..pkg.pkgrel..".apk"
-end
-
-function M.get_apk_file_path(pkg)
- local pkgdest = abuild.get_conf("PKGDEST")
- if pkgdest ~= nil and pkgdest ~= "" then
- return pkgdest.."/"..M.get_apk_filename(pkg)
- end
- local repodest = abuild.get_conf("REPODEST")
- if repodest ~= nil and repodest ~= "" then
- local arch = abuild.get_conf("CARCH")
- return repodest.."/"..M.get_repo_name(pkg).."/"..arch.."/"..M.get_apk_filename(pkg)
- end
- return pkg.dir.."/"..M.get_apk_filename(pkg)
-end
-
-
local function init_apkdb(repodirs)
local pkgdb = {}
local revdeps = {}
@@ -181,7 +91,7 @@ local function init_apkdb(repodirs)
if pkgdb[a.pkgname] == nil then
pkgdb[a.pkgname] = {}
end
- a.all_deps = M.all_deps
+ pkg.init(a)
table.insert(pkgdb[a.pkgname], a)
-- add subpackages to package db
local k,v
@@ -192,7 +102,7 @@ local function init_apkdb(repodirs)
table.insert(pkgdb[v], a)
end
-- add to reverse dependencies
- for v in pairs(M.all_deps(a)) do
+ for v in pairs(a:all_deps()) do
if revdeps[v] == nil then
revdeps[v] = {}
end
@@ -216,7 +126,7 @@ function Aports:recursive_dependencies(pn)
local _, p
for _, p in pairs(apkdb[pn]) do
local d
- for d in pairs(M.all_deps(p)) do
+ for d in pairs(p:all_deps()) do
if recurs(d) then
return true
end
diff --git a/aports/pkg.lua b/aports/pkg.lua
new file mode 100644
index 0000000..276a7b8
--- /dev/null
+++ b/aports/pkg.lua
@@ -0,0 +1,101 @@
+
+local M = {}
+local abuild = require('aports.abuild')
+
+-- return a key list with makedepends and depends
+function M.all_deps(p)
+ local m = {}
+ local k,v
+ if p == nil then
+ return m
+ end
+ 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
+end
+
+function M.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
+
+-- iterator for all remote sources of given pkg/aport
+function M.remote_sources(p)
+ if p == nil or type(p.source) ~= "table" then
+ return nil
+ end
+ return coroutine.wrap(function()
+ for _,url in pairs(p.source) do
+ if M.is_remote(url) then
+ coroutine.yield(url)
+ end
+ end
+ end)
+end
+
+function M.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
+
+function M.get_repo_name(pkg)
+ if pkg == nil or pkg.dir == nil then
+ return nil
+ end
+ return string.match(pkg.dir, ".*/(.*)/.*")
+end
+
+function M.get_apk_file_name(pkg)
+ return pkg.pkgname.."-"..pkg.pkgver.."-r"..pkg.pkgrel..".apk"
+end
+
+function M.get_apk_file_path(pkg)
+ local pkgdest = abuild.get_conf("PKGDEST")
+ if pkgdest ~= nil and pkgdest ~= "" then
+ return pkgdest.."/"..M.get_apk_filename(pkg)
+ end
+ local repodest = abuild.get_conf("REPODEST")
+ if repodest ~= nil and repodest ~= "" then
+ local arch = abuild.get_conf("CARCH")
+ return repodest.."/"..M.get_repo_name(pkg).."/"..arch.."/"..M.get_apk_filename(pkg)
+ end
+ return pkg.dir.."/"..M.get_apk_filename(pkg)
+end
+
+function M.init(pkg)
+ pkg.all_deps = M.all_deps
+ pkg.remote_sources = M.remote_sources
+ pkg.get_maintainer = M.get_maintainer
+ pkg.get_repo_name = M.get_repo_name
+ pkg.get_apk_file_name = M.get_apk_file_name
+ pkg.get_apk_file_path = M.get_apk_file_path
+end
+return M