home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1397 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.5 KB  |  68 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL 3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. import time
  9. import bz2
  10. from calibre.constants import isfreebsd
  11. from calibre.constants import __version__, __appname__, __author__
  12.  
  13. def create_man_page(prog, parser):
  14.     usage = parser.usage.splitlines()
  15.     for i, line in enumerate(list(usage)):
  16.         if not line.strip():
  17.             usage[i] = '.PP'
  18.             continue
  19.         usage[i] = line.replace('%prog', prog)
  20.     
  21.     lines = [
  22.         '.TH ' + prog.upper() + ' "1" ' + time.strftime('"%B %Y"') + ' "%s (%s %s)" "%s"' % (prog, __appname__, __version__, __appname__),
  23.         '.SH NAME',
  24.         prog + ' \\- part of ' + __appname__,
  25.         '.SH SYNOPSIS',
  26.         '.B "%s"' % prog + '\\fR ' + ' '.join(usage[0].split()[1:]),
  27.         '.SH DESCRIPTION']
  28.     lines += usage[1:]
  29.     lines += [
  30.         '.SH OPTIONS']
  31.     
  32.     def format_option(opt):
  33.         ans = [
  34.             '.TP']
  35.         opts = []
  36.         opts += opt._short_opts
  37.         opts.append(opt.get_opt_string())
  38.         opts = [ '\\fB' + x.replace('-', '\\-') + '\\fR' for x in opts ]
  39.         ans.append(', '.join(opts))
  40.         help = [] if opt.help else ''
  41.         ans.append(help.replace('%prog', prog).replace('%default', str(opt.default)))
  42.         return ans
  43.  
  44.     for opt in parser.option_list:
  45.         lines.extend(format_option(opt))
  46.     
  47.     for group in parser.option_groups:
  48.         lines.append('.SS ' + group.title)
  49.         if group.description:
  50.             lines.extend([
  51.                 '.PP',
  52.                 group.description])
  53.         
  54.         for opt in group.option_list:
  55.             lines.extend(format_option(opt))
  56.         
  57.     
  58.     lines += [
  59.         '.SH SEE ALSO',
  60.         'The User Manual is available at http://calibre-ebook.com/user_manual',
  61.         '.PP',
  62.         '.B Created by ' + __author__]
  63.     lines = [ _[1] if isinstance(x, unicode) else unicode(x, 'utf-8', 'replace') for x in lines ]
  64.     if not isfreebsd:
  65.         return bz2.compress(u'\n'.join(lines).encode('utf-8'))
  66.     return u'\n'.join(lines).encode('utf-8')
  67.  
  68.