policycoreutils: semanage: use define/raise instead of lots of conditionals

Right now the validation code has lots of conditionals which check if we
are trying to add and delete or add and modify or something like that.
Instead make a single function which just sets if this operation is
trying to do an action and if it gets called twice will realize this is
invalid and will raise and exception.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
Eric Paris 2011-07-18 12:12:34 -04:00
parent 123559545f
commit 0c4d0788ab

View File

@ -40,6 +40,13 @@ except IOError:
if __name__ == '__main__':
action = False
def set_action(option):
global action
if action:
raise ValueError(_("%s bad option") % option)
action = True
def usage(message = ""):
text = _("""
semanage [ -S store ] -i [ input_file | - ]
@ -169,6 +176,8 @@ Object-specific Options (see above):
return ret
def process_args(argv):
global action
action = False
serange = ""
port = ""
proto = ""
@ -229,17 +238,14 @@ Object-specific Options (see above):
for o,a in gopts:
if o == "-a" or o == "--add":
if modify or delete:
raise ValueError(_("%s bad option") % o)
set_action(o)
add = True
if o == "-d" or o == "--delete":
if modify or add:
raise ValueError(_("%s bad option") % o)
set_action(o)
delete = True
if o == "-D" or o == "--deleteall":
if modify:
raise ValueError(_("%s bad option") % o)
set_action(o)
deleteall = True
if o == "-f" or o == "--ftype":
ftype=a
@ -257,8 +263,7 @@ Object-specific Options (see above):
locallist = True
if o == "-m"or o == "--modify":
if delete or add:
raise ValueError(_("%s bad option") % o)
set_action(o)
modify = True
if o == "-S" or o == '--store':