~ubuntu-branches/ubuntu/wily/system-config-printer/wily

« back to all changes in this revision

Viewing changes to newprinter.py

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2014-08-05 23:59:59 UTC
  • mfrom: (256.1.1 utopic-proposed)
  • Revision ID: package-import@ubuntu.com-20140805235959-v1yzis5mo1nkxo2m
Tags: 1.5.0+20140805-0ubuntu2
debian/control: Build-depend on Python 3 (python3-all-dev).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
 
1
#!/usr/bin/python3
2
2
 
3
3
## system-config-printer
4
4
 
28
28
import cupshelpers
29
29
 
30
30
import errno
31
 
import sys, os, tempfile, time, traceback, re, httplib
 
31
import sys, os, tempfile, time, traceback, re, http.client
32
32
import locale
33
33
import string
34
34
import subprocess
35
 
import thread
 
35
import _thread
36
36
from timedops import *
37
37
import dbus
38
38
from gi.repository import Gdk
39
39
from gi.repository import Gtk
40
40
import pycurl
 
41
import functools
41
42
# prefer Python 2 module here, as in Python 2 io.StringIO is broken
42
43
try:
43
 
    from cStringIO import StringIO
 
44
    from io import StringIO
44
45
except ImportError:
45
46
    from io import StringIO
46
47
 
59
60
from optionwidgets import OptionWidget
60
61
from debug import *
61
62
import probe_printer
62
 
import urllib
 
63
import urllib.request, urllib.parse
63
64
from smburi import SMBURI
64
65
from errordialogs import *
65
66
from PhysicalDevice import PhysicalDevice
69
70
import dnssdresolve
70
71
 
71
72
import gettext
72
 
gettext.install(domain=config.PACKAGE, localedir=config.localedir, unicode=True)
 
73
gettext.install(domain=config.PACKAGE, localedir=config.localedir)
73
74
 
74
75
 
