| #!/usr/bin/python |
| # |
| |
| # Copyright (C) 2011 Google Inc. |
| # |
| # This program is free software; you can redistribute it and/or modify |
| # it under the terms of the GNU General Public License as published by |
| # the Free Software Foundation; either version 2 of the License, or |
| # (at your option) any later version. |
| # |
| # This program is distributed in the hope that it will be useful, but |
| # WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| # General Public License for more details. |
| # |
| # 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., 51 Franklin Street, Fifth Floor, Boston, MA |
| # 02110-1301, USA. |
| |
| |
| """Script to replace special directives in documentation. |
| |
| """ |
| |
| import re |
| import fileinput |
| |
| from ganeti import query |
| from ganeti.build import sphinx_ext |
| |
| |
| _DOC_RE = re.compile(r"^@(?P<class>[A-Z_]+)_(?P<kind>[A-Z]+)@$") |
| |
| _DOC_CLASSES_DATA = { |
| "CONSTANTS": (sphinx_ext.DOCUMENTED_CONSTANTS, sphinx_ext.BuildValuesDoc), |
| "QUERY_FIELDS": (query.ALL_FIELDS, sphinx_ext.BuildQueryFields), |
| } |
| |
| |
| def main(): |
| for line in fileinput.input(): |
| m = _DOC_RE.match(line) |
| if m: |
| fields_dict, builder = _DOC_CLASSES_DATA[m.group("class")] |
| fields = fields_dict[m.group("kind").lower()] |
| for i in builder(fields): |
| print i |
| else: |
| print line, |
| |
| |
| if __name__ == "__main__": |
| main() |