Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Turris
pyuci
Commits
9b4739f5
Verified
Commit
9b4739f5
authored
Mar 15, 2018
by
Karel Koci
🤘
Browse files
Commit all changes when leaving context
parent
adbff4eb
Pipeline
#34411
passed with stage
in 34 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
pyuci.c
View file @
9b4739f5
...
...
@@ -64,8 +64,20 @@ static PyObject *pyuci_enter(uci_object *self, PyObject *args) {
}
static
PyObject
*
pyuci_exit
(
uci_object
*
self
,
PyObject
*
args
)
{
if
(
self
->
ctx
)
if
(
self
->
ctx
)
{
// Commit all changes
struct
uci_ptr
ptr
;
memset
(
&
ptr
,
0
,
sizeof
ptr
);
struct
uci_element
*
e
,
*
tmp
;
uci_foreach_element_safe
(
&
self
->
ctx
->
root
,
tmp
,
e
)
{
struct
uci_package
*
p
=
uci_to_package
(
e
);
if
(
ptr
.
p
&&
(
ptr
.
p
!=
p
))
continue
;
ptr
.
p
=
p
;
uci_commit
(
self
->
ctx
,
&
p
,
false
);
}
uci_free_context
(
self
->
ctx
);
}
self
->
ctx
=
NULL
;
Py_RETURN_NONE
;
}
...
...
tests/test_module.py
View file @
9b4739f5
...
...
@@ -177,3 +177,17 @@ config testing 'testing'
with
uci
.
Uci
(
confdir
=
tmpdir
.
strpath
)
as
u
:
assert
u
.
get
(
'test'
,
'testing'
,
'one'
)
==
'0'
assert
u
.
get
(
'test'
,
'testing'
,
'two'
)
==
'1'
def
test_context_commit
(
tmpdir
):
"""Test that when we leave context that we commit. This depends on working
test_set.
"""
tmpdir
.
join
(
'test'
).
write
(
""
)
with
uci
.
Uci
(
confdir
=
tmpdir
.
strpath
)
as
u
:
u
.
set
(
'test'
,
'testing'
,
'testing'
)
u
.
set
(
'test'
,
'testing'
,
'one'
,
'0'
)
u
.
set
(
'test'
,
'testing'
,
'two'
,
'1'
)
with
uci
.
Uci
(
confdir
=
tmpdir
.
strpath
)
as
u
:
assert
u
.
get
(
'test'
,
'testing'
,
'one'
)
==
'0'
assert
u
.
get
(
'test'
,
'testing'
,
'two'
)
==
'1'
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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