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

gpupdate: Add choices for target argument and short argument names for others

This commit is contained in:
Evgeny Sinelnikov 2022-05-28 05:12:54 +04:00
parent bced76ac4d
commit 66ebe87592
2 changed files with 16 additions and 15 deletions

View File

@ -72,11 +72,14 @@ def parse_cli_arguments():
'--user',
default=None,
help='Name of the user for GPO update')
argparser.add_argument('--target',
argparser.add_argument('-t',
'--target',
default=None,
type=str,
type=str.upper,
choices=["ALL", "USER", "COMPUTER"],
help='Specify if it is needed to update user\'s or computer\'s policies')
argparser.add_argument('--loglevel',
argparser.add_argument('-l',
'--loglevel',
type=int,
default=5,
help='Set logging verbosity level')
@ -94,13 +97,14 @@ def runner_factory(args, target):
factors taken into account.
'''
username = None
target = target.upper()
if is_root():
# Only root may specify any username to update.
try:
if args.user:
username = pwd.getpwnam(args.user).pw_name
else:
target = 'Computer'
target = 'COMPUTER'
except:
username = None
logdata = dict({'username': args.user})
@ -126,10 +130,10 @@ def try_by_oddjob(username, target):
log('D13')
computer_runner = None
user_runner = None
if target == 'All' or target == 'Computer':
if target == 'ALL' or target == 'COMPUTER':
computer_runner = dbus_runner()
if username:
if target == 'All' or target == 'User':
if target == 'ALL' or target == 'USER':
user_runner = dbus_runner(username)
return (computer_runner, user_runner)
else:
@ -145,9 +149,9 @@ def try_directly(username, target, loglevel):
log('D14')
computer_runner = None
user_runner = None
if target == 'All' or target == 'Computer':
if target == 'ALL' or target == 'COMPUTER':
computer_runner = file_runner(loglevel)
if target == 'All' or target == 'User':
if target == 'ALL' or target == 'USER':
user_runner = file_runner(loglevel, username)
return (computer_runner, user_runner)
else:

View File

@ -64,18 +64,15 @@ def process_target(target_name=None):
The target may be 'All', 'Computer' or 'User'. This function
determines which one was specified.
'''
target = 'All'
if target_name == 'Computer':
target = 'Computer'
if target_name == 'User':
target = 'User'
target = "All"
if target_name:
target = target_name
logdata = dict({'target': target})
logging.debug(slogm(message_with_code('D10'), logdata))
return target
return target.upper()
class ExitCodeUpdater(IntEnum):
'''