Skip to content

Instantly share code, notes, and snippets.

@n3bulous
Forked from jacobian/virtualenv-example.rb
Created June 7, 2013 01:03
Show Gist options
  • Save n3bulous/5726367 to your computer and use it in GitHub Desktop.
Save n3bulous/5726367 to your computer and use it in GitHub Desktop.
# An example of the below
virtualenv "/home/dvcsmirrors/hg" do
owner "root"
group "dvcsmirrors"
mode 0775
packages "Mercurial" => "1.6.3",
"hgsubversion" => "1.1.2"
end
#
# Definition to create virtualenvs
#
# For example::
#
# virtualenv "/home/me/myenv" do
# packages "Django" => "1.2.3"
# end
#
# This would create a new virtualenv in /home/me/myenv and install
# Django 1.2.3. "packages" is a hash, so you can include multiple
# packages there. Right now there's nothing to say "latest version"
# because I don't know Ruby that well!
#
# The definition also accepts path, owner, group, and mode arguments, just
# like the directory resource.
#
# TODO: support a requirements file.
#
define :virtualenv, :action => :create, :owner => "root", :group => "root", :mode => 0755, :packages => {} do
path = params[:path] ? params[:path] : params[:name]
if params[:action] == :create
# Manage the directory.
directory path do
owner params[:owner]
group params[:group]
mode params[:mode]
end
execute "create-virtualenv-#{path}" do
command "virtualenv #{path}"
not_if "test -f #{path}/bin/python"
end
params[:packages].each_pair do |package, version|
pip = "#{path}/bin/pip"
execute "install-#{package}-#{path}" do
command "#{pip} install #{package}==#{version}"
not_if "[ `#{pip} freeze | grep #{package} | cut -d'=' -f3` = '#{version}' ]"
end
end
elsif params[:action] == :delete
directory path do
action :delete
recursive true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment