forked from conan-io/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands_help_update.py
104 lines (85 loc) · 2.64 KB
/
commands_help_update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import subprocess
import sys
commands = ["config", "get", "info", "install", "search", "create", "export-pkg", "export", "new",
"test", "upload", "build", "package", "source", "alias", "copy", "download", "help",
"imports", "profile", "remote", "remove", "user"]
folder = {
"config": "consumer",
"get": "consumer",
"info": "consumer",
"install": "consumer",
"search": "consumer",
"create": "creator",
"export-pkg": "creator",
"export": "creator",
"new": "creator",
"test": "creator",
"upload": "creator",
"build": "development",
"package": "development",
"source": "development",
"alias": "misc",
"copy": "misc",
"download": "misc",
"help": "misc",
"imports": "misc",
"profile": "misc",
"remote": "misc",
"remove": "misc",
"user": "misc"
}
conan_name = ""
try:
conan_name = sys.argv[1]
except IndexError:
conan_name = "conan"
template = """
.. _conan_{0}:
conan {0}
======{1}
.. code-block:: bash
$ {2}
{3}
.. code-block:: text
{4}"""
for command in commands:
execute = [conan_name, command, "-h"]
print(execute)
output = str(subprocess.check_output(execute))
output = output.rstrip()
search_string = "conan %s [-h]" % command
output = search_string + output.split(search_string)[1]
output = output.split("\\r\\n\\r\\n", 2)
underline = ""
for char in command:
underline += "="
small_help = ""
for line in output[0].replace("\\r", "").replace("\\n", "\n").splitlines():
if not line.startswith("conan"):
line = line[1:]
small_help += "%s\n" % line.rstrip()
text_help = output[1].replace("\\r", "").replace("\\n", "\n").rstrip()
arguments_help = ""
for line in output[2].replace("\\r", "").split("\\n"):
arguments_help += (" %s\n" % line) if line else "\n"
arguments_help = arguments_help
text = template.format(command, underline, small_help, text_help, arguments_help)[:-7]
text = text.replace("\\'", "\'")
filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "reference", "commands",
folder[command], command)
print("filepath:", filepath)
file = open("%s.rst" % filepath, "r")
content = file.read()
file.close()
file = open("%s.rst" % filepath, "w")
separator = "\n\n\n"
if content:
content = content.split(separator, 1)
if len(content) > 1:
file.write(text + separator + content[1])
else:
raise Exception("Separator (two consecutive newlines) not found")
else:
file.write(text)
file.close()