Remove dead code and use default value of argparse.

In the 'tool' method, the var 'apply_rule' was tested, and the
method returned if it was true. Then, it was tested again even
though it could only be 'false' (or not be None).
Also, an unused parameter of main() had been removed.

Closes-Bug #1650599
Change-Id: I4b265ef609d4a5fc8128f40359cf8d04ee8cbe28
Signed-off-by: Sami Makki <mail@samimakki.fr>
This commit is contained in:
Sami Makki 2016-12-16 17:04:55 +01:00
parent 6db6274f80
commit 98bc1354e2

View File

@ -56,14 +56,10 @@ def tool(policy_file, access_file, apply_rule, is_admin=False):
return
for key, rule in rules.items():
if ":" in key:
if apply_rule:
if (apply_rule == key):
_try_rule(key, rule, target, access_data, o)
else:
_try_rule(key, rule, target, access_data, o)
_try_rule(key, rule, target, access_data, o)
def main(argv=sys.argv[1:]):
def main():
parser = argparse.ArgumentParser(sys.argv[0])
parser.add_argument(
'--policy',
@ -85,16 +81,12 @@ def main(argv=sys.argv[1:]):
help='set is_admin=True on the credentials used for the evaluation')
args = parser.parse_args()
try:
apply_rule = args.rule
except Exception:
apply_rule = None
try:
is_admin = args.is_admin.lower() == "true"
except Exception:
is_admin = False
tool(args.policy, args.access, apply_rule, is_admin)
tool(args.policy, args.access, args.rule, is_admin)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
sys.exit(main())