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

use new style exceptions everywhere

parent 81c77d54
......@@ -26,7 +26,7 @@ from . import autorun, const
from .utils import check_exclusive_lock as _check_exclusive_lock
from .utils import daemonize as _daemonize
from ._pidlock import pid_locked as _pid_locked
from .exceptions import ExceptionUpdaterDisabled
from .exceptions import UpdaterDisabledError
from ._supervisor import run as _run
from .prerun import wait_for_network as _wait_for_network
......@@ -59,7 +59,7 @@ def run(wait_for_network=False, ensure_run=False, timeout=const.PKGUPDATE_TIMEOU
You can pass hooks (single line shell scripts) to be run after updater.
"""
if not autorun.enabled():
raise ExceptionUpdaterDisabled(
raise UpdaterDisabledError(
"Can't run. Updater is configured to be disabled.")
# Fork to daemon
if _daemonize():
......
......@@ -34,7 +34,7 @@ import errno
import signal
from .const import PID_FILE_PATH
from .utils import report, check_exclusive_lock
from .exceptions import ExceptionUpdaterPidLockFailure
from .exceptions import UpdaterPidLockFailureError
def pid_locked():
......@@ -181,7 +181,7 @@ class PidLock():
"""Free pid lock if we have it at the moment
"""
if self.file is None:
raise ExceptionUpdaterPidLockFailure(
raise UpdaterPidLockFailureError(
"Can't free not taken pidlock")
file = self.file
self.file = None
......@@ -195,7 +195,7 @@ class PidLock():
"""Block read access to pid lock.
"""
if self.file is None:
raise ExceptionUpdaterPidLockFailure(
raise UpdaterPidLockFailureError(
"Can't block not taken pidlock")
# TODO timeout
fcntl.flock(self.file, fcntl.LOCK_EX)
......@@ -205,7 +205,7 @@ class PidLock():
lock is acquired it is blocking read access.
"""
if self.file is None:
raise ExceptionUpdaterPidLockFailure(
raise UpdaterPidLockFailureError(
"Can't block not taken pidlock")
# TODO timeout
fcntl.flock(self.file, fcntl.LOCK_SH)
......@@ -26,7 +26,7 @@ import os
import time
from . import const, autorun, notify
from .utils import report
from .exceptions import ExceptionUpdaterApproveInvalid
from .exceptions import UpdaterApproveInvalidError
# TODO do we want to have list of packages that are auto approved?
# This would be beneficial for packages such as base-files that are updated
......@@ -117,7 +117,7 @@ def _set_stat(status, hsh):
cols.extend(file.readline().split(' '))
if hsh is not None and cols[0].strip() != hsh:
raise ExceptionUpdaterApproveInvalid("Not matching hash passed")
raise UpdaterApproveInvalidError("Not matching hash passed")
# Write new stat
cols[1] = status
......@@ -127,7 +127,7 @@ def _set_stat(status, hsh):
def approve(hsh):
"""Approve current plan. Passed hash should match with hash returned from
current(). If it doesn't match then ExceptionUpdaterApproveInvalid is
current(). If it doesn't match then UpdaterApproveInvalidError is
thrown. You can pass None to skip this check.
"""
_set_stat('granted', hsh)
......@@ -136,7 +136,7 @@ def approve(hsh):
def deny(hsh):
"""Deny current plan. This makes it effectively never timeout
(automatically installed). Passed hash should be same as the one returned
from current(). If it doesn't match then ExceptionUpdaterApproveInvalid is
from current(). If it doesn't match then UpdaterApproveInvalidError is
thrown. You can pass None to skip this check.
"""
_set_stat('denied', hsh)
......
......@@ -31,7 +31,7 @@ from threading import Thread
from .utils import report
from ._pidlock import pid_locked
from .const import POSTRUN_HOOK_FILE
from .exceptions import ExceptionUpdaterInvalidHookCommand
from .exceptions import UpdaterInvalidHookCommandError
def __run_command(command):
......@@ -67,7 +67,7 @@ def register(command):
"commands" has to be single line shell script.
"""
if '\n' in command:
raise ExceptionUpdaterInvalidHookCommand(
raise UpdaterInvalidHookCommandError(
"Argument register can be only single line string.")
# Open file for writing and take exclusive lock
file = os.open(POSTRUN_HOOK_FILE, os.O_WRONLY | os.O_CREAT | os.O_APPEND)
......
......@@ -25,7 +25,7 @@
import os
from uci import Uci, UciExceptionNotFound
from .const import L10N_FILE
from .exceptions import ExceptionUpdaterNoSuchLang
from .exceptions import UpdaterNoSuchLangError
def languages():
......@@ -67,7 +67,7 @@ def update_languages(langs):
expected.add(line.strip())
for lang in langs:
if lang not in expected:
raise ExceptionUpdaterNoSuchLang(
raise UpdaterNoSuchLangError(
"Can't enable unsupported language code:" + str(lang))
# Set
......
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