Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
updater
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michal Čihař
updater
Commits
21e82a22
Verified
Commit
21e82a22
authored
Feb 15, 2016
by
Michal 'vorner' Vaner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parser: Post-process a package table
Parse some of the fields there.
parent
7701e24a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
1 deletion
+95
-1
src/lib/autoload/a_04_backend.lua
src/lib/autoload/a_04_backend.lua
+50
-0
tests/backend.lua
tests/backend.lua
+40
-0
tests/lunit-launch/launch.lua
tests/lunit-launch/launch.lua
+5
-1
No files found.
src/lib/autoload/a_04_backend.lua
View file @
21e82a22
...
...
@@ -18,6 +18,7 @@ along with Updater. If not, see <http://www.gnu.org/licenses/>.
]]
--
local
error
=
error
local
type
=
type
module
"backend"
...
...
@@ -87,4 +88,53 @@ function split_blocks(string)
return
filter_empty
end
--[[
Postprocess the table representing a status of a package. The original table
is modified and returned.
It does:
Splitting these fielts into subtables of items:
Conffiles
Depends
Status
]]
function
package_postprocess
(
status
)
--[[
If the field is present, it replaces it with a new table.
The table is created from the field by splitting it by
separator (list of „forbidden“ characters and extracting
two fields from cleanup pattern. If only one is provided,
the second is replaced by true. If the cleanup doesn't match,
the part is thrown away.
]]
local
function
replace
(
name
,
separator
,
cleanup
)
if
type
(
cleanup
)
==
"string"
then
local
c
=
cleanup
cleanup
=
function
(
s
)
return
s
:
match
(
c
)
end
end
local
value
=
status
[
name
]
if
value
then
local
result
=
{}
for
item
in
value
:
gmatch
(
"[^"
..
separator
..
"]+"
)
do
local
n
,
v
=
cleanup
(
item
)
if
n
then
if
not
v
then
v
=
true
end
result
[
n
]
=
v
end
end
status
[
name
]
=
result
end
end
-- Conffiles are lines with two „words“
replace
(
"Conffiles"
,
"
\n
"
,
"%s*(%S+)%s+(%S+)"
)
-- Depends are separated by commas and may contain a version in parentheses
local
idx
=
0
replace
(
"Depends"
,
","
,
function
(
s
)
idx
=
idx
+
1
return
idx
,
s
:
gsub
(
"%s"
,
""
):
gsub
(
"%
(
"
,
"
(
"
)
end
)
replace
(
"Status"
,
" "
,
"(%S+)"
)
return
status
end
return
_M
tests/backend.lua
View file @
21e82a22
...
...
@@ -90,3 +90,43 @@ block 2
]]
,
{
'block 1'
,
'block 2'
})
-- Few empty lines at the beginning - should not produce an empty block
end
--[[
Test post-processing packages. Examples taken and combined from real status file
(however, this exact package doesn't exist).
]]
function
test_package_postprocces
()
local
package
=
{
Package
=
"dnsmasq-dhcpv6"
,
Version
=
"2.73-1"
,
Depends
=
"libc, kernel (= 3.18.21-1-70ea6b9a4b789c558ac9d579b5c1022f-10), kmod-nls-base"
,
Status
=
"install user installed"
,
Architecture
=
"mpc85xx"
,
Conffiles
=
[[
/etc/config/dhcp f81fe9bd228dede2165be71e5c9dcf76cc
/etc/dnsmasq.conf 1e6ab19c1ae5e70d609ac7b6246541d520]]
}
local
output
=
B
.
package_postprocess
(
package
)
-- Make sure it modifies the table in-place
assert_equal
(
package
,
output
)
assert_table_equal
({
install
=
true
,
user
=
true
,
installed
=
true
},
output
.
Status
)
assert_table_equal
({[
"/etc/config/dhcp"
]
=
"f81fe9bd228dede2165be71e5c9dcf76cc"
,
[
"/etc/dnsmasq.conf"
]
=
"1e6ab19c1ae5e70d609ac7b6246541d520"
},
output
.
Conffiles
)
assert_table_equal
({
"libc"
,
"kernel (=3.18.21-1-70ea6b9a4b789c558ac9d579b5c1022f-10)"
,
"kmod-nls-base"
},
output
.
Depends
)
--[[
Now check it doesn't get confused when some of the modified fields aren't there
(or none, in this case).
]]
local
pack_nomod
=
{
Package
=
"wget"
,
Version
=
"1.17.1-1"
,
Architecture
=
"mpc85xx"
}
local
pack_nomod_cp
=
{}
for
n
,
v
in
pairs
(
pack_nomod
)
do
pack_nomod_cp
[
n
]
=
v
end
local
output
=
B
.
package_postprocess
(
pack_nomod
)
assert_not_equal
(
pack_nomod_cp
,
output
)
assert_equal
(
pack_nomod
,
output
)
assert_table_equal
(
pack_nomod_cp
,
output
)
end
tests/lunit-launch/launch.lua
View file @
21e82a22
...
...
@@ -6,9 +6,13 @@ function launch(test)
end
function
assert_table_equal
(
t1
,
t2
)
lunit
.
assert_table
(
t1
)
lunit
.
assert_table
(
t2
)
local
function
cmp
(
t1
,
t2
,
name
)
for
k
,
v
in
pairs
(
t1
)
do
lunit
.
assert_equal
(
v
,
t2
[
k
],
"Values for key '"
..
k
..
"' differ: '"
..
v
..
"' vs '"
..
t2
[
k
]
..
"'"
..
name
)
local
v2
=
t2
[
k
]
if
v2
==
nil
then
v2
=
"nil"
end
lunit
.
assert_equal
(
v
,
t2
[
k
],
"Values for key '"
..
k
..
"' differ: '"
..
tostring
(
v
)
..
"' vs '"
..
tostring
(
v2
)
..
"'"
..
name
)
end
end
cmp
(
t1
,
t2
,
" pass 1"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment