]>
Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/prepare_manpage.py
776e6556e5b2bd683acbcf79d7bc07431be6548a
1 from __future__
import unicode_literals
8 ROOT_DIR
= os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
)))
9 README_FILE
= os
.path
.join(ROOT_DIR
, 'README.md')
12 def filter_options(readme
):
15 for line
in readme
.split('\n'):
16 if line
.startswith('# '):
17 if line
[2:].startswith('OPTIONS'):
23 if line
.lstrip().startswith('-'):
24 option
, description
= re
.split(r
'\s{2,}', line
.lstrip())
25 split_option
= option
.split(' ')
27 if not split_option
[-1].startswith('-'): # metavar
28 option
= ' '.join(split_option
[:-1] + ['*%s*' % split_option
[-1]])
30 # Pandoc's definition_lists. See http://pandoc.org/README.html
31 # for more information.
32 ret
+= '\n%s\n: %s\n' % (option
, description
)
34 ret
+= line
.lstrip() + '\n'
40 with io
.open(README_FILE
, encoding
='utf-8') as f
:
43 PREFIX
= '''%YOUTUBE-DL(1)
47 youtube\-dl \- download videos from youtube.com or other video platforms
51 **youtube-dl** \[OPTIONS\] URL [URL...]
54 readme
= re
.sub(r
'(?s)^.*?(?=# DESCRIPTION)', '', readme
)
55 readme
= re
.sub(r
'\s+youtube-dl \[OPTIONS\] URL \[URL\.\.\.\]', '', readme
)
56 readme
= PREFIX
+ readme
58 readme
= filter_options(readme
)
60 if sys
.version_info
< (3, 0):
61 print(readme
.encode('utf-8'))