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

Check for puppet executable instead of gem #162

Merged
merged 2 commits into from
Jan 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions lib/librarian/puppet.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
require 'librarian'
require 'fileutils'
require 'open3'
require 'open3_backport' if RUBY_VERSION < '1.9'

status = nil
out = nil
error = nil

begin
require 'puppet'
rescue LoadError
Open3.popen3('puppet --version') {|stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid # pid of the started process.
out = stdout.read
status = wait_thr.value # Process::Status object returned.
}
rescue => e
error = e
end

if status.nil? or status.exitstatus != 0
$stderr.puts <<-EOF
Unable to load puppet. Either install it using native packages for your
platform (eg .deb, .rpm, .dmg, etc) or as a gem (gem install puppet).
Unable to load puppet. Please install it using native packages for your platform (eg .deb, .rpm, .dmg, etc).
#{out.nil? or out.empty? ? "puppet --version returned #{status.exitstatus}" : out}
#{error.message unless error.nil?}
EOF
exit 1
end

PUPPET_VERSION=out.split(' ').first.strip

require 'librarian/puppet/extension'
require 'librarian/puppet/version'

Expand Down
2 changes: 1 addition & 1 deletion lib/librarian/puppet/source/forge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def cache_version_unpacked!(version)

def check_puppet_module_options
min_version = Gem::Version.create('2.7.13')
puppet_version = Gem::Version.create(`puppet --version`.split(' ').first.strip.gsub('-', '.'))
puppet_version = Gem::Version.create(PUPPET_VERSION.gsub('-', '.'))

if puppet_version < min_version
raise Error, "To get modules from the forge, we use the puppet faces module command. For this you need at least puppet version 2.7.13 and you have #{puppet_version}"
Expand Down
1 change: 1 addition & 0 deletions lib/librarian/puppet/source/git.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'librarian/source/git'
require 'librarian/puppet/source/local'
require 'puppet'

module Librarian
module Source
Expand Down
1 change: 1 addition & 0 deletions librarian-puppet.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Gem::Specification.new do |s|

s.add_dependency "librarian", ">=0.1.1"
s.add_dependency "json"
s.add_dependency "open3_backport" if RUBY_VERSION < '1.9'

s.add_development_dependency "rake"
s.add_development_dependency "rspec"
Expand Down