From 656928f9741a8a4b02b960ae99601c9d4a09e1f5 Mon Sep 17 00:00:00 2001 From: Chris Edester Date: Tue, 2 Dec 2014 18:19:25 -0500 Subject: [PATCH] Handle case of not setting options; do not return options we don't set --- lib/puppet/provider/printer/cups.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/printer/cups.rb b/lib/puppet/provider/printer/cups.rb index 8510d4b..567884c 100644 --- a/lib/puppet/provider/printer/cups.rb +++ b/lib/puppet/provider/printer/cups.rb @@ -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 @@ -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]