~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to debian/local/pyppd/pyppd/pyppd-ppdfile.in

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-10-06 15:03:44 UTC
  • mfrom: (1.6.1) (20.1.16 quantal)
  • Revision ID: package-import@ubuntu.com-20121006150344-2p3xz26br0t3hu2q
Tags: 3.12.10-1
* New upstream release
  - Fixes "Network scanning fails (Closes: #683033)
* quilt refresh hplip-syslog-fix-debug-messages-to-error.dpatch
* Fix "error in clean build env" updated debian/rules (Closes: #687129)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
# compressor.py
4
 
@compressor@
5
 
# compressor.py
6
 
 
7
 
from optparse import OptionParser
8
 
from sys import argv
9
 
import base64
10
 
import cPickle
11
 
from cStringIO import StringIO
12
 
from os.path import basename
13
 
 
14
 
def load():
15
 
    ppds_compressed = base64.b64decode(ppds_compressed_b64)
16
 
    ppds_decompressed = decompress(ppds_compressed)
17
 
    ppds = cPickle.loads(ppds_decompressed)
18
 
    return ppds
19
 
 
20
 
def ls():
21
 
    binary_name = basename(argv[0])
22
 
    ppds = load()
23
 
    for key, value in ppds.iteritems():
24
 
        if key == 'ARCHIVE': continue
25
 
        for ppd in value[2]:
26
 
            print ppd.replace('"', '"' + binary_name + ':', 1)
27
 
 
28
 
def cat(ppd):
29
 
    # Ignore driver's name, take only PPD's
30
 
    ppd = ppd.split(":")[-1]
31
 
    # Remove also the index
32
 
    ppd = "0/" + ppd[ppd.find("/")+1:]
33
 
 
34
 
    ppds = load()
35
 
    ppds['ARCHIVE'] = StringIO(decompress(ppds['ARCHIVE']))
36
 
 
37
 
    if ppds.has_key(ppd):
38
 
        start = ppds[ppd][0]
39
 
        length = ppds[ppd][1]
40
 
        ppds['ARCHIVE'].seek(start)
41
 
        return ppds['ARCHIVE'].read(length)
42
 
 
43
 
def main():
44
 
    usage = "usage: %prog list\n" \
45
 
            "       %prog cat URI"
46
 
    version = "%prog 0.4.9\n" \
47
 
              "Copyright (c) 2010 Vitor Baptista.\n" \
48
 
              "This is free software; see the source for copying conditions.\n" \
49
 
              "There is NO warranty; not even for MERCHANTABILITY or\n" \
50
 
              "FITNESS FOR A PARTICULAR PURPOSE."
51
 
    parser = OptionParser(usage=usage,
52
 
                          version=version)
53
 
    (options, args) = parser.parse_args()
54
 
 
55
 
    if len(args) == 0 or len(args) > 2:
56
 
        parser.error("incorrect number of arguments")
57
 
 
58
 
    if args[0].lower() == 'list':
59
 
        ls()
60
 
    elif args[0].lower() == 'cat':
61
 
        if not len(args) == 2:
62
 
            parser.error("incorrect number of arguments")
63
 
        ppd = cat(args[1])
64
 
        if not ppd:
65
 
            parser.error("Printer '%s' does not have default driver!" % args[1])
66
 
        print ppd
67
 
    else:
68
 
        parser.error("argument " + args[0] + " invalid")
69
 
 
70
 
# PPDs Archive
71
 
ppds_compressed_b64 = "@ppds_compressed_b64@"
72
 
 
73
 
if __name__ == "__main__":
74
 
    try:
75
 
        main()
76
 
    except (IOError, KeyboardInterrupt):
77
 
        # We don't want neither IOError nor KeyboardInterrupt throwing a
78
 
        # traceback into stdout.
79
 
        pass