Changing func to certmaster in top level directories, also covered
[certmaster.git] / scripts / func-create-module
1 #!/usr/bin/env python
2 #
3 # Copyright 2008, Red Hat, Inc
4 # Steve 'Ashcrow' Milner <smilner@redhat.com>
5 # John Eckersberg <jeckersb@redhat.com>
6 #
7 # This software may be freely redistributed under the terms of the GNU
8 # general public license.
9 #
10 # You should have received a copy of the GNU General Public License
11 # along with this program; if not, write to the Free Software
12 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13
14 TEMPLATE = """\
15 #
16 # Copyright %s
17 # %s <%s>
18 #
19 # This software may be freely redistributed under the terms of the GNU
20 # general public license.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26 import func_module
27
28 class %s(func_module.FuncModule):
29
30 # Update these if need be.
31 version = "0.0.1"
32 api_version = "0.0.1"
33 description = "%s"
34
35 %s
36 """
37
38 METHOD_TEMPLATE = '''\
39 def %s(self):
40 """
41 TODO: Document me ...
42 """
43 pass
44
45 '''
46
47
48 def populate_template(author_name, author_email, module_name, desc, methods):
49 """
50 Makes the method strings and populates the template.
51 """
52 from datetime import datetime
53
54 actual_methods = ""
55 for method in methods:
56 actual_methods += METHOD_TEMPLATE % method
57 return TEMPLATE % (datetime.now().strftime("%Y"), author_name,
58 author_email, module_name, desc, actual_methods[:-2])
59
60
61 if __name__ == '__main__':
62 module_name = raw_input("Module Name: ").capitalize()
63 desc = raw_input("Description: ")
64 author_name = raw_input("Author: ")
65 author_email = raw_input("Email: ")
66 methods = []
67 print "\nLeave blank to finish."
68 while True:
69 method = raw_input("Method: ")
70 if method == '':
71 break
72 methods.append(method)
73 # Write it out to a file
74 file_name = "%s.py" % module_name.lower()
75 file_obj = open(file_name, "w")
76 file_obj.write(populate_template(author_name, author_email,
77 module_name, desc, methods))
78 file_obj.close()
79 print "Your module is ready to be hacked on. Wrote out to %s." % file_name