diff options
| author | Adrian Likins <alikins@grimlock.devel.redhat.com> | 2008-02-25 13:28:32 -0500 |
|---|---|---|
| committer | Adrian Likins <alikins@grimlock.devel.redhat.com> | 2008-02-25 13:28:32 -0500 |
| commit | 71ca4184404df52dabfea318e3e0a1ca8c1b4c61 (patch) | |
| tree | 5a4b69c9b9e38057256624f1c173f59d928487e5 /scripts | |
| parent | e648895b13205a4669ba9d3ea8756209b6a6d9eb (diff) | |
| parent | e27f9d8383848d523d301706046c54e99b5f9676 (diff) | |
| download | third_party-func-71ca4184404df52dabfea318e3e0a1ca8c1b4c61.tar.gz third_party-func-71ca4184404df52dabfea318e3e0a1ca8c1b4c61.tar.xz third_party-func-71ca4184404df52dabfea318e3e0a1ca8c1b4c61.zip | |
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/func-create-module | 70 |
1 files changed, 53 insertions, 17 deletions
diff --git a/scripts/func-create-module b/scripts/func-create-module index f2885e8..4786cb0 100755 --- a/scripts/func-create-module +++ b/scripts/func-create-module @@ -10,6 +10,10 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +""" +Creates a boilerplate minion module. +""" + TEMPLATE = """\ # @@ -25,6 +29,7 @@ TEMPLATE = """\ import func_module + class %s(func_module.FuncModule): # Update these if need be. @@ -35,6 +40,7 @@ class %s(func_module.FuncModule): %s """ + METHOD_TEMPLATE = '''\ def %s(self): """ @@ -58,22 +64,52 @@ def populate_template(author_name, author_email, module_name, desc, methods): author_email, module_name, desc, actual_methods[:-2]) -if __name__ == '__main__': - module_name = raw_input("Module Name: ").capitalize() - desc = raw_input("Description: ") - author_name = raw_input("Author: ") - author_email = raw_input("Email: ") - methods = [] - print "\nLeave blank to finish." + +def get_email(): + """ + Get and return a valid email address. + """ + import re + + regx = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$" while True: - method = raw_input("Method: ") - if method == '': + author_email = get_input("Email") + if re.match(regx, author_email) != None: 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 + 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__': + 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 ..." |
