mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 14:25:52 +00:00
aa.py / ask_the_question() - simplify duplicate option prevention
add a add_to_options() helper function to aa.py which - adds newpath to options if it's not already there - returns the updated options and the index of newpath This removes duplicated code for CMD_GLOB and CMD_GLOBEXT in ask_the_question() It also adds duplicate prevention to CMD_NEW. Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
This commit is contained in:
@@ -1921,30 +1921,19 @@ def ask_the_questions():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
user_globs.append(ans)
|
user_globs.append(ans)
|
||||||
options.append(ans)
|
options, default_option = add_to_options(options, ans)
|
||||||
default_option = len(options)
|
|
||||||
|
|
||||||
elif ans == 'CMD_GLOB':
|
elif ans == 'CMD_GLOB':
|
||||||
newpath = options[selected].strip()
|
newpath = options[selected].strip()
|
||||||
if not re_match_include(newpath):
|
if not re_match_include(newpath):
|
||||||
newpath = glob_path(newpath)
|
newpath = glob_path(newpath)
|
||||||
|
options, default_option = add_to_options(options, newpath)
|
||||||
if newpath not in options:
|
|
||||||
options.append(newpath)
|
|
||||||
default_option = len(options)
|
|
||||||
else:
|
|
||||||
default_option = options.index(newpath) + 1
|
|
||||||
|
|
||||||
elif ans == 'CMD_GLOBEXT':
|
elif ans == 'CMD_GLOBEXT':
|
||||||
newpath = options[selected].strip()
|
newpath = options[selected].strip()
|
||||||
if not re_match_include(newpath):
|
if not re_match_include(newpath):
|
||||||
newpath = glob_path_withext(newpath)
|
newpath = glob_path_withext(newpath)
|
||||||
|
options, default_option = add_to_options(options, newpath)
|
||||||
if newpath not in options:
|
|
||||||
options.append(newpath)
|
|
||||||
default_option = len(options)
|
|
||||||
else:
|
|
||||||
default_option = options.index(newpath) + 1
|
|
||||||
|
|
||||||
elif re.search('\d', ans):
|
elif re.search('\d', ans):
|
||||||
default_option = ans
|
default_option = ans
|
||||||
@@ -2039,6 +2028,13 @@ def ask_the_questions():
|
|||||||
else:
|
else:
|
||||||
done = False
|
done = False
|
||||||
|
|
||||||
|
def add_to_options(options, newpath):
|
||||||
|
if newpath not in options:
|
||||||
|
options.append(newpath)
|
||||||
|
|
||||||
|
default_option = options.index(newpath) + 1
|
||||||
|
return (options, default_option)
|
||||||
|
|
||||||
def glob_path(newpath):
|
def glob_path(newpath):
|
||||||
"""Glob the given file path"""
|
"""Glob the given file path"""
|
||||||
if newpath[-1] == '/':
|
if newpath[-1] == '/':
|
||||||
|
Reference in New Issue
Block a user