Skip to content

Instantly share code, notes, and snippets.

@rickheil
Last active September 17, 2016 12:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickheil/d4fb9b58c3c75505ebf7e2d7d41a27b2 to your computer and use it in GitHub Desktop.
Save rickheil/d4fb9b58c3c75505ebf7e2d7d41a27b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
"""Formats lpoptions output to PrinterGenerator input"""
import sys
import subprocess
def main():
subproc = subprocess.Popen(['lpoptions', '-p', sys.argv[1], '-l'], stdout=subprocess.PIPE)
out, err = subproc.communicate()
printer_options = out.splitlines(True)
options_output = ""
for line in printer_options:
line = line.split(' ')
option_name = line[0].split('/')[0]
for option in line:
if '*' in option:
selected_option = option[1:]
options_output += "%s=%s " % (option_name, selected_option)
print options_output.replace("\n", "")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment