source: trunk/debathena/config/printing-config/files/usr/bin/add-athena-printer @ 24215

Revision 24215, 2.5 KB checked in by broder, 14 years ago (diff)
In printing-config: * Include add-athena-printer script for configuring Athena print queues not available via BrowsePoll. parser = optparse.OptionParser( usage="usage: %prog [options] <Athena queue> [<Athena queue> ...]" ) parser.add_option('-f', '--force', action='store_true', dest='force', default=False, help="Attempt to install queue even if checks fail" ) return parser print >>sys.stderr, msg.strip() sys.exit(-1) # Local cupsd cups.setServer(LOCAL_SERVER) lc = cups.Connection() # Remote cupsd cups.setServer(REMOTE_SERVER) rc = cups.Connection() queues = rc.getPrinters() if queue not in queues: error('Athena printer %s does not exist' % queue) if not force and queue in lc.getPrinters(): error('The Athena printer %s has already been configured locally' % queue) info = queues[queue] # Download the PPD try: ppd = rc.getPPD(queue) except: error(""" try: lc.addPrinter(queue, filename=ppd, info=info['printer-info'], location=info['printer-location'], device=info['printer-uri-supported']) for k, v in rc.getPrinterAttributes(queue).items(): if not v: continue if not k.endswith('-default'): continue k = k[:-len('-default')] lc.addPrinterOptionDefault(queue, k, v) lc.acceptJobs(queue) lc.enablePrinter(queue) finally: os.unlink(ppd) options, args = parser().parse_args() try: if (not options.force and os.getuid() != 0 and grp.getgrnam('lpadmin').gr_gid not in os.getgroups()): error(""" except Exception: error(""" for q in args: addAthenaPrinter(q, force=options.force) main() { matrix currentmatrix % Push current matrix 5 1 roll % roll to bottom 3 index 2 index add 3 index moveto % move to start 4 2 roll translate scale % translate then scale 0 0 1 0 360 arc % draw it setmatrix % restore matrix } def motdfontsize mul leftmargin exch currentpoint exch pop exch sub moveto cvn motdfontsize selectfont gsave (\033) search % post (\033) pre true OR string false { stringwidth pop exch pop exch % prelen post ( ) search exch dofont % prelen post ( ) true OR prelen false { pop measure add } if } { stringwidth pop } ifelse grestore dup measure currentpoint pop add rightmargin gt { currentpoint pop leftmargin ne { 1 newline } if } if currentpoint pop exch { (\033) search % post (\033) pre true OR string false { show pop ( ) search exch dofont % post ( ) true OR false { pop exch pop currentpoint pop exch } { exit } ifelse } { show exit } ifelse } loop % and write the following space if we wrote anything else currentpoint pop ne { ( ) show } if % split into words and write them one by one { ( ) search { dup length 0 eq { pop show } { doword pop } ifelse } { exit } ifelse } loop doword % If text contains newline, parwrap first half, newline, and wrap % second half. if not, just parwrap whole thing. (\n) search { parwrap pop 1.75 newline innerwrap } { parwrap } ifelse exch /rightmargin exch def exch /leftmargin exch def (Times-Roman) dofont innerwrap dup stringwidth pop -1 mul 0 rmoveto show % set clipping path gsave newpath pageleft pagetop moveto pageright pagetop lineto pageright vsplit lineto pageleft vsplit lineto pageleft pagetop lineto clip newpath % date pageleft pagetop otherfontsize sub moveto otherfont setfont ({time-at-creation}) show % logo pageleft hsplit .25 inch sub add 2 div vsplit pagetop add 2 div moveto gsave .75 setgray logo grestore % vertical line hsplit pagetop moveto hsplit vsplit lineto stroke % username gsave pageright pagetop userfontsize .75 mul sub moveto userfont setfont pageright hsplit .25 inch add sub dup ({job-originating-user-name}) stringwidth pop lt { ({job-originating-user-name}) stringwidth pop div 1 scale } { pop } ifelse ({job-originating-user-name}) stringwidth pop -1 mul 0 rmoveto ({job-originating-user-name}) show grestore otherfont setfont % host pageright pagetop userfontsize sub otherfontsize sub moveto ({job-originating-host-name}) rshow % queue/job pageright pagetop userfontsize sub otherfontsize 2.2 mul sub moveto ({printer-name})show pageright pagetop userfontsize sub otherfontsize 2.2 mul sub moveto ({job-name}) rshow % horizontal line pageleft vsplit moveto pageright vsplit lineto stroke % undo clipping path grestore % left top right bottom spacing % left bottom right top spacing /spacing exch def /graphtop exch def /graphright exch def /graphbot exch def /graphleft exch def gsave 0 setlinewidth graphleft spacing graphright { dup graphtop moveto graphbot lineto stroke } for graphtop spacing neg graphbot { dup graphleft exch moveto graphright exch lineto stroke } for grestore % ulx uly length height 4 div % substitute h/4 for h 4 2 roll moveto % go to x, y 5 { } repeat pop pop % clear off the stack % llx lly urx ury height number % (coords assume transforms undone) [/n /h /ury /urx /lly /llx] {exch def} forall % undo transforms from the top of the job -90 rotate inchwidth inch neg 0 translate 2 setlinecap newpath % calculate dy between staves based on size and num/page ury lly sub h n mul sub n 1 sub div h add 0 1 n 1 sub { % spc i } for stroke pop 0.40 setlinewidth pagetop vsplit sub 1 inch add pageleft pagetop pageright .5 inch sub 25 12 musicpaper 0.48 setlinewidth pagetop vsplit sub 1 inch add pageleft pagetop pageright .5 inch sub 30 10 musicpaper /hex { dohex }
  • Property svn:executable set to *
