Created
May 15, 2015 19:44
-
-
Save nmcspadden/a419187b103ce2afe47f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import subprocess | |
import sys | |
printerName = "PRINTERNAME" | |
printerOptions = { "HPOption_Duplexer":"False", | |
"HPOption_500_Sheet_Feeder_Tray3":"False" } | |
# Only lpoptions needs to be checked - if the printer doesn't exist, lpoptions will fail anyway. | |
cmd = ['/usr/bin/lpoptions', '-p', printerName, '-l'] | |
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
(lpoptOut, lpoptErr) = proc.communicate() | |
if lpoptErr: | |
sys.exit(0) | |
for option in lpoptOut.splitlines(): | |
for myOption in printerOptions.keys(): | |
optionName = option.split("/", 1)[0] | |
optionValues = option.split("/",1)[1].split(":")[1].strip().split(" ") | |
for opt in optionValues: | |
if "*" in opt: | |
actualOptionValue = opt.replace('*', '') | |
break | |
if optionName == myOption: | |
if not printerOptions[myOption] == actualOptionValue: | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment