1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-03-21 18:50:38 +03:00

Added comments and moved part of the code in class methods

This commit is contained in:
Valery Sinelnikov 2022-04-26 12:11:08 +04:00 committed by Evgeny Sinelnikov
parent 31ba4ad214
commit 43161e61bc
2 changed files with 38 additions and 11 deletions

View File

@ -46,7 +46,15 @@ class scripts_applier(applier_frontend):
, self.__module_name
, self.__module_experimental
)
if sid in check_sid[machine_name]['sid']:
self.filling_cache()
def filling_cache(self):
'''
Creating and updating folder directories for scripts and copying them
'''
machine_name = os.uname()[1] + '$'
check_sid = pysss_nss_idmap.getsidbyname(machine_name)
if self.sid in check_sid[machine_name]['sid']:
try:
remove_dir_tree(self.folder_path, True, True, True,)
except FileNotFoundError as exc:
@ -56,6 +64,7 @@ class scripts_applier(applier_frontend):
logdata['exc'] = exc
log('E64', logdata)
self.folder_path.mkdir(parents=True, exist_ok=True)
print(self.__module_enabled)
if self.__module_enabled:
for ts in self.scripts:
if ts.path.split('/')[-4] == 'MACHINE':
@ -64,6 +73,8 @@ class scripts_applier(applier_frontend):
'/'.join(ts.path.split('/')[ts.path.split('/').index('POLICIES')+4:-1]))
install_script(ts, script_path, '700')
def run(self):
pass
def apply(self):
@ -85,6 +96,12 @@ class scripts_applier_user(applier_frontend):
, self.__module_name
, self.__module_experimental
)
self.filling_cache()
def filling_cache(self):
'''
Creating and updating folder directories for scripts and copying them
'''
if self.username[:-1] != os.uname()[1].upper():
try:
remove_dir_tree(self.folder_path, True, True, True,)
@ -99,9 +116,9 @@ class scripts_applier_user(applier_frontend):
for ts in self.scripts:
if ts.path.split('/')[-4] == 'USER':
script_path = (self.__cache_scripts +
self.username + '/' +
ts.policy_num + '/' +
'/'.join(ts.path.split('/')[ts.path.split('/').index('POLICIES')+4:-1]))
self.username + '/' +
ts.policy_num + '/' +
'/'.join(ts.path.split('/')[ts.path.split('/').index('POLICIES')+4:-1]))
install_script(ts, script_path, '755')
@ -118,6 +135,11 @@ class scripts_applier_user(applier_frontend):
pass
def install_script(storage_script_entry, script_path, access_permissions):
'''
Copy scripts to specific directories and
if given arguments
create directories for them and copy them there
'''
dir_cr = Path(script_path)
dir_cr.mkdir(parents=True, exist_ok=True)
script_file = (script_path + '/' +

19
gpoa/scripts_runner Normal file → Executable file
View File

@ -22,25 +22,30 @@ import argparse
from pathlib import Path
class Scripts_runner:
'''
A class for an object that iterates over directories with scripts
in the desired sequence and launches them
'''
def __init__(self, work_mode = None, user_name = None, action = None):
self.dir_scripts_machine = '/var/cache/gpupdate_scripts_cache/machine/'
self.dir_scripts_users = '/var/cache/gpupdate_scripts_cache/users/'
self.user_name = user_name
self.sort_path_scripts = dict()
self.list_with_all_commands = list()
if action:
self.action = action.upper()
else:
print('Action needed')
return
self.stack_dir = list()
if work_mode and work_mode.upper() == 'MACHINE':
self.machine_runner_fill()
elif work_mode and work_mode.upper() == 'USER':
self.user_runner_fill()
else:
print('Invalid arguments entered')
return
if action:
self.action = action.upper()
else:
print('Action needed')
return
self.find_action()
self.sort_path_scripts = sorted(self.sort_path_scripts.items(), reverse = True)