summaryrefslogtreecommitdiff
path: root/src/test-cups-pk.py
blob: 19a82ba578486db13307220960b94c9eacd15456 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
# vim: set ts=4 sw=4 et: coding=UTF-8
#
# Copyright (C) 2008 Novell, Inc.
#
# Authors: Vincent Untz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

import os
import sys

import dbus

def removeprinter(cups_pk, printer_name):
    error = cups_pk.PrinterDelete(printer_name)

    if not type(error) in [dbus.String, dbus.UTF8String]:
           print 'Unexpected return value'
           return

    if error == '':
        print 'Worked!'
    else:
        print 'Ouch: %s' % error

def addprinter(cups_pk, printer_name, printer_uri, ppd_file, info, location):
    error = cups_pk.PrinterAdd(printer_name, printer_uri, ppd_file, info, location)

    if not type(error) in [dbus.String, dbus.UTF8String]:
           print 'Unexpected return value'
           return

    if error == '':
        print 'Worked!'
    else:
        print 'Ouch: %s' % error

def acceptjobs(cups_pk, printer_name, enabled, reason):
    error = cups_pk.PrinterSetAcceptJobs(printer_name, enabled, reason)

    if not type(error) in [dbus.String, dbus.UTF8String]:
           print 'Unexpected return value'
           return

    if error == '':
        print 'Worked!'
    else:
        print 'Ouch: %s' % error

def changeoption(cups_pk, printer_name, option, value):
    error = cups_pk.PrinterAddOptionDefault(printer_name, option, value)

    if not type(error) in [dbus.String, dbus.UTF8String]:
           print 'Unexpected return value'
           return

    if error == '':
        print 'Worked!'
    else:
        print 'Ouch: %s' % error

def main(args):
    system_bus = dbus.SystemBus()

    cups_pk_object = system_bus.get_object('org.opensuse.CupsPkHelper.Mechanism', '/')
    cups_pk_interface = dbus.Interface(cups_pk_object, 'org.opensuse.CupsPkHelper.Mechanism')

    try:
        #removeprinter(cups_pk_interface, "MyPrinter")
        addprinter(cups_pk_interface, "MyPrinter", "smb://really/cool", "HP/Business_Inkjet_2200-chp2200.ppd.gz", "This is my printer", "At home")
        #changeoption(cups_pk_interface, "MyPrinter", "toto", "At home")
        #acceptjobs(cups_pk_interface, "MyPrinter", True, "")
    except dbus.exceptions.DBusException, e:
        print 'Error: %s' % e


if __name__ == '__main__':
    try:
      main(sys.argv)
    except KeyboardInterrupt:
      pass