Commits

Mark Roddy committed 7f076f5

initial commit

  • Participants

Comments (0)

Files changed (4)

+Description
+===========
+The ```gsettings``` resource can be used for manipulation of Gnome configuration settings 
+via the gsettings configuration tool added in Gnome v3.
+
+Usage
+=====
+
+    gsettings "org.gnome.desktop.interface" do
+      option "monospace-font-name"
+      value "Monospace 14"
+      user "bob"
+    end
+
+* schema - used as the name attribute above, the dotted notation schema that contains the 
+attribute
+* option - the key being set with a new value
+* value - the new value for the key, this should be a pure ruby type. the gsettings resource 
+will automatically marshal the value into the GVariant format required by the underlying
+gsettings command line tool
+* user - User name for whom the setting applies to, should be a valid account on the system.
+
+Examples
+========
+
+Swap Ctrl and Caps Lock key
+---------------------------
+
+    gsettings "org.gnome.libgnomekbd.keyboard" do
+      option "options"
+      user "bob"
+      value ["ctrl\tctrl:nocaps"]
+    end
+
+
+License and Author
+==================
+
+Author:: Mark Roddy (<markroddy a t gmail d-o-t com>)
+
+Copyright:: 2012, Mark Roddy
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+maintainer       "Mark Roddy"
+maintainer_email "^^ at gmail"
+license          "apache"
+description      "Configure Gnome via gsettings"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version          "0.0.1"

File providers/default.rb

+
+# Coerces the ruby type into a string that can
+# be passed to gsettings via the command line
+def format_value_for_commandline(v)
+  if v.kind_of?(String)
+    # It's a hard coded string value, user already did the
+    # formatting so pass it along to the command
+    return "'#{v}'"
+  elsif v.kind_of?(Array)
+    return '"[\'' + v.join("', '") + '\']"'
+  else
+    v = v.to_s
+    return "'#{v}'"
+  end
+end
+
+action :set do
+  value = format_value_for_commandline(new_resource.value)
+  cmd = "dbus-launch gsettings set #{new_resource.schema} #{new_resource.option} #{value}"
+  execute "Updating gsetting config #{new_resource.schema} #{new_resource.option}" do
+    command cmd
+    user new_resource.user
+  end
+end
+
+action :reset do
+  if new_resource.recursive then
+    cmd = "dbus-launch gsettings reset-recursively #{new_resource.schema}"
+    cmd_name = "Recursively unsetting gsettings key '#{new_resource.schema}'"
+  else
+    schema = new_resource.schema
+    key = new_resource.option
+    cmd = "dbus-launch gsettings reset-recursively #{schema} #{key}"
+    cmd_mame = "Unsetting gsettings key '#{new_resource.key}'"
+  end
+  execute cmd_name do
+    command cmd
+    user new_resource.user
+  end
+end

File resources/default.rb

+actions :set, :reset
+
+default_action :set
+# Covers 0.10.8 and earlier
+def initialize(*args)
+  super
+  @action = :set
+end
+
+attribute :schema, :kind_of => String, :name_attribute => true
+attribute :option, :kind_of => String, :required => true
+attribute :value,  :required => true
+attribute :user, :kind_of => String, :required => true
+attribute :recursive, :kind_of => [TrueClass, FalseClass], :default => false