From a018ecf031cd5a69bfde75817d90625d1d5b6d66 Mon Sep 17 00:00:00 2001 From: Peter Mosmans Date: Mon, 13 Jun 2016 22:32:44 +1000 Subject: [PATCH] Added option to prevent questions --- scripts/gitlab-to-pentext.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/gitlab-to-pentext.py b/scripts/gitlab-to-pentext.py index 5536f62..727ddad 100644 --- a/scripts/gitlab-to-pentext.py +++ b/scripts/gitlab-to-pentext.py @@ -115,8 +115,7 @@ def add_finding(issue, options): print_line('Finding {0} already exists (use --overwrite to overwrite)'. format(filename)) else: - print_line('Create file {0} ? [y/N]'.format(filename)) - if raw_input().lower() == 'y': + if options['y'] or ask_permission('Create file ' + filename): with open(filename, 'w') as xmlfile: xmlfile.write(finding_xml.emit_xml().encode('utf-8')) print_line('[+] Created {0}'.format(filename)) @@ -148,9 +147,18 @@ def add_non_finding(issue, options): print_line('Non-finding {0} already exists (use --overwrite to overwrite)'. format(filename)) else: - with open(filename, 'w') as xmlfile: - xmlfile.write(non_finding_xml.emit_xml().encode('utf-8')) - print_line('[+] Created {0}'.format(filename)) + if options['y'] or ask_permission('Create file ' + filename): + with open(filename, 'w') as xmlfile: + xmlfile.write(non_finding_xml.emit_xml().encode('utf-8')) + print_line('[+] Created {0}'.format(filename)) + + +def ask_permission(question): + """ + Ask question and return True if user answered with y. + """ + print_line('{0} ? [y/N]'.format(question)) + return raw_input().lower() == 'y' def list_projects(gitserver, options): @@ -188,6 +196,8 @@ the Free Software Foundation, either version 3 of the License, or help='list gitlab projects') parser.add_argument('-v', '--verbose', action='store_true', help='increase output verbosity') + parser.add_argument('-y', action='store_true', + help='assume yes on all questions, write findings') if len(sys.argv) == 1: parser.print_help() return vars(parser.parse_args())