blob: 276a7b8decfd16cc64d37636a9c5f269a18a2a3c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
|