Line 
1#!/usr/bin/python
2
3import grp
4import optparse
5import os
6import sys
7
8import cups
9
10
11LOCAL_SERVER = cups.getServer()
12REMOTE_SERVER = 'printers.mit.edu'
13
14
15def parser():
16    parser = optparse.OptionParser(
17        usage="usage: %prog [options] <Athena queue> [<Athena queue> ...]"
18        )
19
20    parser.add_option('-f', '--force',
21                      action='store_true',
22                      dest='force',
23                      default=False,
24                      help="Attempt to install queue even if checks fail"
25                      )
26
27    return parser
28
29
30def error(msg):
31    print >>sys.stderr, msg.strip()
32    sys.exit(-1)
33
34
35def addAthenaPrinter(queue, force=False):
36    # Local cupsd
37    cups.setServer(LOCAL_SERVER)
38    lc = cups.Connection()
39    # Remote cupsd
40    cups.setServer(REMOTE_SERVER)
41    rc = cups.Connection()
42
43    queues = rc.getPrinters()
44    if queue not in queues:
45        error('Athena printer %s does not exist' % queue)
46    if not force and queue in lc.getPrinters():
47        error('The Athena printer %s has already been configured locally' %
48              queue)
49
50    info = queues[queue]
51
52    # Download the PPD
53    try:
54        ppd = rc.getPPD(queue)
55    except:
56        error("""
57There was a problem downloading the printer configuration from the
58Athena print servers. This will happen if you're not on campus. If you
59are on campus, this could indicate a bug in Debathena.
60""")
61    try:
62        lc.addPrinter(queue,
63                      filename=ppd,
64                      info=info['printer-info'],
65                      location=info['printer-location'],
66                      device=info['printer-uri-supported'])
67
68        for k, v in rc.getPrinterAttributes(queue).items():
69            if not v:
70                continue
71            if not k.endswith('-default'):
72                continue
73            k = k[:-len('-default')]
74
75            lc.addPrinterOptionDefault(queue, k, v)
76
77        lc.acceptJobs(queue)
78        lc.enablePrinter(queue)
79    finally:
80        os.unlink(ppd)
81
82
83def main():
84    options, args = parser().parse_args()
85
86    try:
87        if (not options.force and
88            os.getuid() != 0 and
89            grp.getgrnam('lpadmin').gr_gid not in os.getgroups()):
90            error("""
91You do not appear to have permission to modify printers on this system.
92""")
93    except Exception:
94        error("""
95Unable to determine if you have permission to modify printers on this
96system.
97""")
98
99    for q in args:
100        addAthenaPrinter(q, force=options.force)
101
102if __name__ == '__main__':
103    main()
Note: See TracBrowser for help on using the repository browser.