Skip to content

Commit 45df1ef

Browse files
committed
Updated "PrinterGenerator" for deployment with munki-python (successfully tested with python 3.9 on macOS 10.14 & 10.15). May not work on macOS 11 since cups shows a deprecation warning.
Deprecation warning will be catched on english and german macOS 10.15.
1 parent f1eb72c commit 45df1ef

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

AddPrinter-Template.plist

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
<key>display_name</key>
1414
<string>DISPLAY_NAME</string>
1515
<key>installcheck_script</key>
16-
<string>#!/usr/bin/python
16+
<string>#!/usr/local/munki/munki-python
1717
import subprocess
1818
import sys
1919
import shlex
2020
2121
printerOptions = { OPTIONS }
2222
2323
cmd = ['/usr/bin/lpoptions', '-p', 'PRINTERNAME', '-l']
24-
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
24+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
2525
(lpoptLongOut, lpoptErr) = proc.communicate()
2626
2727
# lpoptions -p printername -l will still exit 0 even if printername does not exist
@@ -51,6 +51,11 @@ for option in lpoptLongOut.splitlines():
5151
print("Found mismatch: %s is '%s', should be '%s'" % (myOption, printerOptions[myOption], actualOptionValue))
5252
sys.exit(0)
5353
54+
try:
55+
lpoptOut = lpoptOut.decode("utf-8")
56+
except UnicodeDecodeError:
57+
sys.exit(0)
58+
5459
optionDict = {}
5560
for builtOption in shlex.split(lpoptOut):
5661
try:
@@ -66,23 +71,24 @@ for keyName in comparisonDict.keys():
6671
print("Settings mismatch: %s is '%s', should be '%s'" % (keyName, optionDict[keyName], comparisonDict[keyName]))
6772
sys.exit(0)
6873
69-
sys.exit(1)</string>
74+
sys.exit(1)
75+
</string>
7076
<key>installer_type</key>
7177
<string>nopkg</string>
7278
<key>minimum_os_version</key>
7379
<string>10.7.0</string>
7480
<key>name</key>
7581
<string>AddPrinter_DISPLAYNAME</string>
7682
<key>postinstall_script</key>
77-
<string>#!/usr/bin/python
83+
<string>#!/usr/local/munki/munki-python
7884
import subprocess
7985
import sys
8086
8187
# Populate these options if you want to set specific options for the printer. E.g. duplexing installed, etc.
8288
printerOptions = { OPTIONS }
8389
8490
cmd = [ '/usr/sbin/lpadmin', '-x', 'PRINTERNAME' ]
85-
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
91+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
8692
(lpadminxOut, lpadminxErr) = proc.communicate()
8793
8894
# Install the printer
@@ -100,19 +106,19 @@ for option in printerOptions.keys():
100106
cmd.append("-o")
101107
cmd.append(str(option) + "=" + str(printerOptions[option]))
102108
103-
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
109+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
104110
(lpadminOut, lpadminErr) = proc.communicate()
105111
106112
if lpadminErr:
107-
if "Printer drivers are deprecated" in lpadminErr:
113+
if "Printer drivers are deprecated" in lpadminErr or "Reine Wartelisten wurden verworfen" in lpadminErr:
108114
# work around lpadmin deprecation message
109-
print "Install successful - caught deprecation message; preventing exit 1"
110-
pass
115+
print("Install successful - caught deprecation message; preventing exit 1")
111116
else:
112-
print "Error: %s" % lpadminErr
117+
print("Error: %s" % lpadminErr)
113118
sys.exit(1)
114119
print("Results: %s" % lpadminOut)
115-
sys.exit(0)</string>
120+
sys.exit(0)
121+
</string>
116122
<key>unattended_install</key>
117123
<true/>
118124
<key>uninstall_method</key>

0 commit comments

Comments
 (0)