source: trunk/debathena/config/printing-config/debathena/printing/simple.py @ 25209

Revision 25209, 2.1 KB checked in by jdreed, 13 years ago (diff)
In printing-config: * Deal with CUPS' lprm's stupid syntax (Trac: #720)
Line 
1"""A generator for simple printing utility wrapper scripts.
2
3Given the command line options for the CUPS and LPRng forms of a
4command, as well as the specific flag which specifies the print queue
5to use, this module generates a main function for a wrapper script
6around that command that appropriate dispatches invocations between
7the CUPS and LPRng commands.
8"""
9
10
11import os
12import sys
13
14from debathena.printing import common
15
16
17def simple(command, optinfo, queue_opt, args):
18    args.pop(0)
19   
20    # Sigh.  CUPS' lprm, in its infinite wisdom, accepts '-' as a
21    # specifier for 'all jobs', which doesn't work with any option
22    # parsing code, ever.  However, CUPS does require that it be the
23    # last argument, so check for it, and save it because parse_args
24    # will kill it
25    lprmdash=False
26    if (command == 'lprm') and len(args) and (args[-1] == '-'):
27        lprmdash=True
28
29    queue = common.get_default_printer()
30    try:
31        argstyle, options, arguments = common.parse_args(args, optinfo)
32
33        # Find the last queue specified in the arguments
34        queue_args, options = common.extract_opt(options, queue_opt)
35        if queue_args:
36            queue = queue_args[-1][-1]
37
38        # Now that we've sliced up the arguments, put them back
39        # together
40        args = [o + a for o, a in options] + arguments
41
42    except ValueError:
43        # parse_args returned None, so we learned nothing. We'll just
44        # go with the default queue
45        pass
46
47    if not queue:
48        # We tried and couldn't figure it out, so not our problem
49        common.error(2, ("\n"
50                         "No default printer configured. Specify a %s option, or configure a\n"
51                         "default printer via e.g. System | Administration | Printing.\n"
52                         "\n" % queue_opt))
53
54    system, server, queue = common.find_queue(queue)
55
56    args.insert(0, '%s%s' % (queue_opt, queue))
57    if server:
58        os.environ['CUPS_SERVER'] = server
59
60    # And now add it back (see above)
61    if lprmdash and (system == common.SYSTEM_CUPS):
62        args.append('-')
63
64    common.dispatch_command(system, command, args)
Note: See TracBrowser for help on using the repository browser.