OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Runs 'gn help' and various subhelps, and spits out html. | 6 # Runs 'gn help' and various subhelps, and spits out html. |
7 # TODO: | 7 # TODO: |
8 # - Handle numbered and dashed lists -> <ol> <ul>. (See "os" and "toolchain"). | 8 # - Handle numbered and dashed lists -> <ol> <ul>. (See "os" and "toolchain"). |
9 # - Handle "Arguments:" blocks a bit better (the argument names could be | 9 # - Handle "Arguments:" blocks a bit better (the argument names could be |
10 # distinguished). | 10 # distinguished). |
11 # - Convert "|blahblah|" to <code>. | 11 # - Convert "|blahblah|" to <code>. |
12 # - Spit out other similar formats like wiki, markdown, whatever. | 12 # - Spit out other similar formats like wiki, markdown, whatever. |
13 | 13 |
14 import cgi | 14 import cgi |
| 15 import re |
15 import subprocess | 16 import subprocess |
16 import sys | 17 import sys |
17 | 18 |
18 | 19 |
19 def GetOutput(*args): | 20 def GetOutput(*args): |
20 try: | 21 try: |
21 return subprocess.check_output([sys.argv[1]] + list(args)) | 22 # TODO: Remove ansi escape code stripping if crbug.com/362239 gets fixed. |
| 23 ansi_escape = re.compile(r'\x1b[^m]*m') |
| 24 return ansi_escape.sub( |
| 25 '', subprocess.check_output([sys.argv[1]] + list(args))) |
22 except subprocess.CalledProcessError: | 26 except subprocess.CalledProcessError: |
23 return '' | 27 return '' |
24 | 28 |
25 | 29 |
26 def ParseTopLevel(out): | 30 def ParseTopLevel(out): |
27 commands = [] | 31 commands = [] |
28 output = [] | 32 output = [] |
29 for line in out.splitlines(): | 33 for line in out.splitlines(): |
30 if line.startswith(' '): | 34 if line.startswith(' '): |
31 command, sep, rest = line.partition(':') | 35 command, sep, rest = line.partition(':') |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 footer = '</div></body></html>' | 100 footer = '</div></body></html>' |
97 commands, output = ParseTopLevel(GetOutput('help')) | 101 commands, output = ParseTopLevel(GetOutput('help')) |
98 for command in commands: | 102 for command in commands: |
99 output += ParseCommand(command, GetOutput('help', command)) | 103 output += ParseCommand(command, GetOutput('help', command)) |
100 print header + '\n'.join(output) + footer | 104 print header + '\n'.join(output) + footer |
101 return 0 | 105 return 0 |
102 | 106 |
103 | 107 |
104 if __name__ == '__main__': | 108 if __name__ == '__main__': |
105 sys.exit(main()) | 109 sys.exit(main()) |
OLD | NEW |