Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmcspadden/a419187b103ce2afe47f to your computer and use it in GitHub Desktop.
Save nmcspadden/a419187b103ce2afe47f to your computer and use it in GitHub Desktop.
#!/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