mirror of
https://github.com/altlinux/gpupdate.git
synced 2025-03-28 14:50:14 +03:00
gpupdate moved into main package
This commit is contained in:
parent
5c89834908
commit
ba6ea5522d
@ -5,10 +5,17 @@ import argparse
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import dbus
|
||||
import logging
|
||||
import pwd
|
||||
|
||||
from util.users import (
|
||||
is_root
|
||||
)
|
||||
from util.dbus import (
|
||||
is_oddjobd_gpupdate_accessible,
|
||||
dbus_runner
|
||||
)
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
class file_runner:
|
||||
@ -28,35 +35,6 @@ class file_runner:
|
||||
output = subprocess.call(gpoa_cmd)
|
||||
sys.exit(output)
|
||||
|
||||
def print_dbus_result(result):
|
||||
exitcode = result[0]
|
||||
message = result[1:]
|
||||
logging.debug('Exit code is {}'.format(exitcode))
|
||||
for line in message:
|
||||
print(str(line))
|
||||
|
||||
class dbus_runner:
|
||||
_bus_name = 'com.redhat.oddjob_gpupdate'
|
||||
_object_path = '/'
|
||||
|
||||
def __init__(self, username=None):
|
||||
self.username = username
|
||||
system_bus = dbus.SystemBus()
|
||||
obj = system_bus.get_object(self._bus_name, self._object_path)
|
||||
self.interface = dbus.Interface(obj, self._bus_name)
|
||||
|
||||
def run(self):
|
||||
#print(obj.Introspect()[0])
|
||||
if self.username:
|
||||
logging.info('Starting GPO applier for user {} via D-Bus'.format(self.username))
|
||||
result = self.interface.gpupdatefor(dbus.String(self.username))
|
||||
print_dbus_result(result)
|
||||
else:
|
||||
result = self.interface.gpupdate()
|
||||
print_dbus_result(result)
|
||||
#self.interface.Quit()
|
||||
|
||||
|
||||
def parse_cli_arguments():
|
||||
'''
|
||||
Command line argument parser
|
||||
@ -69,43 +47,6 @@ def parse_cli_arguments():
|
||||
|
||||
return argparser.parse_args()
|
||||
|
||||
def is_oddjobd_gpupdate_accessible():
|
||||
'''
|
||||
Check is oddjobd is running via systemd so it will be possible
|
||||
to run gpoa via D-Bus
|
||||
'''
|
||||
try:
|
||||
system_bus = dbus.SystemBus()
|
||||
systemd_bus = system_bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
|
||||
systemd_interface = dbus.Interface(systemd_bus, 'org.freedesktop.systemd1.Manager')
|
||||
oddjobd_unit = systemd_interface.GetUnit(dbus.String('oddjobd.service'))
|
||||
|
||||
oddjobd_proxy = system_bus.get_object('org.freedesktop.systemd1', str(oddjobd_unit))
|
||||
oddjobd_properties = dbus.Interface(oddjobd_proxy, dbus_interface='org.freedesktop.DBus.Properties')
|
||||
|
||||
# Check if oddjobd service is running
|
||||
oddjobd_state = oddjobd_properties.Get('org.freedesktop.systemd1.Unit', 'ActiveState')
|
||||
|
||||
# Check if oddjobd_gpupdate is accesssible
|
||||
oddjobd_gpupdate = system_bus.get_object('com.redhat.oddjob_gpupdate', '/')
|
||||
oddjobd_upupdate_interface = dbus.Interface(oddjobd_gpupdate, 'com.redhat.oddjob_gpupdate')
|
||||
#oddjobd_upupdate_interface.gpupdate()
|
||||
|
||||
if oddjobd_state == 'active':
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
def is_root():
|
||||
'''
|
||||
Check UID.
|
||||
'''
|
||||
if os.geteuid() == 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
def runner_factory(args):
|
||||
'''
|
||||
Return the necessary runner class according to some
|
Loading…
x
Reference in New Issue
Block a user