~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/pdf/manipulate/cli.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import with_statement
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
__license__   = 'GPL v3'
 
5
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
 
6
__docformat__ = 'restructuredtext en'
 
7
 
 
8
'''
 
9
Command line interface to run pdf manipulation commands.
 
10
'''
 
11
 
 
12
import string, sys
 
13
 
 
14
from calibre.utils.config import OptionParser
 
15
from calibre.utils.logging import Log
 
16
from calibre.constants import preferred_encoding
 
17
from calibre.ebooks.pdf.manipulate import crop, decrypt, encrypt, \
 
18
    info, merge, reverse, rotate, split
 
19
 
 
20
COMMANDS = {
 
21
             'crop'    : crop,
 
22
             'decrypt' : decrypt,
 
23
             'encrypt' : encrypt,
 
24
             'info'    : info,
 
25
             'merge'   : merge,
 
26
             'reverse' : reverse,
 
27
             'rotate'  : rotate,
 
28
             'split'   : split,
 
29
           }
 
30
 
 
31
USAGE = '%prog ' + _('''command ...
 
32
 
 
33
command can be one of the following:
 
34
[%%commands]
 
35
 
 
36
Use %prog command --help to get more information about a specific command
 
37
 
 
38
Manipulate a PDF.
 
39
''').replace('%%commands', string.join(sorted(COMMANDS.keys()), ', '))
 
40
 
 
41
def print_help(parser, log):
 
42
    help = parser.format_help().encode(preferred_encoding, 'replace')
 
43
    log(help)
 
44
 
 
45
def option_parser():
 
46
    return OptionParser(usage=USAGE)
 
47
 
 
48
def main(args=sys.argv):
 
49
    log = Log()
 
50
    parser = option_parser()
 
51
 
 
52
    if len(args) < 2:
 
53
        print 'Error: No command sepecified.\n'
 
54
        print_help(parser, log)
 
55
        return 1
 
56
 
 
57
    command = args[1].lower().strip()
 
58
 
 
59
    if command in COMMANDS.keys():
 
60
        del args[1]
 
61
        return COMMANDS[command].main(args, command)
 
62
    else:
 
63
        parser.parse_args(args)
 
64
        print 'Unknown command %s.\n' % command
 
65
        print_help(parser, log)
 
66
        return 1
 
67
 
 
68
    # We should never get here.
 
69
    return 0
 
70
 
 
71
if __name__ == '__main__':
 
72
    sys.exit(main())