75
76
TEXT_adjust_firewall = _("The firewall may need adjusting in order to "
78
79
 
79
80
def validDeviceURI (uri):
80
81
    """Returns True is the provided URI is valid."""
81
 
    (scheme, rest) = urllib.splittype (uri)
 
82
    (scheme, rest) = urllib.parse.splittype (uri)
82
83
    if scheme == None or scheme == '':
83
84
        return False
84
85
    return True
104
105
    iter = model.get_iter_first()
105
106
    result = []
106
107
    while iter:
107
 
        result.append(model.get(iter, 0)[0].decode ('utf-8'))
 
108
        result.append(model.get(iter, 0)[0])
108
109
        iter = model.iter_next(iter)
109
110
    result.sort()
110
111
    return result
111
112
 
112
113
def checkNPName(printers, name):
113
114
    if not name: return False
114
 
    name = unicode (name.lower())
 
115
    name = name.lower()
115
116
    for printer in printers.values():
116
117
        if not printer.discovered and printer.name.lower()==name:
117
118
            return False
257
258
        self._installdialog = None
258
259
 
259
260
        # Synchronisation objects.
260
 
        self.drivers_lock = thread.allocate_lock()
 
261
        self.drivers_lock = _thread.allocate_lock()
261
262
 
262
263
        self.getWidgets({"NewPrinterWindow":
263
264
                             ["NewPrinterWindow",
914
915
 
915
916
    def installdriverpackage (self, driver, onlycheckpresence = False):
916
917
        pkgs = driver.get('packages', {})
917
 
        arches = pkgs.keys()
 
918
        arches = list(pkgs.keys())
918
919
        if len(arches) == 0:
919
920
            debugprint('No packages for driver')
920
921
            return False
927
928
        if len(pkgs) != 1:
928
929
            debugprint('Returned more than one package, this is currently not handled')
929
930
            return False
930
 
        pkg = pkgs.keys()[0]
 
931
        pkg = list(pkgs.keys())[0]
931
932
 
932
933
        name = ''
933
934
        if pkg.endswith('.deb'):
1107
1108
                        else:
1108
1109
                            port = 631
1109
1110
                        try:
1110
 
                            conn = httplib.HTTPConnection(resg[0], port)
 
1111
                            conn = http.client.HTTPConnection(resg[0], port)
1111
1112
                            conn.request("GET", "/printers/%s.ppd" % resg[2])
1112
1113
                            resp = conn.getresponse()
1113
1114
                            if resp.status == 200:
1149
1150
                    treeview = self.tvNPDownloadableDrivers
1150
1151
                    model, iter = treeview.get_selection ().get_selected ()
1151
1152
                    driver = model.get_value (iter, 1)
1152
 
                    if driver != None and driver.has_key ('packages'):
 
1153
                    if driver != None and 'packages' in driver:
1153
1154
                        # Find the package name, repository, and fingerprint
1154
1155
                        # and install the package
1155
1156
                        if self.installdriverpackage (driver) and \
1242
1243
                                                     self.device.make_and_model)
1243
1244
                        debugprint ("Suitable PPDs found: %s" % repr(fit))
1244
1245
                        ppdnamelist = self.ppds.\
1245
 
                            orderPPDNamesByPreference (fit.keys (),
 
1246
                            orderPPDNamesByPreference (list(fit.keys ()),
1246
1247
                                                       self.installed_driver_files,
1247
1248
                                                       devid=id_dict, fit=fit)
1248
1249
                        debugprint ("PPDs in priority order: %s" % repr(ppdnamelist))
1264
1265
 
1265
1266
                            # Search for ppdname with that make-and-model
1266
1267
                            ppds = self.ppds.getInfoFromModel (make, model)
1267
 
                            for ppd, info in ppds.iteritems ():
 
1268
                            for ppd, info in ppds.items ():
1268
1269
                                if (_singleton (info.
1269
1270
                                                get ("ppd-make-and-model")) ==
1270
1271
                                    value):
1543
1544
            name = self.makeNameUnique (name)
1544
1545
            self.entNPName.set_text (name)
1545
1546
 
1546
 
            if self.entNPDescription.get_text () == '' and descr:
 
1547
            if descr:
1547
1548
                self.entNPDescription.set_text (descr)
1548
1549
 
1549
1550
        self.ntbkNewPrinter.set_current_page(next_page_nr)
1701
1702
 
1702
1703
    def on_entNPName_changed(self, widget):
1703
1704
        # restrict
1704
 
        text = unicode (widget.get_text(), 'utf-8')
 
1705
        text = widget.get_text()
1705
1706
        new_text = text
1706
1707
        new_text = new_text.replace("/", "")
1707
1708
        new_text = new_text.replace("#", "")
1766
1767
        # Add the network devices to the list.
1767
1768
        no_more = True
1768
1769
        need_resolving = {}
1769
 
        for uri, device in result.iteritems ():
 
1770
        for uri, device in result.items ():
1770
1771
            if uri.startswith ("dnssd://"):
1771
1772
                need_resolving[uri] = device
1772
1773
                no_more = False
1909
1910
 
1910
1911
            if stdout != None:
1911
1912
                line = stdout.strip ()
1912
 
                if isinstance(line, bytes):
1913
 
                    line = line.decode('utf-8', 'replace')
1914
1913
                words = probe_printer.wordsep (line)
1915
1914
                n = len (words)
1916
1915
                if n < 4:
2043
2042
 
2044
2043
    def add_devices (self, devices, current_uri, no_more=False):
2045
2044
        if current_uri:
2046
 
            if devices.has_key (current_uri):
 
2045
            if current_uri in devices:
2047
2046
                current = devices.pop(current_uri)
2048
 
            elif devices.has_key (current_uri.replace (":9100", "")):
 
2047
            elif current_uri.replace (":9100", "") in devices:
2049
2048
                current_uri = current_uri.replace (":9100", "")
2050
2049
                current = devices.pop(current_uri)
2051
2050
            elif no_more:
2054
2053
            else:
2055
2054
                current_uri = None
2056
2055
 
2057
 
        devices = devices.values()
 
2056
        devices = list(devices.values())
2058
2057
 
2059
2058
        for device in devices:
2060
2059
            if device.type == "socket":
2069
2068
                device.uri = "hpfax"
2070
2069
            return device
2071
2070
 
2072
 
        devices = map (replace_generic, devices)
 
2071
        devices = list(map (replace_generic, devices))
2073
2072
 
2074
2073
        # Mark duplicate URIs for deletion
2075
2074
        for i in range (len (devices) - 1):
2088
2087
                        device1.uri = "delete"
2089
2088
                    else:
2090
2089
                        device2.uri = "delete"
2091
 
        devices = filter(lambda x: x.uri not in ("hp", "hpfax",
 
2090
        devices = [x for x in devices if x.uri not in ("hp", "hpfax",
2092
2091
                                                 "hal", "beh",
2093
 
                                                 "scsi", "http", "delete"),
2094
 
                         devices)
 
2092
                                                 "scsi", "http", "delete")]
2095
2093
        newdevices = []
2096
2094
        for device in devices:
2097
2095
            physicaldevice = PhysicalDevice (device)
2532
2530
                    pass
2533
2531
 
2534
2532
                f = ctx.open ("smb://%s/%s" % (host, share),
2535
 
                              os.O_RDWR, 0777)
 
2533
                              os.O_RDWR, 0o777)
2536
2534
                accessible = True
2537
2535
            else:
2538
2536
                # May need to prompt.
2545
2543
                while smbc_auth.perform_authentication () > 0:
2546
2544
                    try:
2547
2545
                        f = ctx.open ("smb://%s/%s" % (host, share),
2548
 
                                      os.O_RDWR, 0777)
 
2546
                                      os.O_RDWR, 0o777)
2549
2547
                        accessible = True
2550
2548
                    except Exception as e:
2551
2549
                        smbc_auth.failed (e)
2575
2573
 
2576
2574
    def entry_changed(self, entry, allowed_chars):
2577
2575
        "Remove all chars from entry's text that are not in allowed_chars."
2578
 
        try:
2579
 
            allowed_chars = unicode (allowed_chars, 'utf-8')
2580
 
        except UnicodeDecodeError:
2581
 
            allowed_chars = unicode (allowed_chars)
2582
 
        origtext = unicode (entry.get_text(), 'utf-8')
 
2576
        origtext = entry.get_text()
2583
2577
        new_text = origtext
2584
2578
        for char in origtext:
2585
2579
            if char not in allowed_chars:
2693
2687
        physicaldevice = model.get_value (iter, 1)
2694
2688
        if physicaldevice == None:
2695
2689
            return
 
2690
        show_uris = True
2696
2691
        for device in physicaldevice.get_devices ():
2697
2692
            if device.type == "parallel":
2698
2693
                device.menuentry = _("Parallel Port")
2712
2707
            elif device.type == "socket":
2713
2708
                device.menuentry = _("AppSocket/HP JetDirect")
2714
2709
            elif device.type == "lpd":
2715
 
                (scheme, rest) = urllib.splittype (device.uri)
2716
 
                (hostport, rest) = urllib.splithost (rest)
2717
 
                (queue, rest) = urllib.splitquery (rest)
 
2710
                (scheme, rest) = urllib.parse.splittype (device.uri)
 
2711
                (hostport, rest) = urllib.parse.splithost (rest)
 
2712
                (queue, rest) = urllib.parse.splitquery (rest)
2718
2713
                if queue != '':
2719
2714
                    if queue[0] == '/':
2720
2715
                        queue = queue[1:]
2727
2722
            elif device.type == "smb":
2728
2723
                device.menuentry = _("Windows Printer via SAMBA")
2729
2724
            elif device.type == "ipp":
2730
 
                (scheme, rest) = urllib.splittype (device.uri)
2731
 
                (hostport, rest) = urllib.splithost (rest)
2732
 
                (queue, rest) = urllib.splitquery (rest)
 
2725
                (scheme, rest) = urllib.parse.splittype (device.uri)
 
2726
                (hostport, rest) = urllib.parse.splithost (rest)
 
2727
                (queue, rest) = urllib.parse.splitquery (rest)
2733
2728
                if queue != '':
2734
2729
                    if queue[0] == '/':
2735
2730
                        queue = queue[1:]
2742
2737
            elif device.type == "http" or device.type == "https":
2743
2738
                device.menuentry = _("HTTP")
2744
2739
            elif device.type == "dnssd" or device.type == "mdns":
2745
 
                (scheme, rest) = urllib.splittype (device.uri)
2746
 
                (name, rest) = urllib.splithost (rest)
2747
 
                (cupsqueue, rest) = urllib.splitquery (rest)
 
2740
                (scheme, rest) = urllib.parse.splittype (device.uri)
 
2741
                (name, rest) = urllib.parse.splithost (rest)
 
2742
                (cupsqueue, rest) = urllib.parse.splitquery (rest)
2748
2743
                if cupsqueue != '' and cupsqueue[0] == '/':
2749
2744
                    cupsqueue = cupsqueue[1:]
2750
2745
                if cupsqueue == 'cups':
2751
2746
                    device.menuentry = _("Remote CUPS printer via DNS-SD")
2752
2747
                    if device.info != '':
2753
 
                         device.menuentry += " (%s)" % device.info
 
2748
                        device.menuentry += " (%s)" % device.info
2754
2749
                else:
2755
2750
                    protocol = None
2756
2751
                    if name.find("._ipp") != -1:
2766
2761
                        device.menuentry = \
2767
2762
                            _("Network printer via DNS-SD")
2768
2763
            else:
 
2764
                show_uris = False
2769
2765
                device.menuentry = device.uri
2770
2766
 
2771
2767
        model = Gtk.ListStore (str,                    # URI description
2795
2791
                elif device.type in ["socket", "lpd", "ipp", "dnssd", "mdns"]:
2796
2792
                    # This is a network printer.
2797
2793
                    if host == None and device.type in ["socket", "lpd", "ipp"]:
2798
 
                        (scheme, rest) = urllib.splittype (device.uri)
2799
 
                        (hostport, rest) = urllib.splithost (rest)
 
2794
                        (scheme, rest) = urllib.parse.splittype (device.uri)
 
2795
                        (hostport, rest) = urllib.parse.splithost (rest)
2800
2796
                        if hostport != None:
2801
 
                            (host, port) = urllib.splitport (hostport)
 
2797
                            (host, port) = urllib.parse.splitport (hostport)
2802
2798
                    if host:
2803
2799
                        is_network = True
2804
2800
                        remotecups = ((device.uri.startswith('dnssd:') or \
2857
2853
            n += 1
2858
2854
        column = self.tvNPDeviceURIs.get_column (0)
2859
2855
        self.tvNPDeviceURIs.set_cursor (Gtk.TreePath(), column, False)
2860
 
        if n > 1:
 
2856
        if show_uris:
2861
2857
            self.expNPDeviceURIs.show_all ()
2862
2858
        else:
2863
2859
            self.expNPDeviceURIs.hide ()
2897
2893
                text = _("Local printer detected by the "
2898
2894
                         "Hardware Abstraction Layer (HAL).")
2899
2895
            elif device.type == "dnssd" or device.type == "mdns":
2900
 
                (scheme, rest) = urllib.splittype (device.uri)
2901
 
                (name, rest) = urllib.splithost (rest)
2902
 
                (cupsqueue, rest) = urllib.splitquery (rest)
 
2896
                (scheme, rest) = urllib.parse.splittype (device.uri)
 
2897
                (name, rest) = urllib.parse.splithost (rest)
 
2898
                (cupsqueue, rest) = urllib.parse.splitquery (rest)
2903
2899
                if cupsqueue != '' and cupsqueue[0] == '/':
2904
2900
                    cupsqueue = cupsqueue[1:]
2905
2901
                if cupsqueue == 'cups':
2921
2917
 
2922
2918
            self.lblNPDeviceDescription.set_text (text)
2923
2919
        elif device.type=="socket":
2924
 
            (scheme, rest) = urllib.splittype (device.uri)
 
2920
            (scheme, rest) = urllib.parse.splittype (device.uri)
2925
2921
            host = ''
2926
2922
            port = 9100
2927
2923
            if scheme == "socket":
2928
 
                (hostport, rest) = urllib.splithost (rest)
2929
 
                (host, port) = urllib.splitnport (hostport, defport=port)
 
2924
                (hostport, rest) = urllib.parse.splithost (rest)
 
2925
                (host, port) = urllib.parse.splitnport (hostport, defport=port)
2930
2926
                debugprint ("socket: host is %s, port is %s" % (host,
2931
2927
                                                                repr (port)))
2932
2928
                if device.location != '':
2949
2945
                    (self.cmbNPTSerialBits, "bits"),
2950
2946
                    (self.cmbNPTSerialParity, "parity"),
2951
2947
                    (self.cmbNPTSerialFlow, "flow")):
2952
 
                    if option_dict.has_key(name): # option given in URI?
 
2948
                    if name in option_dict: # option given in URI?
2953
2949
                        model = widget.get_model()
2954
2950
                        iter = model.get_iter_first()
2955
2951
                        nr = 0
2956
2952
                        while iter:
2957
2953
                            value = model.get(iter,1)[0]
2958
 
                            if unicode (value) == unicode (option_dict[name]):
 
2954
                            if str (value) == str (option_dict[name]):
2959
2955
                                break
2960
2956
                            iter = model.iter_next(iter)
2961
2957
                            nr += 1
3259
3255
    def openprinting_printers_found (self, status, user_data, printers):
3260
3256
        if status != 0:
3261
3257
            # Should report error.
3262
 
            print "HTTP Status %d" % status
3263
 
            print printers
3264
 
            print traceback.extract_tb(printers[2], limit=None)
 
3258
            print("HTTP Status %d" % status)
 
3259
            print(printers)
 
3260
            print(traceback.extract_tb(printers[2], limit=None))
3265
3261
            self.downloadable_printers = []
3266
3262
            self.openprinting_drivers_found ()
3267
3263
            return
3268
3264
 
3269
3265
        self.openprinting_query_handle = None
3270
 
        self.downloadable_printers_unchecked = map (lambda x:
3271
 
                                                        (x, printers[x]),
3272
 
                                                    printers)
 
3266
        self.downloadable_printers_unchecked = [(x, printers[x]) for x in printers]
3273
3267
        self.downloadable_printers = []
3274
3268
        self.downloadable_drivers = dict() # by printer id of dict
3275
3269
 
3316
3310
    def openprinting_printer_drivers_found (self, status, user_data, drivers):
3317
3311
        self.openprinting_query_handle = None
3318
3312
        if status != 0:
3319
 
            print "HTTP Status %d" % status
3320
 
            print drivers
3321
 
            print traceback.extract_tb(drivers[2], limit=None)
 
3313
            print("HTTP Status %d" % status)
 
3314
            print(drivers)
 
3315
            print(traceback.extract_tb(drivers[2], limit=None))
3322
3316
            self.downloadable_printers = []
3323
3317
            self.openprinting_drivers_found ()
3324
3318
            return
3327
3321
            debugprint (" - drivers found")
3328
3322
            for driverkey in drivers.keys ():
3329
3323
                driver = drivers[driverkey]
3330
 
                if ((not driver.has_key ('ppds') or
 
3324
                if (('ppds' not in driver or
3331
3325
                     len(driver['ppds']) <= 0) and
3332
3326
                    (self.DOWNLOADABLE_ONLYPPD or
3333
3327
                     (not self.installdriverpackage (driver,
3369
3363
            for printer_id, printer_name in self.downloadable_printers:
3370
3364
                sorted_list.append ((printer_id, printer_name))
3371
3365
 
3372
 
            sorted_list.sort (lambda x, y: cups.modelSort (x[1], y[1]))
 
3366
            sorted_list.sort (key=functools.cmp_to_key(lambda x, y: cups.modelSort (x[1], y[1])))
3373
3367
            sought = self.entNPDownloadableDriverSearch.get_text ().lower ()
3374
3368
            select_index = 0
3375
3369
            for id, name in sorted_list:
3584
3578
            # driver preference list.
3585
3579
            make_and_model = pmake + " " + pmodel
3586
3580
            ppds = self.ppds.getInfoFromModel(pmake, pmodel)
3587
 
            ppdnames = ppds.keys ()
 
3581
            ppdnames = list(ppds.keys ())
3588
3582
 
3589
3583
            files = self.installed_driver_files
3590
3584
            try:
3752
3746
            hs = self.__dict__.get ("hsDownloadableDriverPerf%s" % field)
3753
3747
            unknown = self.__dict__.get ("lblDownloadableDriverPerf%sUnknown"
3754
3748
                                         % field)
3755
 
            if functionality.has_key (key):
 
3749
            if key in functionality:
3756
3750
                if hs:
3757
3751
                    try:
3758
3752
                        value = int (functionality[key])
3767
3761
                hs.hide ()
3768
3762
                unknown.show_all ()
3769
3763
        supportcontacts = ""
3770
 
        if driver.has_key ('supportcontacts'):
 
3764
        if 'supportcontacts' in driver:
3771
3765
            for supportentry in driver['supportcontacts']:
3772
3766
                if supportentry['name']:
3773
3767
                    supportcontact = " - " + supportentry['name']
3789
3783
        if not supportcontacts:
3790
3784
            supportcontacts = _("No support contacts known")
3791
3785
        self.lblNPDownloadableDriverSupportContacts.set_text (supportcontacts)
3792
 
        if driver.has_key ('licensetext'):
 
3786
        if 'licensetext' in driver:
3793
3787
            self.frmNPDownloadableDriverLicenseTerms.show ()
3794
3788
            terms = driver.get('licensetext', _("Not specified."))
3795
3789
            self.tvNPDownloadableDriverLicense.get_buffer ().set_text (terms)
3807
3801
            terms = driver.get('licensetext', _("Not specified."))
3808
3802
            self.tvNPDownloadableDriverLicense.get_buffer ().set_text (terms)
3809
3803
 
3810
 
        if driver.has_key('ppds') and len(driver["ppds"]) > 0:
 
3804
        if 'ppds' in driver and len(driver["ppds"]) > 0:
3811
3805
            self.founddownloadableppd = True
3812
3806
        else:
3813
3807
            self.founddownloadableppd = False
3830
3824
                treeview = self.tvNPDownloadableDrivers
3831
3825
                model, iter = treeview.get_selection ().get_selected ()
3832
3826
                driver = model.get_value (iter, 1)
3833
 
                if driver != 0 and driver.has_key ('ppds'):
 
3827
                if driver != 0 and 'ppds' in driver:
3834
3828
                    # Only need to download a PPD.
3835
3829
                    if (len(driver['ppds']) > 0):
3836
3830
                        file_to_download = driver['ppds'][0]
3837
3831
                        debugprint ("ppd file to download [" + file_to_download+ "]")
3838
3832
                        file_to_download = file_to_download.strip()
3839
3833
                        if (len(file_to_download) > 0):
3840
 
                            ppdurlobj = urllib.urlopen(file_to_download)
 
3834
                            ppdurlobj = urllib.request.urlopen(file_to_download)
3841
3835
                            ppdcontent = ppdurlobj.read()
3842
3836
                            ppdurlobj.close()
3843
3837
                            (tmpfd, ppdname) = tempfile.mkstemp()
3844
3838
                            debugprint(ppdname)
3845
 
                            ppdfile = os.fdopen(tmpfd, 'w')
 
3839
                            ppdfile = os.fdopen(tmpfd, 'wb')
3846
3840
                            ppdfile.write(ppdcontent)
3847
3841
                            ppdfile.close()
3848
3842
                            ppd = cups.PPD(ppdname)
3884
3878
                                          stdout=subprocess.PIPE,
3885
3879
                                          stderr=subprocess.PIPE)
3886
3880
                    (stdout, stderr) = p.communicate ()
3887
 
                    # TODO: remove the decode() after merging python3 branch
3888
 
                    err += stdout.decode ('utf-8', 'replace')
 
3881
                    err += stdout
3889
3882
                except:
3890
3883
                    # Problem executing command.
3891
3884
                    raise
3899
3892
 
3900
3893
        debugprint("ppd: " + repr(ppd))
3901
3894
 
3902
 
        if isinstance(ppd, str) or isinstance(ppd, unicode):
 
3895
        if isinstance(ppd, str):
3903
3896
            self.cups._begin_operation (_("fetching PPD"))
3904
3897
            try:
3905
3898
                if ppd != "raw":
3990
3983
            self.dec_spinner_task ()
3991
3984
 
3992
3985
        if self.dialog_mode in ("class", "printer", "printer_with_uri"):
3993
 
            name = unicode (self.entNPName.get_text(), 'utf-8')
3994
 
            location = unicode (self.entNPLocation.get_text(), 'utf-8')
3995
 
            info = unicode (self.entNPDescription.get_text(), 'utf-8')
 
3986
            name = self.entNPName.get_text()
 
3987
            location = self.entNPLocation.get_text()
 
3988
            info = self.entNPDescription.get_text()
3996
3989
        else:
3997
3990
            name = self._name
3998
3991
 
4024
4017
                return
4025
4018
 
4026
4019
            # write Installable Options to ppd
4027
 
            for option in self.options.itervalues():
 
4020
            for option in self.options.values():
4028
4021
                option.writeback()
4029
4022
 
4030
4023
            busy (self.NewPrinterWindow)
4032
4025
                Gtk.main_iteration ()
4033
4026
            self.cups._begin_operation (_("adding printer %s") % name)
4034
4027
            try:
4035
 
                if isinstance(ppd, str) or isinstance(ppd, unicode):
 
4028
                if isinstance(ppd, str):
4036
4029
                    self.cups.addPrinter(name, ppdname=ppd,
4037
4030
                         device=uri, info=info, location=location)
4038
4031
                elif ppd is None: # raw queue
4093
4086
            # set ppd on server and retrieve it
4094
4087
            # cups doesn't offer a way to just download a ppd ;(=
4095
4088
            raw = False
4096
 
            if isinstance(ppd, str) or isinstance(ppd, unicode):
 
4089
            if isinstance(ppd, str):
4097
4090
                if self.rbtnChangePPDasIs.get_active():
4098
4091
                    # To use the PPD as-is we need to prevent CUPS copying
4099
4092
                    # the old options over.  Do this by setting it to a
4132
4125
                    cupshelpers.setPPDPageSize(ppd, self.language[0])
4133
4126
 
4134
4127
                # write Installable Options to ppd
4135
 
                for option in self.options.itervalues():
 
4128
                for option in self.options.values():
4136
4129
                    option.writeback()
4137
4130
 
4138
4131
                try: