Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/puppet/provider/printer/cups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,13 @@ def self.printers_long
# NOTE: single quotation marks in option values are not escaped. So this makes things very difficult to parse.
def self.printer_options(destination, resource)
options = {}
return options unless resource[:options]

# I'm using shellsplit here from the ruby std lib to avoid having to write a quoted string parser.
Shellwords.shellwords(lpoptions('-p', destination)).each do |kv|
values = kv.split('=')
next if Immutable_Option_Blacklist.include? values[0]
next unless resource.nil? or resource[:options].include? values[0]
next unless resource[:options].include? values[0]

options[values[0]] = values[1]
end
Expand All @@ -239,10 +240,12 @@ def self.printer_options(destination, resource)
# If something other than the default is selected, it turns up in lpoptions -p
def self.ppd_options(destination, resource)
ppdopts = {}
return ppdopts unless resource[:ppd_options]

lpoptions('-p', destination, '-l').each_line do |line|
keyvalues = line.split(':')
key = /^([^\/]*)/.match(keyvalues[0]).captures[0]
next unless resource[:ppd_options].include? key

selected_value = /\s\*([^\s]*)\s/.match(keyvalues[1]).captures[0]

Expand Down