Verified Commit 3c4e1b55 authored by Martin Matějek's avatar Martin Matějek
Browse files

use generic get/set euci functions

parent f677115f
......@@ -23,8 +23,7 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import typing
from uci import UciExceptionNotFound
from euci import EUci
from euci import EUci, UciExceptionNotFound
def enabled() -> typing.Optional[bool]:
......@@ -36,7 +35,7 @@ def enabled() -> typing.Optional[bool]:
"""
with EUci() as uci:
try:
return uci.get_boolean("updater", "autorun", "enable")
return uci.get("updater", "autorun", "enable", dtype=bool)
except UciExceptionNotFound:
# No option means disabled but instead of False we return None to
# allow to handle no setting situation.
......@@ -49,7 +48,7 @@ def set_enabled(enable: bool):
"""
with EUci() as uci:
uci.set('updater', 'autorun', 'autorun')
uci.set_boolean('updater', 'autorun', 'enable', enable)
uci.set('updater', 'autorun', 'enable', enable)
def approvals() -> bool:
......@@ -57,10 +56,7 @@ def approvals() -> bool:
Relevant uci configuration is: updater.autorun.approvals
"""
with EUci() as uci:
try:
return uci.get_boolean("updater", "autorun", "approvals")
except UciExceptionNotFound:
return False # No option means disabled
return uci.get("updater", "autorun", "approvals", dtype=bool, default=False)
def set_approvals(enabled: bool):
......@@ -69,7 +65,7 @@ def set_approvals(enabled: bool):
"""
with EUci() as uci:
uci.set('updater', 'autorun', 'autorun')
uci.set_boolean('updater', 'autorun', 'approvals', enabled)
uci.set('updater', 'autorun', 'approvals', enabled)
def auto_approve_time() -> typing.Optional[int]:
......@@ -78,11 +74,8 @@ def auto_approve_time() -> typing.Optional[int]:
This is releavant to uci config: updater.autorun.auto_approve_time
"""
with EUci() as uci:
try:
value = uci.get_integer("updater", "autorun", "auto_approve_time")
return value if value > 0 else None
except UciExceptionNotFound:
return 0
value = uci.get("updater", "autorun", "auto_approve_time", dtype=int, default=0)
return value if value > 0 else None
def set_auto_approve_time(approve_time: typing.Optional[int]):
......@@ -93,6 +86,6 @@ def set_auto_approve_time(approve_time: typing.Optional[int]):
with EUci() as uci:
if approve_time and approve_time > 0:
uci.set('updater', 'autorun', 'autorun')
uci.set_integer('updater', 'autorun', 'auto_approve_time', approve_time)
uci.set('updater', 'autorun', 'auto_approve_time', approve_time)
else:
uci.delete('updater', 'autorun', 'auto_approve_time')
......@@ -23,12 +23,13 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
from uci import Uci, UciExceptionNotFound
import typing
from euci import EUci
from .const import L10N_FILE
from .exceptions import UpdaterNoSuchLangError
def languages():
def languages() -> typing.Dict[str, bool]:
"""Returns dict with all available l10n translations for system packages.
"""
result = dict()
......@@ -40,19 +41,15 @@ def languages():
continue # ignore empty lines
result[line.strip()] = False
with Uci() as uci:
try:
l10n_enabled = uci.get("updater", "l10n", "langs")
except (UciExceptionNotFound, KeyError):
# If we fail to get that section then just ignore
return result
with EUci() as uci:
l10n_enabled = uci.get("updater", "l10n", "langs", list=True, default=[])
for lang in l10n_enabled:
result[lang] = True
return result
def update_languages(langs):
def update_languages(langs: typing.Iterable[str]):
"""Updates what languages should be installed to system.
langs is expected to be a list of strings where values are ISO languages
codes.
......@@ -71,6 +68,6 @@ def update_languages(langs):
"Can't enable unsupported language code:" + str(lang))
# Set
with Uci() as uci:
with EUci() as uci:
uci.set('updater', 'l10n', 'l10n')
uci.set('updater', 'l10n', 'langs', tuple(langs))
uci.set('updater', 'l10n', 'langs', langs)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment