1 | """A generator for simple printing utility wrapper scripts. |
---|
2 | |
---|
3 | Given the command line options for the CUPS and LPRng forms of a |
---|
4 | command, as well as the specific flag which specifies the print queue |
---|
5 | to use, this module generates a main function for a wrapper script |
---|
6 | around that command that appropriate dispatches invocations between |
---|
7 | the CUPS and LPRng commands. |
---|
8 | """ |
---|
9 | |
---|
10 | |
---|
11 | import os |
---|
12 | import sys |
---|
13 | |
---|
14 | from debathena.printing import common |
---|
15 | |
---|
16 | |
---|
17 | def 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) |
---|