summaryrefslogtreecommitdiffstats
path: root/scripts/func-create-module
blob: cf05449739e32ad905eff3badbbbc38c63d60cff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# Steve 'Ashcrow' Milner <smilner@redhat.com>
# John Eckersberg <jeckersb@redhat.com>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# 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.

TEMPLATE = """\
import func_module

class %s(func_module.FuncModule):

    # Update these if need be.
    version = "0.0.1"
    api_version = "0.0.1"
    description = "%s"

%s
"""

METHOD_TEMPLATE = '''\
    def %s(self):
        """
        TODO: Document me ...
        """
        pass

'''


def populate_template(module_name, desc, methods):
    """
    Makes the method strings and populates the template.
    """
    actual_methods = ""
    for method in methods:
        actual_methods += METHOD_TEMPLATE % method
    return TEMPLATE % (module_name, desc, actual_methods[:-2])


if __name__ == '__main__':
    module_name = raw_input("Name: ").capitalize()
    desc = raw_input("Description: ")
    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(module_name, desc, methods))
    file_obj.close()
    print "Your module is ready to be hacked on. Wrote out to %s." % file_name