diff --git a/svupdater/autorun.py b/svupdater/autorun.py index 1198e2c4141a6c7ccaf1397a3a31f99b1d855595..a5849a285a087c8255d59d54b74e0639ed2726e1 100644 --- a/svupdater/autorun.py +++ b/svupdater/autorun.py @@ -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') diff --git a/svupdater/l10n.py b/svupdater/l10n.py index 271a9b7cf5be8aa6e3a04111e6d3b82c285dce78..bbe3c6b1a7c2b2447d3a915546182e89fa9c5b29 100644 --- a/svupdater/l10n.py +++ b/svupdater/l10n.py @@ -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)