2015-09-08 22:13:08 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
# Usage:
|
|
|
|
# describe pip('Jinja2') do
|
|
|
|
# it { should be_installed }
|
|
|
|
# end
|
|
|
|
class PipPackage < Vulcano.resource(1)
|
|
|
|
name 'pip'
|
|
|
|
|
|
|
|
def initialize(package_name)
|
|
|
|
@package_name = package_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def info
|
2015-09-17 14:54:01 +00:00
|
|
|
return @info unless @info.nil?
|
|
|
|
|
|
|
|
@info = {}
|
|
|
|
@info[:type] = 'pip'
|
|
|
|
|
2015-09-08 22:13:08 +00:00
|
|
|
cmd = vulcano.run_command("pip show #{@package_name}")
|
2015-09-17 14:54:01 +00:00
|
|
|
return @info if cmd.exit_status != 0
|
2015-09-08 22:13:08 +00:00
|
|
|
|
|
|
|
params = SimpleConfig.new(
|
|
|
|
cmd.stdout,
|
|
|
|
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
2015-09-09 16:37:16 +00:00
|
|
|
multiple_values: false,
|
2015-09-08 22:13:08 +00:00
|
|
|
).params
|
2015-09-17 14:54:01 +00:00
|
|
|
@info[:name] = params['Name']
|
|
|
|
@info[:version] = params['Version']
|
|
|
|
@info[:installed] = true
|
|
|
|
@info
|
2015-09-08 22:13:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def installed?
|
2015-09-17 18:51:06 +00:00
|
|
|
info[:installed] == true
|
2015-09-08 22:13:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def version
|
2015-09-17 14:54:01 +00:00
|
|
|
info[:version]
|
2015-09-08 22:13:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"pip package #{@package_name}"
|
|
|
|
end
|
|
|
|
end
|