mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 09:35:54 +02:00
jw.pkg.cmds.distro.CmdRebootRequired: Add class
Add the command distro.CmdRebootRequired, adding support for "distro reboot-required". The command exits with status code 1 if a reboot is required and 0 otherwise. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
5d95ca01ca
commit
79d40af558
4 changed files with 85 additions and 0 deletions
18
src/python/jw/pkg/cmds/distro/CmdRebootRequired.py
Normal file
18
src/python/jw/pkg/cmds/distro/CmdRebootRequired.py
Normal file
|
|
@ -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)
|
||||
16
src/python/jw/pkg/cmds/distro/backend/BeRebootRequired.py
Normal file
16
src/python/jw/pkg/cmds/distro/backend/BeRebootRequired.py
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
22
src/python/jw/pkg/cmds/distro/backend/suse/RebootRequired.py
Normal file
22
src/python/jw/pkg/cmds/distro/backend/suse/RebootRequired.py
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue