Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enables to install fonts via cookbook files #148

Closed
wants to merge 2 commits into from

Conversation

sbotman
Copy link
Contributor

@sbotman sbotman commented Nov 25, 2014

Adding font provider for installation of fonts via cookbook files.
Simply add the font into your cookbook files, depend on the windows cookbook and target the windows_font "your_font.ttf" within your recipe.

del_cookbook_font
new_resource.updated_by_last_action(true)
else
new_resource.updated_by_last_action(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A debug line here like "Not installing font #{@new_resource.name} because file already exists at #{@current_resource.file}" would be useful.

- Moving win_path into the Windows::Helper win_friendly_path.
- Cleaning the resource file.
- Adding debug infomation.
@sbotman sbotman force-pushed the fix_fonts branch 2 times, most recently from 7bfb712 to fb00dd9 Compare December 10, 2014 15:40
@sbotman
Copy link
Contributor Author

sbotman commented Dec 10, 2014

@btm, please review again.

@btm
Copy link
Contributor

btm commented Dec 11, 2014

👍

I wonder how much value there'd be in a delete/remove action, but I don't think it's essential enough to block getting this in.

def get_cookbook_font
r = Chef::Resource::CookbookFile.new(@new_resource.file, run_context)
r.path(win_friendly_path(::File.join(ENV['TEMP'], @new_resource.file)))
r.cookbook(cookbook_name.to_s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized this is missing docs, so I'm writing them. Does this require that the font be in the windows cookbook or can you specify another cookbook as an attribute to the resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You just create another cookbook and drop the fonts in the files/default folder.
Then depend on the windows cookbook and use the provider to install them.
Example within the recipe:

%w(apl385.ttf
   BodonBEBol.ttf
   BodonBEIta.ttf
   BodonBEReg.ttf
   dyalogal.fon
   dyalogaltk.ttf
   dyalogal.ttf
   QUADBD_.ttf
   QUADI__.ttf
   QUAD___.ttf
   QuaSBd_.ttf
   QuaSIt_.ttf
   QuaSRg_.ttf).each do |f|

  windows_font f do
    file f
  end
end

That will copy the files into the right location and (because it's using wscript to copy) registers the fonts as you would do by copy them via explorer. Really could not find a better way. Tried to use the native C calls by importing the ffi api hooks, but it seems to do something nasty in the background. If you want to chat about this, please call me on skype: sander.botman@gmail.com. Cheers Sander

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great, I was confused. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the temp location is not the best place to store the file temporarily.
Could change that to the chef-cache location, but what are your thoughts about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file should already be on the disk... unless we're lazy loading, hrm.. gotta look into that. Maybe we can skip copying it out with CookbookFile? You'd think we would have a helper for this...

I just tested this with chef-zero. There's tidbits of this in the back of my head from the minitest-handler cookbook.

# the name of the test cookbook was collection
# there was a file in files/default named foo.txt

relative_path = run_context.cookbook_collection["collection"].manifest["files"].select { |f| f[:name] == "foo.txt" }.first[:path]
absolute_path = "#{Chef::Config[:cookbook_path]}/#{cookbook_name}/#{relative_path}"

puts "computed path is: #{absolute_path}"
File.open(absolute_path, "r") { |f| f.each_line { |l| puts l } }

@btm
Copy link
Contributor

btm commented Dec 12, 2014

I've merged this to master as is, as we're planning on releasing the cookbook on Monday and it's working. I added some docs and added this to the basic integration testing framework we just added (bundle exec kitchen test). I wanted to get my additions merged in with yours too.

I agree we could continue improve it and I encourage you to do so based off master.

@btm btm closed this Dec 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants