Statistics
| Branch: | Tag: | Revision:

root / autotools / docpp @ 387863a5

History | View | Annotate | Download (1.4 kB)

1 95eb4188 Michael Hanselmann
#!/usr/bin/python
2 95eb4188 Michael Hanselmann
#
3 95eb4188 Michael Hanselmann
4 95eb4188 Michael Hanselmann
# Copyright (C) 2011 Google Inc.
5 95eb4188 Michael Hanselmann
#
6 95eb4188 Michael Hanselmann
# This program is free software; you can redistribute it and/or modify
7 95eb4188 Michael Hanselmann
# it under the terms of the GNU General Public License as published by
8 95eb4188 Michael Hanselmann
# the Free Software Foundation; either version 2 of the License, or
9 95eb4188 Michael Hanselmann
# (at your option) any later version.
10 95eb4188 Michael Hanselmann
#
11 95eb4188 Michael Hanselmann
# This program is distributed in the hope that it will be useful, but
12 95eb4188 Michael Hanselmann
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 95eb4188 Michael Hanselmann
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 95eb4188 Michael Hanselmann
# General Public License for more details.
15 95eb4188 Michael Hanselmann
#
16 95eb4188 Michael Hanselmann
# You should have received a copy of the GNU General Public License
17 95eb4188 Michael Hanselmann
# along with this program; if not, write to the Free Software
18 95eb4188 Michael Hanselmann
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 95eb4188 Michael Hanselmann
# 02110-1301, USA.
20 95eb4188 Michael Hanselmann
21 95eb4188 Michael Hanselmann
22 95eb4188 Michael Hanselmann
"""Script to replace special directives in documentation.
23 95eb4188 Michael Hanselmann
24 95eb4188 Michael Hanselmann
"""
25 95eb4188 Michael Hanselmann
26 95eb4188 Michael Hanselmann
import re
27 95eb4188 Michael Hanselmann
import fileinput
28 95eb4188 Michael Hanselmann
29 95eb4188 Michael Hanselmann
from ganeti import query
30 95eb4188 Michael Hanselmann
from ganeti.build import sphinx_ext
31 95eb4188 Michael Hanselmann
32 95eb4188 Michael Hanselmann
33 12637df5 Andrea Spadaccini
_DOC_RE = re.compile(r"^@(?P<class>[A-Z_]+)_(?P<kind>[A-Z]+)@$")
34 12637df5 Andrea Spadaccini
35 12637df5 Andrea Spadaccini
_DOC_CLASSES_DATA = {
36 3ac3f5e4 Andrea Spadaccini
  "CONSTANTS": (sphinx_ext.DOCUMENTED_CONSTANTS, sphinx_ext.BuildValuesDoc),
37 12637df5 Andrea Spadaccini
  "QUERY_FIELDS": (query.ALL_FIELDS, sphinx_ext.BuildQueryFields),
38 12637df5 Andrea Spadaccini
  }
39 95eb4188 Michael Hanselmann
40 95eb4188 Michael Hanselmann
41 95eb4188 Michael Hanselmann
def main():
42 95eb4188 Michael Hanselmann
  for line in fileinput.input():
43 12637df5 Andrea Spadaccini
    m = _DOC_RE.match(line)
44 95eb4188 Michael Hanselmann
    if m:
45 12637df5 Andrea Spadaccini
      fields_dict, builder = _DOC_CLASSES_DATA[m.group("class")]
46 12637df5 Andrea Spadaccini
      fields = fields_dict[m.group("kind").lower()]
47 12637df5 Andrea Spadaccini
      for i in builder(fields):
48 95eb4188 Michael Hanselmann
        print i
49 95eb4188 Michael Hanselmann
    else:
50 95eb4188 Michael Hanselmann
      print line,
51 95eb4188 Michael Hanselmann
52 95eb4188 Michael Hanselmann
53 95eb4188 Michael Hanselmann
if __name__ == "__main__":
54 95eb4188 Michael Hanselmann
  main()