Passed
Pull Request — master (#21)
by
unknown
01:11
created

conf   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 228
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 67
dl 0
loc 228
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B make_rst_table_with_header() 0 42 7
1
# -*- coding: utf-8 -*-
2
#
3
# Configuration file for the Sphinx documentation builder.
4
#
5
# This file does only contain a selection of the most common options. For a
6
# full list see the documentation:
7
# http://www.sphinx-doc.org/en/master/config
8
9
# -- Path setup --------------------------------------------------------------
10
11
# If extensions (or modules to document with autodoc) are in another directory,
12
# add these directories to sys.path here. If the directory is relative to the
13
# documentation root, use os.path.abspath to make it absolute, like shown here.
14
#
15
import json
16
import os
17
import sys
18
sys.path.insert(0, os.path.abspath('../../'))
19
20
21
# -- API implementation statuses -----------------------------------------------------
22
23
def make_rst_table_with_header(table_data):
24
    rst_table = ""
25
26
    page_title = table_data['title']
27
    headers = table_data['headers']
28
    headers_attributes = table_data['headers attributes']
29
    data = table_data['data']
30
31
    # write page title
32
    rst_table += "{}\n{}\n".format(page_title, "-" * len(page_title))
33
34
    # calculate each column max length
35
    column_lengths = []
36
    for i in range(len(headers)):
37
        column_members = [headers[i]]
38
        column_members += [each[headers_attributes[i]] for each in data]
39
        column_length = max([len(each) for each in column_members])
40
41
        column_lengths.append(column_length)
42
43
    rst_table += " ".join(["=" * each for each in column_lengths]) + "\n"
44
    # write table headers
45
    for i in range(len(headers)):
46
        rst_table += headers[i]
47
        if i != len(headers) - 1:
48
            rst_table += " " * (column_lengths[i] - len(headers[i]) + 1)
49
        else:
50
            rst_table += "\n"
51
52
    rst_table += " ".join(["=" * each for each in column_lengths]) + "\n"
53
    # write table content
54
    for each in data:
55
        for i in range(len(headers_attributes)):
56
            rst_table += each[headers_attributes[i]]
57
            if i != len(headers) - 1:
58
                rst_table += " " * (column_lengths[i] - len(each[headers_attributes[i]]) + 1)
59
            else:
60
                rst_table += "\n"
61
62
    rst_table += " ".join(["=" * each for each in column_lengths]) + "\n"
63
64
    return rst_table
65
66
67
with open("../../api_implementation.json", "r") as json_data, \
68
        open('api_implementation.rst', 'w') as api_implementation:
69
    table_data = json.load(json_data)
70
    content = make_rst_table_with_header(table_data)
71
    api_implementation.write(content)
72
73
# -- Project information -----------------------------------------------------
74
75
project = 'nextcloud-API'
76
copyright = '2018, EnterpriseyIntranet'
77
author = 'EnterpriseyIntranet'
78
79
# The short X.Y version
80
version = ''
81
# The full version, including alpha/beta/rc tags
82
release = '0.0.1'
83
84
85
# -- General configuration ---------------------------------------------------
86
87
# If your documentation needs a minimal Sphinx version, state it here.
88
#
89
# needs_sphinx = '1.0'
90
91
# Add any Sphinx extension module names here, as strings. They can be
92
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
93
# ones.
94
extensions = [
95
    'sphinx.ext.doctest', 'sphinx.ext.autodoc', 'sphinx.ext.napoleon',
96
]
97
98
# Add any paths that contain templates here, relative to this directory.
99
templates_path = ['ntemplates']
100
101
# The suffix(es) of source filenames.
102
# You can specify multiple suffix as a list of string:
103
#
104
# source_suffix = ['.rst', '.md']
105
source_suffix = '.rst'
106
107
# The master toctree document.
108
master_doc = 'index'
109
110
# The language for content autogenerated by Sphinx. Refer to documentation
111
# for a list of supported languages.
112
#
113
# This is also used if you do content translation via gettext catalogs.
114
# Usually you set "language" from the command line for these cases.
115
language = None
116
117
# List of patterns, relative to source directory, that match files and
118
# directories to ignore when looking for source files.
119
# This pattern also affects html_static_path and html_extra_path.
120
exclude_patterns = []
121
122
# The name of the Pygments (syntax highlighting) style to use.
123
pygments_style = None
124
125
126
# -- Options for HTML output -------------------------------------------------
127
128
# The theme to use for HTML and HTML Help pages.  See the documentation for
129
# a list of builtin themes.
130
#
131
html_theme = 'default'
132
133
# Theme options are theme-specific and customize the look and feel of a theme
134
# further.  For a list of options available for each theme, see the
135
# documentation.
136
#
137
# html_theme_options = {}
138
139
# Add any paths that contain custom static files (such as style sheets) here,
140
# relative to this directory. They are copied after the builtin static files,
141
# so a file named "default.css" will overwrite the builtin "default.css".
142
html_static_path = ['nstatic']
143
144
# Custom sidebar templates, must be a dictionary that maps document names
145
# to template names.
146
#
147
# The default sidebars (for documents that don't match any pattern) are
148
# defined by theme itself.  Builtin themes are using these templates by
149
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
150
# 'searchbox.html']``.
151
#
152
# html_sidebars = {}
153
154
155
# -- Options for HTMLHelp output ---------------------------------------------
156
157
# Output file base name for HTML help builder.
158
htmlhelp_basename = 'nextcloud-APIdoc'
159
160
161
# -- Options for LaTeX output ------------------------------------------------
162
163
latex_elements = {
164
    # The paper size ('letterpaper' or 'a4paper').
165
    #
166
    # 'papersize': 'letterpaper',
167
168
    # The font size ('10pt', '11pt' or '12pt').
169
    #
170
    # 'pointsize': '10pt',
171
172
    # Additional stuff for the LaTeX preamble.
173
    #
174
    # 'preamble': '',
175
176
    # Latex figure (float) alignment
177
    #
178
    # 'figure_align': 'htbp',
179
}
180
181
# Grouping the document tree into LaTeX files. List of tuples
182
# (source start file, target name, title,
183
#  author, documentclass [howto, manual, or own class]).
184
latex_documents = [
185
    (master_doc, 'nextcloud-API.tex', 'nextcloud-API Documentation',
186
     'EnterpriseyIntranet', 'manual'),
187
]
188
189
190
# -- Options for manual page output ------------------------------------------
191
192
# One entry per manual page. List of tuples
193
# (source start file, name, description, authors, manual section).
194
man_pages = [
195
    (master_doc, 'nextcloud-api', 'nextcloud-API Documentation',
196
     [author], 1)
197
]
198
199
200
# -- Options for Texinfo output ----------------------------------------------
201
202
# Grouping the document tree into Texinfo files. List of tuples
203
# (source start file, target name, title, author,
204
#  dir menu entry, description, category)
205
texinfo_documents = [
206
    (master_doc, 'nextcloud-API', 'nextcloud-API Documentation',
207
     author, 'nextcloud-API', 'One line description of project.',
208
     'Miscellaneous'),
209
]
210
211
212
# -- Options for Epub output -------------------------------------------------
213
214
# Bibliographic Dublin Core info.
215
epub_title = project
216
217
# The unique identifier of the text. This can be a ISBN number
218
# or the project homepage.
219
#
220
# epub_identifier = ''
221
222
# A unique identification for the text.
223
#
224
# epub_uid = ''
225
226
# A list of files that should not be packed into the epub file.
227
epub_exclude_files = ['search.html']
228
229
230
# -- Extension configuration -------------------------------------------------