class Chef::Resource::WindowsFont

Public Instance Methods

del_cookbook_font() click to toggle source

delete the temp cookbook file

# File lib/chef/resource/windows_font.rb, line 73
def del_cookbook_font
  file Chef::Util::PathHelper.join(ENV["TEMP"], new_resource.font_name) do
    action :delete
  end
end
font_exists?() click to toggle source

Check to see if the font is installed in the fonts dir

@return [Boolean] Is the font is installed?

# File lib/chef/resource/windows_font.rb, line 92
def font_exists?
  require "win32ole" if RUBY_PLATFORM =~ /mswin|mingw32|windows/
  fonts_dir = WIN32OLE.new("WScript.Shell").SpecialFolders("Fonts")
  logger.trace("Seeing if the font at #{Chef::Util::PathHelper.join(fonts_dir, new_resource.font_name)} exists")
  ::File.exist?(Chef::Util::PathHelper.join(fonts_dir, new_resource.font_name))
end
install_font() click to toggle source

install the font into the appropriate fonts directory

# File lib/chef/resource/windows_font.rb, line 80
def install_font
  require "win32ole" if RUBY_PLATFORM =~ /mswin|mingw32|windows/
  fonts_dir = Chef::Util::PathHelper.join(ENV["windir"], "fonts")
  folder = WIN32OLE.new("Shell.Application").Namespace(fonts_dir)
  converge_by("install font #{new_resource.font_name} to #{fonts_dir}") do
    folder.CopyHere(Chef::Util::PathHelper.join(ENV["TEMP"], new_resource.font_name))
  end
end
remote_file_schema?(schema) click to toggle source

Parse out the schema provided to us to see if it's one we support via remote_file. We do this because URI will parse C:/foo as schema 'c', which won't work with remote_file

@return [Boolean]

# File lib/chef/resource/windows_font.rb, line 103
def remote_file_schema?(schema)
  return true if %w{http https ftp}.include?(schema)
end
retrieve_cookbook_font() click to toggle source

if a source is specified fetch using remote_file. If not use cookbook_file

# File lib/chef/resource/windows_font.rb, line 55
def retrieve_cookbook_font
  font_file = new_resource.font_name
  if new_resource.source
    declare_resource(:remote_file, font_file) do
      action :nothing
      source source_uri
      path Chef::Util::PathHelper.join(ENV["TEMP"], font_file)
    end.run_action(:create)
  else
    declare_resource(:cookbook_file, font_file) do
      action    :nothing
      cookbook  cookbook_name.to_s unless cookbook_name.nil?
      path      Chef::Util::PathHelper.join(ENV["TEMP"], font_file)
    end.run_action(:create)
  end
end
source_uri() click to toggle source

return new_resource.source if we have a proper URI specified if it's a local file listed as a source return it in file:// format

@return [String] path to the font

# File lib/chef/resource/windows_font.rb, line 111
def source_uri
  begin
    require "uri"
    if remote_file_schema?(URI.parse(new_resource.source).scheme)
      logger.trace("source property starts with ftp/http. Using source property unmodified")
      return new_resource.source
    end
  rescue URI::InvalidURIError
    Chef::Log.warn("source property of #{new_resource.source} could not be processed as a URI. Check the format you provided.")
  end
  logger.trace("source property does not start with ftp/http. Prepending with file:// as it appears to be a local file.")
  "file://#{new_resource.source}"
end