-
Notifications
You must be signed in to change notification settings - Fork 0
/
rosa.lua
212 lines (200 loc) · 7.29 KB
/
rosa.lua
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/lua
local lfs = require("lfs") -- need lfs lib
local json = require("json")
local function get_pkgdir(command)
local pkglist = io.popen(command)
local pkgdir = {}
for line in pkglist:lines() do
line = line:gsub("\n", "")
table.insert(pkgdir, line)
end
pkglist:close()
return pkgdir
end
local function get_string(linestr, desc_tmp)
local file_res = ""
local cont = false
for line in desc_tmp:gmatch("[^\n]+") do
if line == linestr or cont then -- If find %FILES%
cont = true -- start reading
if line:match("^%s*$") or (line:sub(1,1) == "%" and line ~= linestr) then -- find empty line or (start symbol is % and not linestr)
cont = false -- stop reading
elseif cont and line ~= linestr then
file_res = file_res .. line .. "\n"
end
end
end
return file_res
end
local function get_content(pkgdir)
local name_ct, base_ct, version_ct, desc_ct, csize_ct, isize_ct, url_ct, license_ct, arch_ct, builddate_ct, packager_ct, depends_ct, optdepends_ct, makedepends_ct, files_ct = {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}
for i = 1, #pkgdir do
local desc_tm = io.open("data/" .. pkgdir[i] .. "/desc", "r")
local desc_tmp = desc_tm:read("*a")
desc_tm:close()
-- read name --
local desc_res = get_string("%NAME%", desc_tmp)
desc_res = desc_res:gsub("\n", "")
table.insert(name_ct, desc_res)
local desc_res = ""
-- read base --
local desc_res = get_string("%BASE%", desc_tmp)
desc_res = desc_res:gsub("\n", "")
table.insert(base_ct, desc_res)
local desc_res = ""
-- read version --
local desc_res = get_string("%VERSION%", desc_tmp)
desc_res = desc_res:gsub("\n", "")
table.insert(version_ct, desc_res)
local desc_res = ""
-- read desc --
local desc_res = get_string("%DESC%", desc_tmp)
desc_res = desc_res:gsub("\n", "")
table.insert(desc_ct, desc_res)
local desc_res = ""
-- read csize --
local desc_res = get_string("%CSIZE%", desc_tmp)
desc_res = desc_res:gsub("\n", "")
table.insert(csize_ct, desc_res)
local desc_res = ""
-- read isize --
local desc_res = get_string("%ISIZE%", desc_tmp)
desc_res = desc_res:gsub("\n", "")
table.insert(isize_ct, desc_res)
local desc_res = ""
-- read url --
local desc_res = get_string("%URL%", desc_tmp)
desc_res = desc_res:gsub("\n", "")
table.insert(url_ct, desc_res)
local desc_res = ""
-- read license --
local desc_res = get_string("%LICENSE%", desc_tmp)
table.insert(license_ct, desc_res)
local desc_res = ""
-- read arch --
local desc_res = get_string("%ARCH%", desc_tmp)
table.insert(arch_ct, desc_res)
local desc_res = ""
-- read builddate --
local desc_res = get_string("%BUILDDATE%", desc_tmp)
desc_res = desc_res:gsub("\n", "")
table.insert(builddate_ct, desc_res)
local desc_res = ""
-- read packager --
local desc_res = get_string("%PACKAGER%", desc_tmp)
desc_res = desc_res:gsub("\n", "")
table.insert(packager_ct, desc_res)
local desc_res = ""
-- read depends --
local desc_res = get_string("%DEPENDS%", desc_tmp)
table.insert(depends_ct, desc_res)
local desc_res = ""
-- read optdepends --
local desc_res = get_string("%OPTDEPENDS%", desc_tmp)
table.insert(optdepends_ct, desc_res)
local desc_res = ""
-- read makedepends --
local desc_res = get_string("%MAKEDEPENDS%", desc_tmp)
table.insert(makedepends_ct, desc_res)
local desc_res = ""
end
--read desc end--
--read files--
for i = 1, #pkgdir do
local file_tm = io.open("data/" .. pkgdir[i] .. "/files", "r")
local file_tmp = file_tm:read("*a")
file_tm:close()
local file_res = get_string("%FILES%", file_tmp)
table.insert(files_ct, file_res)
end
--read files end--
return name_ct, base_ct, version_ct, desc_ct, csize_ct, isize_ct, url_ct, license_ct, arch_ct, builddate_ct, packager_ct, depends_ct, optdepends_ct, makedepends_ct, files_ct
end
local function write_api(name, func, func_str)
local nname = name:gsub("%s+", "")
lfs.mkdir("/usr/share/lilac/api/" .. nname)
local fn = string.format("/usr/share/lilac/api/%s/%s", nname, func_str)
local apifile = assert(io.open(fn, "w+"), "Error: cannot open file " .. fn)
apifile:write(func or "")
apifile:close()
end
local function gen_api(params)
os.execute("mkdir -p /usr/share/lilac/api")
local param_names = {"name", "base", "version", "desc", "csize", "isize", "url", "license", "arch", "builddate", "packager", "depends", "optdepends", "makedepends", "files"}
for i = 1, #params.name do -- #params.name: length of params.name
-- create a table
local param_table = {}
for _, param_name in ipairs(param_names) do
-- insert para into table
param_table[param_name] = params[param_name][i]
end
-- convert table to json
local param_json = json.encode(param_table)
local file = io.open("/usr/share/lilac/api/" .. params.name[i] .. ".json", "w")
file:write(param_json .. "\n")
file:close()
end
end
local function gen_pkglist(name)
local name_json = json.encode(name)
local file = io.open("/usr/share/lilac/api/pkglist.json", "w")
file:write(name_json .. "\n")
file:close()
end
local function gen_index(params_pkglist)
local combined_params = {}
for i = 1, #params_pkglist.name do
table.insert(combined_params, {
name = params_pkglist.name[i],
version = params_pkglist.version[i],
desc = params_pkglist.desc[i],
builddate = params_pkglist.builddate[i]
})
end
local pkglist_json = json.encode(combined_params)
local file = io.open("/usr/share/lilac/api/index.json", "w")
file:write(pkglist_json .. "\n")
file:close()
end
--main function--
time = os.date("*t")
print(("%02d:%02d:%02d"):format(time.hour, time.min, time.sec))
local mk_dir = os.execute("rm -rf /usr/share/lilac/Rosa/data && mkdir -p /usr/share/lilac/Rosa/data")
if mk_dir then
os.execute("tar xf /usr/share/lilac/Repo/x86_64/bioarchlinux.files -C /usr/share/lilac/Rosa/data/")
end
local pkgdir = get_pkgdir("cd /usr/share/lilac/Rosa/data/ && ls --quoting-style=shell-escape")
local name_ct, base_ct, version_ct, desc_ct, csize_ct, isize_ct, url_ct, license_ct, arch_ct, builddate_ct, packager_ct, depends_ct, optdepends_ct, makedepends_ct, files_ct = get_content(pkgdir)
print("Sucess: read finished")
time = os.date("*t")
print(("%02d:%02d:%02d"):format(time.hour, time.min, time.sec))
os.execute("rm -rf /usr/share/lilac/api/*")
local params = {
name = name_ct,
base = base_ct,
version = version_ct,
desc = desc_ct,
csize = csize_ct,
isize = isize_ct,
url = url_ct,
license = license_ct,
arch = arch_ct,
builddate = builddate_ct,
packager = packager_ct,
depends = depends_ct,
optdepends = optdepends_ct,
makedepends = makedepends_ct,
files = files_ct
}
local indexlist = {
name = name_ct,
version = version_ct,
desc = desc_ct,
builddate = builddate_ct
}
gen_api(params)
gen_pkglist(name_ct)
gen_index(indexlist)
print("Sucess: write finished")
time = os.date("*t")
print(("%02d:%02d:%02d"):format(time.hour, time.min, time.sec))