]>
Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/prepare_manpage.py
ce548739f57f5c52e6c73d46f2095e894c8f940d
   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') 
  11 PREFIX 
= '''%YOUTUBE-DL(1) 
  15 youtube\-dl \- download videos from youtube.com or other video platforms 
  19 **youtube-dl** \[OPTIONS\] URL [URL...] 
  25     parser 
= optparse
.OptionParser(usage
='%prog OUTFILE.md') 
  26     options
, args 
= parser
.parse_args() 
  28         parser
.error('Expected an output filename') 
  32     with io
.open(README_FILE
, encoding
='utf-8') as f
: 
  35     readme 
= re
.sub(r
'(?s)^.*?(?=# DESCRIPTION)', '', readme
) 
  36     readme 
= re
.sub(r
'\s+youtube-dl \[OPTIONS\] URL \[URL\.\.\.\]', '', readme
) 
  37     readme 
= PREFIX 
+ readme
 
  39     readme 
= filter_options(readme
) 
  41     with io
.open(outfile
, 'w', encoding
='utf-8') as outf
: 
  45 def filter_options(readme
): 
  48     for line 
in readme
.split('\n'): 
  49         if line
.startswith('# '): 
  50             if line
[2:].startswith('OPTIONS'): 
  56             if line
.lstrip().startswith('-'): 
  57                 split 
= re
.split(r
'\s{2,}', line
.lstrip()) 
  58                 # Description string may start with `-` as well. If there is 
  59                 # only one piece then it's a description bit not an option. 
  61                     option
, description 
= split
 
  62                     split_option 
= option
.split(' ') 
  64                     if not split_option
[-1].startswith('-'):  # metavar 
  65                         option 
= ' '.join(split_option
[:-1] + ['*%s*' % split_option
[-1]]) 
  67                     # Pandoc's definition_lists. See http://pandoc.org/README.html 
  68                     # for more information. 
  69                     ret 
+= '\n%s\n:   %s\n' % (option
, description
) 
  71             ret 
+= line
.lstrip() + '\n' 
  77 if __name__ 
== '__main__':