diff --git a/src/python/jw/pkg/cmds/distro/CmdRebootRequired.py b/src/python/jw/pkg/cmds/distro/CmdRebootRequired.py new file mode 100644 index 00000000..21abc89e --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/CmdRebootRequired.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +from argparse import Namespace, ArgumentParser + +from .Cmd import Cmd +from ..CmdDistro import CmdDistro + +class CmdRebootRequired(Cmd): # export + + def __init__(self, parent: CmdDistro) -> None: + super().__init__(parent, 'reboot-required', help="Check whether the machine needs rebooting") + + def add_arguments(self, parser: ArgumentParser) -> None: + super().add_arguments(parser) + parser.add_argument('--verbose', default=False, action='store_true', help='Be chatty about the check') + + async def _run(self, args: Namespace) -> None: + return await self._backend.run(args) diff --git a/src/python/jw/pkg/cmds/distro/backend/BeRebootRequired.py b/src/python/jw/pkg/cmds/distro/backend/BeRebootRequired.py new file mode 100644 index 00000000..5e658e2c --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/backend/BeRebootRequired.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +import abc +from argparse import Namespace + +from .Backend import Backend as Base +from ..CmdRebootRequired import CmdRebootRequired as Parent + +class BeRebootRequired(Base): + + def __init__(self, parent: Parent): + super().__init__(parent) + + @abc.abstractmethod + async def run(self, args: Namespace) -> None: + pass diff --git a/src/python/jw/pkg/cmds/distro/backend/debian/RebootRequired.py b/src/python/jw/pkg/cmds/distro/backend/debian/RebootRequired.py new file mode 100644 index 00000000..533b1145 --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/backend/debian/RebootRequired.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +import os +from argparse import Namespace + +from .....lib.log import * +from ...Cmd import Cmd +from ..BeRebootRequired import BeRebootRequired as Base + +class RebootRequired(Base): + + def __init__(self, parent: Cmd): + super().__init__(parent) + + async def run(self, args: Namespace): + reboot_required = '/run/reboot_required' + if os.path.exists(reboot_required): + if args.verbose: + log(NOTICE, f'Yes. {reboot_required} exists.') + required_pkgs = '/run/reboot-required.pkgs' + if os.path.exists(required_pkgs): + with open(required_pkgs, 'r') as f: + content = f.read() + print(f'-- From {required_pkgs}:') + print(content.strip()) + return 1 + if args.verbose: + log(NOTICE, f'No. {reboot_required} doesn\'t exist.') + return 0 diff --git a/src/python/jw/pkg/cmds/distro/backend/suse/RebootRequired.py b/src/python/jw/pkg/cmds/distro/backend/suse/RebootRequired.py new file mode 100644 index 00000000..8e8c5c82 --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/backend/suse/RebootRequired.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +from argparse import Namespace + +from ...Cmd import Cmd +from ..BeRebootRequired import BeRebootRequired as Base + +class RebootRequired(Base): + + def __init__(self, parent: Cmd): + super().__init__(parent) + + async def run(self, args: Namespace): + opts = [] + if not args.verbose: + pass + #opts.append('--quiet') + opts.append('needs-rebooting') + stdout, stderr, ret = await self.util.zypper(opts, sudo=False, verbose=args.verbose) + if ret != 0: + return 1 + return 0