mirror of
https://github.com/altlinux/gpupdate.git
synced 2025-03-22 02:50:32 +03:00
Merge pull request #34 from altlinux/dbus_exception_catch
D-Bus exception catch
This commit is contained in:
commit
ae156bcb92
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
||||
__pycache__
|
||||
*~
|
||||
_opam
|
||||
_build
|
||||
|
||||
|
@ -44,6 +44,22 @@ Show help.
|
||||
\fB--user \fIusername\fR
|
||||
Run \fBgpupdate\fP for \fIusername\fP.
|
||||
.
|
||||
.SS "EXIT CODES"
|
||||
.TP
|
||||
\fB0\fR
|
||||
Application exited successfully.
|
||||
.TP
|
||||
\fB1\fR
|
||||
No runner is able to start \fBgpoa\fR.
|
||||
.TP
|
||||
\fB2\fR
|
||||
No reply from \fID-Bus\fR when starting \fBgpoa\fR for computer using
|
||||
\fBoddjobd\fR via \fID-Bus\fR.
|
||||
.TP
|
||||
\fB3\fR
|
||||
No reply from \fID-Bus\fR when starting \fBgpoa\fR for user using
|
||||
\fBoddjobd\fR via \fID-Bus\fR.
|
||||
.
|
||||
.SH "SEE ALSO"
|
||||
gpoa(1)
|
||||
.SH BUGS
|
||||
|
@ -29,7 +29,8 @@ from util.users import (
|
||||
is_root
|
||||
)
|
||||
from util.arguments import (
|
||||
process_target
|
||||
process_target,
|
||||
ExitCodeUpdater
|
||||
)
|
||||
from util.dbus import (
|
||||
is_oddjobd_gpupdate_accessible,
|
||||
@ -132,14 +133,27 @@ def runner_factory(args, target):
|
||||
def main():
|
||||
args = parse_cli_arguments()
|
||||
gpo_appliers = runner_factory(args, process_target(args.target))
|
||||
|
||||
if gpo_appliers:
|
||||
if gpo_appliers[0]:
|
||||
gpo_appliers[0].run()
|
||||
try:
|
||||
gpo_appliers[0].run()
|
||||
except Exception as exc:
|
||||
logging.error('Error running GPOA for computer: {}'.format(exc))
|
||||
return int(ExitCodeUpdater.FAIL_GPUPDATE_COMPUTER_NOREPLY)
|
||||
|
||||
if gpo_appliers[1]:
|
||||
gpo_appliers[1].run()
|
||||
try:
|
||||
gpo_appliers[1].run()
|
||||
except Exception as exc:
|
||||
logging.error('Error running GPOA for user: {}'.format(exc))
|
||||
return int(ExitCodeUpdater.FAIL_GPUPDATE_USER_NOREPLY)
|
||||
else:
|
||||
logging.error('gpupdate will not be started')
|
||||
return int(ExitCodeUpdater.FAIL_NO_RUNNER)
|
||||
|
||||
return int(ExitCodeUpdater.EXIT_SUCCESS)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
sys.exit(int(main()))
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
from enum import IntEnum
|
||||
|
||||
from .logging import slogm
|
||||
|
||||
@ -75,3 +76,12 @@ def process_target(target_name=None):
|
||||
|
||||
return target
|
||||
|
||||
class ExitCodeUpdater(IntEnum):
|
||||
'''
|
||||
Exit code contract for gpupdate application
|
||||
'''
|
||||
EXIT_SUCCESS = 0
|
||||
FAIL_NO_RUNNER = 1
|
||||
FAIL_GPUPDATE_COMPUTER_NOREPLY = 2
|
||||
FAIL_GPUPDATE_USER_NOREPLY = 3
|
||||
|
||||
|
@ -43,14 +43,27 @@ class dbus_runner:
|
||||
if self.username:
|
||||
logging.info(slogm('Starting GPO applier for user {} via D-Bus'.format(self.username)))
|
||||
if is_root():
|
||||
result = self.interface.gpupdatefor(dbus.String(self.username))
|
||||
try:
|
||||
result = self.interface.gpupdatefor(dbus.String(self.username))
|
||||
print_dbus_result(result)
|
||||
except dbus.exceptions.DBusException as exc:
|
||||
logging.error(slogm('No reply from oddjobd gpoa runner for {}'.format(self.username)))
|
||||
raise exc
|
||||
else:
|
||||
result = self.interface.gpupdate()
|
||||
print_dbus_result(result)
|
||||
try:
|
||||
result = self.interface.gpupdate()
|
||||
print_dbus_result(result)
|
||||
except dbus.exceptions.DBusException as exc:
|
||||
logging.error(slogm('No reply from oddjobd gpoa runner for current user'))
|
||||
raise exc
|
||||
else:
|
||||
logging.info(slogm('Starting GPO applier for computer via D-Bus'))
|
||||
result = self.interface.gpupdate_computer()
|
||||
print_dbus_result(result)
|
||||
try:
|
||||
result = self.interface.gpupdate_computer()
|
||||
print_dbus_result(result)
|
||||
except dbus.exceptions.DBusException as exc:
|
||||
logging.error(slogm('No reply from oddjobd gpoa runner for computer'))
|
||||
raise exc
|
||||
#self.interface.Quit()
|
||||
|
||||
|
||||
|
2
wiki
2
wiki
@ -1 +1 @@
|
||||
Subproject commit a1333257b6b30fbd92ead397abc673d4b9d60d82
|
||||
Subproject commit 8cb284e0f7fc4991272eba9ef4c00f3609c2927a
|
Loading…
x
Reference in New Issue
Block a user