diff options
-rwxr-xr-x | scripts/func-create-module | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/scripts/func-create-module b/scripts/func-create-module index 0250006..4786cb0 100755 --- a/scripts/func-create-module +++ b/scripts/func-create-module @@ -73,29 +73,43 @@ def get_email(): regx = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$" while True: - author_email = raw_input("Email: ") + author_email = get_input("Email") if re.match(regx, author_email) != None: break print "Please enter a valid email!" return author_email +def get_input(prompt): + """ + Get input and make sure input is given. + """ + result = raw_input("%s: " % prompt) + if not result: + print "Please input the requested information." + return get_input(prompt) + return result + + if __name__ == '__main__': - MODULE_NAME = raw_input("Module Name: ").capitalize() - DESC = raw_input("Description: ") - AUTHOR_NAME = raw_input("Author: ") - AUTHOR_EMAIL = get_email() - METHODS = [] - print "\nLeave blank to finish." - while True: - METHOD = raw_input("Method: ") - if METHOD == '': - break - METHODS.append(METHOD) - # Write it out to a file - FILE_NAME = "%s.py" % MODULE_NAME.lower() - FILE_OBJ = open(FILE_NAME, "w") - FILE_OBJ.write(populate_template(AUTHOR_NAME, AUTHOR_EMAIL, - MODULE_NAME, DESC, METHODS)) - FILE_OBJ.close() - print "Your module is ready to be hacked on. Wrote out to %s." % FILE_NAME + try: + MODULE_NAME = get_input("Module Name").capitalize() + DESC = get_input("Description") + AUTHOR_NAME = get_input("Author") + AUTHOR_EMAIL = get_email() + METHODS = [] + print "\nLeave blank to finish." + while True: + METHOD = raw_input("Method: ") + if METHOD == '': + break + METHODS.append(METHOD) + # Write it out to a file + FILE_NAME = "%s.py" % MODULE_NAME.lower() + FILE_OBJ = open(FILE_NAME, "w") + FILE_OBJ.write(populate_template(AUTHOR_NAME, AUTHOR_EMAIL, + MODULE_NAME, DESC, METHODS)) + FILE_OBJ.close() + print "Your module is ready to be hacked on. Wrote out to %s." % FILE_NAME + except KeyboardInterrupt, ex: + print "\nExiting ..." |