|
1
|
|
|
# Copyright 2014 Diamond Light Source Ltd. |
|
2
|
|
|
# |
|
3
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
4
|
|
|
# you may not use this file except in compliance with the License. |
|
5
|
|
|
# You may obtain a copy of the License at |
|
6
|
|
|
# |
|
7
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
8
|
|
|
# |
|
9
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
10
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
11
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12
|
|
|
# See the License for the specific language governing permissions and |
|
13
|
|
|
# limitations under the License. |
|
14
|
|
|
|
|
15
|
|
|
""" |
|
16
|
|
|
.. module:: create_arg_parser_doc |
|
17
|
|
|
:platform: Unix |
|
18
|
|
|
:synopsis: A module to create savu arg parser documentation |
|
19
|
|
|
|
|
20
|
|
|
.. moduleauthor:: Jessica Verschoyle <[email protected]> |
|
21
|
|
|
|
|
22
|
|
|
""" |
|
23
|
|
|
|
|
24
|
|
|
import os |
|
25
|
|
|
|
|
26
|
|
|
import doc.create_plugin_doc as pdoc |
|
27
|
|
|
import scripts.config_generator.savu_config as sc |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
def create_savu_config_documentation(savu_base_path): |
|
31
|
|
|
"""Look at the available commands inside savu_config |
|
32
|
|
|
Create a rst text file for each. |
|
33
|
|
|
""" |
|
34
|
|
|
reference_file_path = f"{savu_base_path}doc/source/reference/" |
|
35
|
|
|
command_file_path = f"{reference_file_path}savu_config_commands.rst" |
|
36
|
|
|
|
|
37
|
|
|
with open(command_file_path, "w") as cfile: |
|
38
|
|
|
savu_command_test_start = """ |
|
39
|
|
|
Savu Config Commands |
|
40
|
|
|
********************** |
|
41
|
|
|
|
|
42
|
|
|
The links on this page provide help for each command. |
|
43
|
|
|
If you are using the command line please type ``-h`` or ``--help``. |
|
44
|
|
|
|
|
45
|
|
|
.. code-block:: bash |
|
46
|
|
|
|
|
47
|
|
|
savu_config --help |
|
48
|
|
|
|
|
49
|
|
|
""" |
|
50
|
|
|
# Write contents |
|
51
|
|
|
cfile.write(savu_command_test_start) |
|
52
|
|
|
for command in sc.commands: |
|
53
|
|
|
cfile.write("\n") |
|
54
|
|
|
cfile.write("* :ref:`" + command + "`") |
|
55
|
|
|
cfile.write("\n") |
|
56
|
|
|
|
|
57
|
|
|
# Document commands |
|
58
|
|
|
for command in sc.commands: |
|
59
|
|
|
cfile.write("\n") |
|
60
|
|
|
cfile.write(".. _" + command + ":") |
|
61
|
|
|
cfile.write("\n\n" + command) |
|
62
|
|
|
cfile.write(pdoc.set_underline(3, 16)) |
|
63
|
|
|
cfile.write("\n.. cssclass:: argstyle\n") |
|
64
|
|
|
cfile.write("\n .. argparse::") |
|
65
|
|
|
cfile.write("\n :module: scripts.config_generator.arg_parsers") |
|
66
|
|
|
cfile.write("\n :func: _" + command + "_arg_parser") |
|
67
|
|
|
cfile.write("\n :prog: " + command) |
|
68
|
|
|
cfile.write("\n") |
|
69
|
|
|
cfile.write("\n") |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
if __name__ == "__main__": |
|
73
|
|
|
# determine Savu base path |
|
74
|
|
|
main_dir = os.path.dirname(os.path.realpath(__file__)).split("/Savu/")[0] |
|
75
|
|
|
savu_base_path = f"{main_dir}/Savu/" |
|
76
|
|
|
|
|
77
|
|
|
# Create savu_config command rst files |
|
78
|
|
|
create_savu_config_documentation(savu_base_path) |
|
79
|
|
|
|