/[escript]/trunk/pyvisi/admin/skel.py
ViewVC logotype

Contents of /trunk/pyvisi/admin/skel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 337 - (show annotations)
Mon Dec 12 01:57:07 2005 UTC (14 years, 5 months ago) by cochrane
File MIME type: text/x-python
File size: 5112 byte(s)
Initial merge of pyvisi into esys repository.
1 #!/usr/bin/env python
2 # Copyright (C) 2004-2005 Paul Cochrane
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 # $Id: skel.py,v 1.3 2005/02/08 05:54:17 paultcochrane Exp $
19
20 import string,sys
21
22 if (len(sys.argv) != 2):
23 print "Usage: python skel.py <className>"
24 sys.exit(1)
25
26 # this is the filename (minus the .py) and the name of the class
27 classname = sys.argv[1]
28
29 # the copyright string to put at the top of the file
30 copyrightStr = """# Copyright (C) 2004-2005 Paul Cochrane
31 #
32 # This program is free software; you can redistribute it and/or
33 # modify it under the terms of the GNU General Public License
34 # as published by the Free Software Foundation; either version 2
35 # of the License, or (at your option) any later version.
36 #
37 # This program is distributed in the hope that it will be useful,
38 # but WITHOUT ANY WARRANTY; without even the implied warranty of
39 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 # GNU General Public License for more details.
41 #
42 # You should have received a copy of the GNU General Public License
43 # along with this program; if not, write to the Free Software
44 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
45
46 # $
47 """ % classname
48 # this is here to get around cvs keyword expansion issues
49 copyrightStr += "Id"
50 copyrightStr += "$"
51
52 # doxygen documentation strings for info about the file itself
53 fileDoxStr = "## @file %s.py\n" % classname
54 fileDoxStr += """
55 \"\"\"
56 Brief introduction to what the file contains/does
57 \"\"\"
58
59 from pyvisi.common import debugMsg, overrideWarning
60
61 """
62
63 # the class body skeleton, with doxygen strings added, and a dummy function
64 classStr = "class %s():" % classname.capitalize()
65 classStr += """
66 \"\"\"
67 Brief introduction to what the class does
68 \"\"\"
69
70 def __init__(self, arg):
71 \"\"\"
72 Brief description of the init function
73
74 @param arg: a description of the argument
75 @type arg: the type of the argument
76 \"\"\"
77 BaseClass.__init__(self)
78 debugMsg(\"Called %s.__init__()\")
79
80 def myfunc(myarg):
81 \"\"\"
82 Brief description of what the function does
83
84 Replace the text given here with an actual description of what
85 the function does. Also change the name of the function and
86 the name of the argument.
87
88 @param myarg: Description of what the parameter means/does
89 @type myarg: the type of the argument
90 \"\"\"
91 return
92 """ % classname.capitalize()
93
94 # this gets vim to "do the right thing" wrt spaces and tabs etc
95 vimStr = "# vim: expandtab shiftwidth=4:"
96
97 fname = classname + '.py'
98 f = open(fname, 'w')
99 f.write(copyrightStr + "\n")
100 f.write(fileDoxStr + "\n")
101 f.write(classStr + "\n")
102 f.write(vimStr + "\n")
103 f.close()
104
105 # now biff out the stuff for the test file
106
107 copyrightStr = """# Copyright (C) 2004-2005 Paul Cochrane
108 #
109 # This program is free software; you can redistribute it and/or
110 # modify it under the terms of the GNU General Public License
111 # as published by the Free Software Foundation; either version 2
112 # of the License, or (at your option) any later version.
113 #
114 # This program is distributed in the hope that it will be useful,
115 # but WITHOUT ANY WARRANTY; without even the implied warranty of
116 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
117 # GNU General Public License for more details.
118 #
119 # You should have received a copy of the GNU General Public License
120 # along with this program; if not, write to the Free Software
121 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
122
123 # \$Id\$
124
125 """ % classname
126
127 fileDoxStr = '## @file test_' + classname + '.py'
128
129 bodyTextStr = """import unittest
130 import sys,os,string
131 here = os.getcwd() + '/../../'
132 sys.path.append(here)
133 from pyvisi import * # this should import all of the pyvisi stuff needed
134
135 \"\"\"
136 Class and functions for testing the %s class
137 \"\"\"
138
139 class Test%s(unittest.TestCase):
140 \"\"\"
141 The main test class
142 \"\"\"
143
144 def testFunction(self):
145 \"\"\"
146 A test function
147 \"\"\"
148 self.assertEqual()
149 self.assertRaises()
150 self.assert_()
151
152 if __name__ == '__main__':
153 unittest.main()
154
155 """ % (classname.capitalize(), classname.capitalize())
156
157 fname = 'test_' + classname + '.py'
158 f = open(fname, 'w')
159 f.write(copyrightStr + "\n")
160 f.write(fileDoxStr + "\n")
161 f.write(bodyTextStr + "\n")
162 f.write(vimStr + "\n")
163 f.close()
164
165 # vim: expandtab shiftwidth=4:
166

  ViewVC Help
Powered by ViewVC 1.1.26