~ubuntu-branches/ubuntu/quantal/gutenprint/quantal

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2010-08-31 11:01:53 UTC
  • Revision ID: james.westby@ubuntu.com-20100831110153-j8yhsaewp4ohj1q3
Tags: 5.2.6-0ubuntu2
* debian/control, debian/rules, debian/ijsgutenprint-ppds.postinst,
  debian/ijsgutenprint-ppds.install: Introduced the binary package
  ijsgutenprint-ppds. This package contains all PPDs which can be generated
  from the Foomatic XML database for ijsgutenprint in one compressed pyppd
  archive. This takes much less disk space than the XML database (1.1 MB vs.
  102 MB) and access (listing all PPDs, extracting the needed PPD) is also
  significantly faster.
* debian/local/pyppd/: Added pyppd scripts to generate compressed PPD
  archives.
* debian/rules: debian/install-stamp rule was executed twice during build.
  Corrected it to avoid duplicate pre-build of the PPD files for
  ijsgutenprint.

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
 
 
32
    ppds = load()
 
33
    ppds['ARCHIVE'] = StringIO(decompress(ppds['ARCHIVE']))
 
34
 
 
35
    if ppds.has_key(ppd):
 
36
        start = ppds[ppd][0]
 
37
        length = ppds[ppd][1]
 
38
        ppds['ARCHIVE'].seek(start)
 
39
        return ppds['ARCHIVE'].read(length)
 
40
 
 
41
def main():
 
42
    usage = "usage: %prog list\n" \
 
43
            "       %prog cat URI"
 
44
    version = "%prog 0.4.3\n" \
 
45
              "Copyright (c) 2010 Vitor Baptista.\n" \
 
46
              "This is free software; see the source for copying conditions.\n" \
 
47
              "There is NO warranty; not even for MERCHANTABILITY or\n" \
 
48
              "FITNESS FOR A PARTICULAR PURPOSE."
 
49
    parser = OptionParser(usage=usage,
 
50
                          version=version)
 
51
    (options, args) = parser.parse_args()
 
52
 
 
53
    if len(args) == 0 or len(args) > 2:
 
54
        parser.error("incorrect number of arguments")
 
55
 
 
56
    if args[0].lower() == 'list':
 
57
        ls()
 
58
    elif args[0].lower() == 'cat':
 
59
        if not len(args) == 2:
 
60
            parser.error("incorrect number of arguments")
 
61
        ppd = cat(args[1])
 
62
        if not ppd:
 
63
            parser.error("Printer '%s' does not have default driver!" % args[1])
 
64
        print ppd
 
65
    else:
 
66
        parser.error("argument " + args[0] + " invalid")
 
67
 
 
68
# PPDs Archive
 
69
ppds_compressed_b64 = "@ppds_compressed_b64@"
 
70
 
 
71
if __name__ == "__main__":
 
72
    main()