conf   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 238
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 72
dl 0
loc 238
rs 10
c 0
b 0
f 0
wmc 9

1 Function

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