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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2009, John Schember <john@nachtimwald.com>'
  7. __docformat__ = 'restructuredtext en'
  8. import os
  9. import sys
  10. from calibre.utils.config import OptionParser
  11. from calibre.utils.logging import Log
  12. from calibre.constants import preferred_encoding
  13. from calibre.ebooks.pdf.verify import is_valid_pdfs, is_encrypted
  14. from calibre import prints
  15. from calibre.utils.podofo import podofo, podofo_err
  16. USAGE = '\n%prog %%name ' + _('file.pdf ...\n\nGet info about a PDF.\n')
  17.  
  18. def print_help(parser, log):
  19.     help = parser.format_help().encode(preferred_encoding, 'replace')
  20.     log(help)
  21.  
  22.  
  23. def option_parser(name):
  24.     usage = USAGE.replace('%%name', name)
  25.     return OptionParser(usage = usage)
  26.  
  27.  
  28. def print_info(pdf_path):
  29.     if not podofo:
  30.         raise RuntimeError('Failed to load PoDoFo with error:' + podofo_err)
  31.     podofo
  32.     p = podofo.PDFDoc()
  33.     p.open(pdf_path)
  34.     
  35.     fmt = lambda x, y: '%-20s: %s' % (x, y)
  36.     print 
  37.     prints(fmt(_('Title'), p.title))
  38.     prints(fmt(_('Author'), p.author))
  39.     prints(fmt(_('Subject'), p.subject))
  40.     prints(fmt(_('Creator'), p.creator))
  41.     prints(fmt(_('Producer'), p.producer))
  42.     prints(fmt(_('Pages'), p.pages))
  43.     prints(fmt(_('File Size'), os.stat(pdf_path).st_size))
  44.     None(prints(fmt, _('PDF Version') if p.version else _('Unknown')))
  45.  
  46.  
  47. def main(args = sys.argv, name = ''):
  48.     log = Log()
  49.     parser = option_parser(name)
  50.     (opts, args) = parser.parse_args(args)
  51.     args = args[1:]
  52.     if len(args) < 1:
  53.         print 'Error: No PDF sepecified.\n'
  54.         print_help(parser, log)
  55.         return 1
  56.     bad_pdfs = is_valid_pdfs(args)
  57.     if bad_pdfs != []:
  58.         for pdf in bad_pdfs:
  59.             print 'Error: Could not read file `%s`.' % pdf
  60.         
  61.         return 1
  62.     enc = False
  63.     for pdf in args:
  64.         if is_encrypted(pdf):
  65.             enc = True
  66.             print 'Error: file `%s` is encrypted. Please decrypt first.' % pdf
  67.             continue
  68.         len(args) < 1
  69.     
  70.     if enc:
  71.         return 1
  72.     for pdf in args:
  73.         print_info(pdf)
  74.     
  75.     return 0
  76.  
  77. if __name__ == '__main__':
  78.     sys.exit(main())
  79.  
  80.