Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
e857e99d
Commit
e857e99d
authored
Jun 07, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
help2rst.py: Support Python 3.4
parent
6d537c41
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
25 deletions
+26
-25
help2rst.py
help2rst.py
+26
-25
No files found.
help2rst.py
View file @
e857e99d
...
...
@@ -4,6 +4,7 @@
# script to produce rst file from program's help output.
from
__future__
import
unicode_literals
from
__future__
import
print_function
import
sys
import
re
import
argparse
...
...
@@ -44,8 +45,8 @@ def help2man(infile):
line
=
infile
.
readline
().
strip
()
m
=
re
.
match
(
r'^Usage: (.*)'
,
line
)
if
not
m
:
print
'usage line is invalid. Expected following lines:'
print
'Usage: cmdname ...'
print
(
'usage line is invalid. Expected following lines:'
)
print
(
'Usage: cmdname ...'
)
sys
.
exit
(
1
)
synopsis
=
m
.
group
(
1
).
split
(
' '
,
1
)
if
len
(
synopsis
)
==
2
:
...
...
@@ -60,7 +61,7 @@ def help2man(infile):
break
description
.
append
(
line
)
print
'''
print
(
'''
.. GENERATED by help2rst.py. DO NOT EDIT DIRECTLY.
.. program:: {cmdname}
...
...
@@ -79,7 +80,7 @@ DESCRIPTION
{description}
'''
.
format
(
cmdname
=
cmdname
,
args
=
args
,
cmdnameunderline
=
'='
*
(
len
(
cmdname
)
+
3
),
synopsis
=
synopsis
,
description
=
format_text
(
'
\n
'
.
join
(
description
)))
synopsis
=
synopsis
,
description
=
format_text
(
'
\n
'
.
join
(
description
)))
)
in_arg
=
False
in_footer
=
False
...
...
@@ -88,16 +89,16 @@ DESCRIPTION
line
=
line
.
rstrip
()
if
not
line
.
strip
()
and
in_arg
:
print
''
print
()
continue
if
line
.
startswith
(
' '
)
and
in_arg
:
if
not
line
.
startswith
(
arg_indent
):
sys
.
stderr
.
write
(
'warning: argument description is not indented correctly. We need {} spaces as indentation.
\n
'
.
format
(
len
(
arg_indent
)))
print
'{}'
.
format
(
format_arg_text
(
line
[
len
(
arg_indent
):]
))
print
(
'{}'
.
format
(
format_arg_text
(
line
[
len
(
arg_indent
):])
))
continue
if
in_arg
:
print
''
print
()
in_arg
=
False
if
line
==
'--'
:
...
...
@@ -105,22 +106,22 @@ DESCRIPTION
continue
if
in_footer
:
print
line
.
strip
(
)
print
(
line
.
strip
()
)
continue
if
line
==
'Options:'
:
print
'OPTIONS'
print
'-------'
print
''
print
(
'OPTIONS'
)
print
(
'-------'
)
print
()
continue
if
line
.
startswith
(
' <'
):
# positional argument
m
=
re
.
match
(
r'^(?:\s+)([a-zA-Z0-9-_<>]+)(.*)'
,
line
)
argname
,
rest
=
m
.
group
(
1
),
m
.
group
(
2
)
print
'.. describe:: {}'
.
format
(
argname
)
print
''
print
'{}'
.
format
(
format_arg_text
(
rest
.
strip
(
)))
print
(
'.. describe:: {}'
.
format
(
argname
)
)
print
()
print
(
'{}'
.
format
(
format_arg_text
(
rest
.
strip
()
)))
in_arg
=
True
continue
...
...
@@ -128,9 +129,9 @@ DESCRIPTION
# positional argument
m
=
re
.
match
(
r'^(?:\s+)(\([a-zA-Z0-9-_<> ]+\))(.*)'
,
line
)
argname
,
rest
=
m
.
group
(
1
),
m
.
group
(
2
)
print
'.. describe:: {}'
.
format
(
argname
)
print
''
print
'{}'
.
format
(
format_arg_text
(
rest
.
strip
(
)))
print
(
'.. describe:: {}'
.
format
(
argname
)
)
print
()
print
(
'{}'
.
format
(
format_arg_text
(
rest
.
strip
()
)))
in_arg
=
True
continue
...
...
@@ -140,23 +141,23 @@ DESCRIPTION
r'^(?:\s+)(-\S+?(?:, -\S+?)*)($| .*)'
,
line
)
argname
,
rest
=
m
.
group
(
1
),
m
.
group
(
2
)
print
'.. option:: {}'
.
format
(
argname
)
print
''
print
(
'.. option:: {}'
.
format
(
argname
)
)
print
()
rest
=
rest
.
strip
()
if
len
(
rest
):
print
'{}'
.
format
(
format_arg_text
(
rest
))
print
(
'{}'
.
format
(
format_arg_text
(
rest
)
))
in_arg
=
True
continue
if
not
line
.
startswith
(
' '
)
and
line
.
endswith
(
':'
):
# subsection
subsec
=
line
.
strip
()[:
-
1
]
print
'{}'
.
format
(
subsec
)
print
'{}'
.
format
(
'~'
*
len
(
subsec
))
print
''
print
(
'{}'
.
format
(
subsec
)
)
print
(
'{}'
.
format
(
'~'
*
len
(
subsec
)
))
print
()
continue
print
line
.
strip
(
)
print
(
line
.
strip
()
)
def
format_text
(
text
):
# escape *
...
...
@@ -186,6 +187,6 @@ if __name__ == '__main__':
args
=
parser
.
parse_args
()
help2man
(
sys
.
stdin
)
if
args
.
include
:
print
''
print
()
with
open
(
args
.
include
)
as
f
:
sys
.
stdout
.
write
(
f
.
read
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment