mirror of
https://github.com/altlinux/gpupdate.git
synced 2025-10-11 07:33:16 +03:00
Compare commits
2 Commits
gsettings_
...
package_pk
Author | SHA1 | Date | |
---|---|---|---|
|
d973f1b5e3 | ||
|
aaf72c5562 |
@@ -96,7 +96,7 @@ class system_gsettings:
|
||||
def glib_map(value, glib_type):
|
||||
result_value = value
|
||||
|
||||
if glib_type == 'i' or glib_type == 'b' or glib_type == 'q':
|
||||
if glib_type == 'i' or glib_type == 'b':
|
||||
result_value = GLib.Variant(glib_type, int(value))
|
||||
else:
|
||||
result_value = GLib.Variant(glib_type, value)
|
||||
|
@@ -20,7 +20,6 @@ import logging
|
||||
import os
|
||||
import pwd
|
||||
import subprocess
|
||||
import urllib.parse
|
||||
|
||||
from gi.repository import (
|
||||
Gio
|
||||
@@ -63,7 +62,6 @@ class gsettings_applier(applier_frontend):
|
||||
__registry_branch = 'Software\\BaseALT\\Policies\\GSettings\\'
|
||||
__registry_locks_branch = 'Software\\BaseALT\\Policies\\GSettingsLocks\\'
|
||||
__wallpaper_entry = 'Software\\BaseALT\\Policies\\GSettings\\org.mate.background.picture-filename'
|
||||
__vino_authentication_methods_entry = 'Software\\BaseALT\\Policies\\GSettings\\org.gnome.Vino.authentication-methods'
|
||||
__global_schema = '/usr/share/glib-2.0/schemas'
|
||||
__override_priority_file = 'zzz_policy.gschema.override'
|
||||
__override_old_file = '0_policy.gschema.override'
|
||||
@@ -119,16 +117,11 @@ class gsettings_applier(applier_frontend):
|
||||
rp = valuename.rpartition('.')
|
||||
schema = rp[0]
|
||||
path = rp[2]
|
||||
data = setting.data
|
||||
lock = bool(self.locks[valuename]) if valuename in self.locks else None
|
||||
if setting.hive_key.lower() == self.__wallpaper_entry.lower():
|
||||
check = urllib.parse.urlparse(setting.data)
|
||||
if check.scheme:
|
||||
self.update_file_cache(setting.data)
|
||||
helper = self.uri_fetch_helper
|
||||
elif setting.hive_key.lower() == self.__vino_authentication_methods_entry.lower():
|
||||
data = [setting.data]
|
||||
self.gsettings.append(schema, path, data, lock, helper)
|
||||
self.update_file_cache(setting.data)
|
||||
helper = self.uri_fetch_helper
|
||||
self.gsettings.append(schema, path, setting.data, lock, helper)
|
||||
|
||||
# Create GSettings policy with highest available priority
|
||||
self.gsettings.apply()
|
||||
@@ -189,7 +182,6 @@ class gsettings_applier_user(applier_frontend):
|
||||
__module_enabled = True
|
||||
__registry_branch = 'Software\\BaseALT\\Policies\\GSettings\\'
|
||||
__wallpaper_entry = 'Software\\BaseALT\\Policies\\GSettings\\org.mate.background.picture-filename'
|
||||
__vino_authentication_methods_entry = 'Software\\BaseALT\\Policies\\GSettings\\org.gnome.Vino.authentication-methods'
|
||||
|
||||
def __init__(self, storage, file_cache, sid, username):
|
||||
self.storage = storage
|
||||
@@ -272,11 +264,8 @@ class gsettings_applier_user(applier_frontend):
|
||||
rp = valuename.rpartition('.')
|
||||
schema = rp[0]
|
||||
path = rp[2]
|
||||
data = setting.data
|
||||
helper = self.uri_fetch_helper if setting.hive_key.lower() == self.__wallpaper_entry.lower() else None
|
||||
if setting.hive_key.lower() == self.__vino_authentication_methods_entry.lower():
|
||||
data = [setting.data]
|
||||
self.gsettings.append(user_gsetting(schema, path, data, helper))
|
||||
self.gsettings.append(user_gsetting(schema, path, setting.data, helper))
|
||||
|
||||
# Create GSettings policy with highest available priority
|
||||
for gsetting in self.gsettings:
|
||||
|
@@ -17,6 +17,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import logging
|
||||
import subprocess
|
||||
from util.logging import slogm
|
||||
from util.rpm import (
|
||||
update
|
||||
@@ -35,6 +36,7 @@ class package_applier(applier_frontend):
|
||||
__module_enabled = False
|
||||
__install_key_name = 'Install'
|
||||
__remove_key_name = 'Remove'
|
||||
__sync_key_name = 'Sync'
|
||||
__hklm_branch = 'Software\\BaseALT\\Policies\\Packages'
|
||||
|
||||
def __init__(self, storage):
|
||||
@@ -42,30 +44,47 @@ class package_applier(applier_frontend):
|
||||
|
||||
install_branch = '{}\\{}%'.format(self.__hklm_branch, self.__install_key_name)
|
||||
remove_branch = '{}\\{}%'.format(self.__hklm_branch, self.__remove_key_name)
|
||||
|
||||
sync_branch = '{}\\{}%'.format(self.__hklm_branch, self.__sync_key_name)
|
||||
self.fulcmd = list()
|
||||
self.fulcmd.append('/usr/libexec/gpupdate/pkcon_runner')
|
||||
self.install_packages_setting = self.storage.filter_hklm_entries(install_branch)
|
||||
self.remove_packages_setting = self.storage.filter_hklm_entries(remove_branch)
|
||||
self.sync_packages_setting = self.storage.filter_hklm_entries(sync_branch)
|
||||
self.flagSync = False
|
||||
|
||||
self.__module_enabled = check_enabled(
|
||||
self.storage
|
||||
, self.__module_name
|
||||
, self.__module_experimental
|
||||
)
|
||||
|
||||
def run(self):
|
||||
if 0 < self.install_packages_setting.count() or 0 < self.remove_packages_setting.count():
|
||||
update()
|
||||
for package in self.install_packages_setting:
|
||||
try:
|
||||
install_rpm(package.data)
|
||||
except Exception as exc:
|
||||
logging.error(exc)
|
||||
for flag in self.sync_packages_setting:
|
||||
if flag.data:
|
||||
self.flagSync = bool(int(flag.data))
|
||||
|
||||
for package in self.remove_packages_setting:
|
||||
if 0 < self.install_packages_setting.count() or 0 < self.remove_packages_setting.count():
|
||||
if not self.flagSync:
|
||||
try:
|
||||
remove_rpm(package.data)
|
||||
subprocess.check_call(self.fulcmd)
|
||||
except Exception as exc:
|
||||
logging.error(exc)
|
||||
else:
|
||||
try:
|
||||
subprocess.Popen(self.fulcmd,close_fds=False)
|
||||
except Exception as exc:
|
||||
logging.error(exc)
|
||||
#update()
|
||||
#for package in self.install_packages_setting:
|
||||
#try:
|
||||
# install_rpm(package.data)
|
||||
#except Exception as exc:
|
||||
# logging.error(exc)
|
||||
|
||||
#for package in self.remove_packages_setting:
|
||||
# try:
|
||||
# remove_rpm(package.data)
|
||||
# except Exception as exc:
|
||||
# logging.error(exc)
|
||||
|
||||
def apply(self):
|
||||
if self.__module_enabled:
|
||||
@@ -81,18 +100,25 @@ class package_applier_user(applier_frontend):
|
||||
__module_enabled = False
|
||||
__install_key_name = 'Install'
|
||||
__remove_key_name = 'Remove'
|
||||
__sync_key_name = 'Sync'
|
||||
__hkcu_branch = 'Software\\BaseALT\\Policies\\Packages'
|
||||
|
||||
def __init__(self, storage, sid, username):
|
||||
self.storage = storage
|
||||
self.sid = sid
|
||||
self.username = username
|
||||
self.fulcmd = list()
|
||||
self.fulcmd.append('/usr/libexec/gpupdate/pkcon_runner')
|
||||
self.fulcmd.append(self.sid)
|
||||
|
||||
install_branch = '{}\\{}%'.format(self.__hkcu_branch, self.__install_key_name)
|
||||
remove_branch = '{}\\{}%'.format(self.__hkcu_branch, self.__remove_key_name)
|
||||
sync_branch = '{}\\{}%'.format(self.__hkcu_branch, self.__sync_key_name)
|
||||
|
||||
self.install_packages_setting = self.storage.filter_hkcu_entries(self.sid, install_branch)
|
||||
self.remove_packages_setting = self.storage.filter_hkcu_entries(self.sid, remove_branch)
|
||||
self.sync_packages_setting = self.storage.filter_hkcu_entries(self.sid, sync_branch)
|
||||
self.flagSync = True
|
||||
|
||||
self.__module_enabled = check_enabled(self.storage, self.__module_name, self.__module_enabled)
|
||||
|
||||
@@ -103,19 +129,32 @@ class package_applier_user(applier_frontend):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
if 0 < self.install_packages_setting.count() or 0 < self.remove_packages_setting.count():
|
||||
update()
|
||||
for package in self.install_packages_setting:
|
||||
try:
|
||||
install_rpm(package.data)
|
||||
except Exception as exc:
|
||||
logging.debug(exc)
|
||||
for flag in self.sync_packages_setting:
|
||||
if flag.data:
|
||||
self.flagSync = bool(int(flag.data))
|
||||
|
||||
for package in self.remove_packages_setting:
|
||||
if 0 < self.install_packages_setting.count() or 0 < self.remove_packages_setting.count():
|
||||
if self.flagSync:
|
||||
try:
|
||||
remove_rpm(package.data)
|
||||
subprocess.check_call(self.fulcmd)
|
||||
except Exception as exc:
|
||||
logging.debug(exc)
|
||||
logging.error(exc)
|
||||
else:
|
||||
try:
|
||||
subprocess.Popen(self.fulcmd,close_fds=False)
|
||||
except Exception as exc:
|
||||
logging.error(exc)
|
||||
# update()
|
||||
# for package in self.install_packages_setting:
|
||||
# try:
|
||||
# install_rpm(package.data)
|
||||
# except Exception as exc:
|
||||
# logging.debug(exc)
|
||||
# for package in self.remove_packages_setting:
|
||||
# try:
|
||||
# remove_rpm(package.data)
|
||||
# except Exception as exc:
|
||||
# logging.debug(exc)
|
||||
|
||||
def admin_context_apply(self):
|
||||
'''
|
||||
|
120
gpoa/pkcon_runner
Executable file
120
gpoa/pkcon_runner
Executable file
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/python3
|
||||
#
|
||||
# GPOA - GPO Applier for Linux
|
||||
#
|
||||
# Copyright (C) 2019-2020 BaseALT Ltd.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import rpm
|
||||
import subprocess
|
||||
from gpoa.storage import registry_factory
|
||||
import logging
|
||||
import argparse
|
||||
|
||||
def is_rpm_installed(rpm_name):
|
||||
'''
|
||||
Check if the package named 'rpm_name' is installed
|
||||
'''
|
||||
ts = rpm.TransactionSet()
|
||||
pm = ts.dbMatch('name', rpm_name)
|
||||
if pm.count() > 0:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
class Pkcon_applier:
|
||||
|
||||
def __init__(self, sid = None):
|
||||
self.sid = sid
|
||||
self.__install_key_name = 'Install'
|
||||
self.__remove_key_name = 'Remove'
|
||||
self.__hkcu_branch = 'Software\\BaseALT\\Policies\\Packages'
|
||||
self.__hklm_branch = 'Software\\BaseALT\\Policies\\Packages'
|
||||
self.__install_command = ['/usr/bin/pkcon', '-y', 'install']
|
||||
self.__remove_command = ['/usr/bin/pkcon', '-y', 'remove']
|
||||
self.__reinstall_command = ['/usr/bin/pkcon', '-y', 'reinstall']
|
||||
self.install_packages = list()
|
||||
self.remove_packages = list()
|
||||
self.storage = registry_factory('registry')
|
||||
if sid:
|
||||
install_branch_user = '{}\\{}%'.format(self.__hkcu_branch, self.__install_key_name)
|
||||
remove_branch_user = '{}\\{}%'.format(self.__hkcu_branch, self.__remove_key_name)
|
||||
self.install_packages_setting = self.storage.filter_hkcu_entries(self.sid, install_branch_user)
|
||||
self.remove_packages_setting = self.storage.filter_hkcu_entries(self.sid, remove_branch_user)
|
||||
else:
|
||||
install_branch = '{}\\{}%'.format(self.__hklm_branch, self.__install_key_name)
|
||||
remove_branch = '{}\\{}%'.format(self.__hklm_branch, self.__remove_key_name)
|
||||
self.install_packages_setting = self.storage.filter_hklm_entries(install_branch)
|
||||
self.remove_packages_setting = self.storage.filter_hklm_entries(remove_branch)
|
||||
for package in self.install_packages_setting:
|
||||
if is_rpm_installed(package.data) == False:
|
||||
self.install_packages.append(package.data)
|
||||
for package in self.remove_packages_setting:
|
||||
if is_rpm_installed(package.data):
|
||||
self.remove_packages.append(package.data)
|
||||
self.install_packages = list(set(self.install_packages) - set(self.remove_packages))
|
||||
|
||||
def run(self):
|
||||
self.update()
|
||||
for package in self.remove_packages:
|
||||
try:
|
||||
self.remove_pkg(package)
|
||||
except Exception as exc:
|
||||
logging.debug(exc)
|
||||
|
||||
for package in self.install_packages:
|
||||
try:
|
||||
self.install_pkg(package)
|
||||
except Exception as exc:
|
||||
logging.debug(exc)
|
||||
|
||||
def apply(self):
|
||||
self.run()
|
||||
|
||||
def install_pkg(self, package_name):
|
||||
fullcmd = list(self.__install_command)
|
||||
fullcmd.append(package_name)
|
||||
return subprocess.check_call(fullcmd)
|
||||
|
||||
def reinstall_pkg(self, package_name):
|
||||
fullcmd = list(self.__reinstall_command)
|
||||
fullcmd.append(self.package_name)
|
||||
return subprocess.check_call(fullcmd)
|
||||
|
||||
def remove_pkg(self, package_name):
|
||||
fullcmd = self.__remove_command
|
||||
fullcmd.append(package_name)
|
||||
return subprocess.check_call(fullcmd)
|
||||
|
||||
def update(self):
|
||||
'''
|
||||
Update APT-RPM database.
|
||||
'''
|
||||
try:
|
||||
subprocess.check_call(['/usr/bin/apt-get', 'update'])
|
||||
except Exception as exc:
|
||||
logging.debug(exc)
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Package applier')
|
||||
parser.add_argument('sid', type = str, help = 'sid', nargs = '?', default = None)
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.sid:
|
||||
applier = Pkcon_applier(args.sid)
|
||||
else:
|
||||
applier = Pkcon_applier()
|
||||
applier.apply()
|
||||
|
@@ -60,6 +60,12 @@ ln -s %python3_sitelibdir/gpoa/gpupdate \
|
||||
ln -s %python3_sitelibdir/gpoa/gpupdate-setup \
|
||||
%buildroot%_sbindir/gpupdate-setup
|
||||
|
||||
mkdir -p \
|
||||
%buildroot%_prefix/libexec/%name
|
||||
|
||||
ln -s %python3_sitelibdir/gpoa/pkcon_runner \
|
||||
%buildroot%_prefix/libexec/%name/pkcon_runner
|
||||
|
||||
mkdir -p %buildroot%_datadir/%name
|
||||
mv %buildroot%python3_sitelibdir/gpoa/templates \
|
||||
%buildroot%_datadir/%name/
|
||||
@@ -102,9 +108,11 @@ fi
|
||||
%_sbindir/gpoa
|
||||
%_sbindir/gpupdate-setup
|
||||
%_bindir/gpupdate
|
||||
%_prefix/libexec/%name/pkcon_runner
|
||||
%attr(755,root,root) %python3_sitelibdir/gpoa/gpoa
|
||||
%attr(755,root,root) %python3_sitelibdir/gpoa/gpupdate
|
||||
%attr(755,root,root) %python3_sitelibdir/gpoa/gpupdate-setup
|
||||
%attr(755,root,root) %python3_sitelibdir/gpoa/pkcon_runner
|
||||
%python3_sitelibdir/gpoa
|
||||
%_datadir/%name
|
||||
%_unitdir/%name.service
|
||||
|
Reference in New Issue
Block a user