summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSteve 'Ashcrow' Milner <stevem@gnulinux.net>2008-02-23 21:50:48 -0500
committerSteve 'Ashcrow' Milner <stevem@gnulinux.net>2008-02-23 21:50:48 -0500
commit737d7ddb4f712a35b5d4cb754f57572980ce1721 (patch)
treec6fa5345dbacc2db0bdebc19cc1a1852d28fce64 /scripts
parent0b2e204bfef1bab070d4c124e5cf4d23f270f9b5 (diff)
downloadthird_party-func-737d7ddb4f712a35b5d4cb754f57572980ce1721.tar.gz
third_party-func-737d7ddb4f712a35b5d4cb754f57572980ce1721.tar.xz
third_party-func-737d7ddb4f712a35b5d4cb754f57572980ce1721.zip
checks for a valid email address and closer to normal __main__ coding.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/func-create-module50
1 files changed, 36 insertions, 14 deletions
diff --git a/scripts/func-create-module b/scripts/func-create-module
index f2885e8..0250006 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,38 @@ def populate_template(author_name, author_email, module_name, desc, methods):
author_email, module_name, desc, actual_methods[:-2])
+
+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:
+ author_email = raw_input("Email: ")
+ if re.match(regx, author_email) != None:
+ break
+ print "Please enter a valid email!"
+ return author_email
+
+
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 = []
+ 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 == '':
+ METHOD = raw_input("Method: ")
+ if METHOD == '':
break
- methods.append(method)
+ 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
+ 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