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

Revision 24763, 1.6 KB checked in by broder, 15 years ago (diff)
printing-config: Make lpq, lprm, and lp wrappers around similarly named Python modules.
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    queue = common.get_default_printer()
21    try:
22        argstyle, options, arguments = common.parse_args(args, optinfo)
23
24        # Find the last queue specified in the arguments
25        queue_args, options = common.extract_opt(options, queue_opt)
26        if queue_args:
27            queue = queue_args[-1][-1]
28
29        # Now that we've sliced up the arguments, put them back
30        # together
31        args = [o + a for o, a in options] + arguments
32    except ValueError:
33        # parse_args returned None, so we learned nothing. We'll just
34        # go with the default queue
35        pass
36
37    if not queue:
38        # We tried and couldn't figure it out, so not our problem
39        common.error(2, ("\n"
40                         "No default printer configured. Specify a %s option, or configure a\n"
41                         "default printer via e.g. System | Administration | Printing.\n"
42                         "\n" % queue_opt))
43
44    system, server, queue = common.find_queue(queue)
45
46    args.insert(0, '%s%s' % (queue_opt, queue))
47    if server:
48        os.environ['CUPS_SERVER'] = server
49
50    common.dispatch_command(system, command, args)
Note: See TracBrowser for help on using the repository browser.