3 # ###################################################
4 # Copyright (C) 2008 The OpenAnno Team
6 # This file is part of OpenAnno.
8 # OpenAnno is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 # ###################################################
25 is_function
= re
.compile('^(\\s*)def\\s+([^\\s(]+)\\s*[(](.*)[)]\\s*:\\s*$')
26 is_decorator
= re
.compile('^(\\s*)@\\s*(.+)\\s*$')
27 func_param
= re
.compile('\\s*(?:,\\s*)?([^,=\\s]+)(?:\\s*=\\s*([^\\s,]+))?')
28 is_empty
= re
.compile('^(\\s*)(?:#.*)?$')
31 for filename
in files
:
32 print 'Adding documentation stubs to:', filename
33 file = open(filename
, 'r+')
37 if is_function
.match(line
) is not None:
38 funk_reg
= is_function
.match(line
)
39 elif funk_reg
is not None and line
.strip().startswith('"""'):
40 newfile
.append(funk_reg
.group())
43 elif funk_reg
is not None:
44 params
= func_param
.findall(funk_reg
.group(3))
45 indent
= funk_reg
.group(1)*2 if funk_reg
.group(2) != '__init__' else funk_reg
.group(1)
46 docstub
= [(indent
+ '"""\n')]
48 if i
[0] != 'self' and i
[0] != 'cls':
49 docstub
.append(("%s@param %s:\n" % (indent
, i
[0])))
50 docstub
.append((indent
+ '"""\n'))
51 if funk_reg
.group(2) == '__init__':
52 newfile
.extend(docstub
)
53 newfile
.append(funk_reg
.group())
55 newfile
.append(funk_reg
.group())
56 newfile
.extend(docstub
)
62 file.writelines(newfile
)