Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

started fleshing out the printer options provider.

  • Loading branch information...
commit 41c9a75fac393456f7fdb777f08be2d8f4ceb8dc 1 parent 8fa4a2b
mosen authored
View
2  lib/puppet/provider/printer/cups.rb
@@ -17,8 +17,6 @@
have taken effect. This will be addressed in future versions of the provider.
"
- include Puppet::Util::Warnings
-
commands :lpadmin => "/usr/sbin/lpadmin"
commands :lpoptions => "/usr/bin/lpoptions"
#commands :lpinfo => "/usr/sbin/lpinfo"
View
56 lib/puppet/provider/printer/cups_options.rb
@@ -1,3 +1,5 @@
+require 'shellwords'
+
Puppet::Type.type(:printer_defaults).provide :cups_options, :parent => Puppet::Provider do
desc "This provider manages default printer options by executing lpoptions(1) as the root user.
@@ -5,41 +7,61 @@
Note: On Mac OS X the default lpoptions do not correlate with the print dialog. The default printer and default media
are selected by ~/Library/Preferences/com.apple.print.PrintingPrefs.plist (10.6) and submitted with the job options.
-
-
"
commands :lpoptions => "/usr/bin/lpoptions"
- commands :lpinfo => "/usr/sbin/lpinfo"
+ #commands :lpinfo => "/usr/sbin/lpinfo"
- class << self
- # Retrieve options including whether the printer destination is shared.
- def printer_options(destination)
- options = {}
+ # Retrieve options including whether the printer destination is shared.
+ def self.printer_options(destination = nil)
+ options = {}
- # I'm using shellsplit here from the ruby std lib to avoid having to write a quoted string parser.
- lpoptions('-d', destination).shellsplit.each do |kv|
- values = kv.split('=')
- options[values[0]] = values[1]
- end
+ if destination.nil?
+ output = lpoptions
+ else
+ output = lpoptions('-d', destination)
+ end
- options
+ # I'm using shellsplit here from the ruby std lib to avoid having to write a quoted string parser.
+ output.shellsplit.each do |kv|
+ values = kv.split('=')
+ options[values[0]] = values[1]
end
- def prefetch(resources)
+ options
+ end
+
+ # Combine output of a number of commands to form a list of printer resources.
+ def self.instances
+ prefetched_options = self.printer_options().each_pair { |k, v|
+ new({
+ :name => k,
+ :value => v,
+ :provider => :cups_options
+ })
+ }
+
+ prefetched_options
+ end
+ def self.prefetch(resources)
+ instances.each do |prov|
+ if resource = resources[prov.name]
+ resource.provider = prov
+ end
end
end
def create
-
+ lpoptions '-o', '%s=%s' % @resource[:name], @resource[:value]
end
def destroy
-
+ lpoptions '-r', @resource[:name]
end
def exists?
-
+ puts 'exists option?'
+ self.printer_options().key? @resource[:name]
end
end
View
6 lib/puppet/type/printer_defaults.rb
@@ -1,9 +1,5 @@
Puppet::Type.newtype(:printer_defaults) do
- @doc = "Sets the global defaults for all printers on the system.
-
- The separation of printer resources from the global printer defaults resolves the issue of declaring multiple printers
- as 'default'. All defaults are set through this resource instead of the individual printer resource.
- "
+ @doc = "Sets the global defaults for all printers on the system."
ensurable
View
22 spec/unit/provider/cups_spec.rb
@@ -16,34 +16,22 @@
Puppet::Type::Printer.stubs(:defaultprovider).returns provider
provider.stubs(:command).with(:lpadmin).returns "/usr/sbin/lpadmin"
- provider.stubs(:command).with(:lpoptions).returns "/usr/sbin/lpoptions"
+ provider.stubs(:command).with(:lpoptions).returns "/usr/bin/lpoptions"
provider.stubs(:command).with(:lpinfo).returns "/usr/sbin/lpinfo"
- provider.stubs(:command).with(:lpstat).returns "/usr/sbin/lpstat"
+ provider.stubs(:command).with(:lpstat).returns "/usr/bin/lpstat"
provider.stubs(:command).with(:cupsenable).returns "/usr/sbin/cupsenable"
provider.stubs(:command).with(:cupsdisable).returns "/usr/sbin/cupsdisable"
provider.stubs(:command).with(:cupsaccept).returns "/usr/sbin/cupsaccept"
provider.stubs(:command).with(:cupsreject).returns "/usr/sbin/cupsreject"
-
end
it 'should be able to get a list of existing printers' do
- provider.expects(:execute).with(['/usr/sbin/lpadmin']).returns("")
- provider.expects(:execute).with(['/usr/sbin/lpoptions']).returns("")
- provider.expects(:execute).with(['/usr/sbin/lpinfo']).returns("")
- provider.expects(:execute).with(['/usr/sbin/lpstat']).returns("")
-
- provider.expects(:execute).with(['/usr/sbin/cupsenable']).returns("")
- provider.expects(:execute).with(['/usr/sbin/cupsdisable']).returns("")
-
- provider.expects(:execute).with(['/usr/sbin/cupsaccept']).returns("")
- provider.expects(:execute).with(['/usr/sbin/cupsreject']).returns("")
- # BUG: for whatever reason RSpec doesn't recognise the cups provider as having an instances method.
- provider.instances.each do |p|
- p.should be_instance_of(provider)
- p.properties[:provider].to_s.should == provider.name.to_s
+ provider.instances.each do |printer|
+ printer.should be_instance_of(provider)
+ printer.get(:provider).to_s.should == provider.name.to_s
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.