capistrano-pyenv 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -79,8 +79,57 @@ module Capistrano
79
79
  }
80
80
  }
81
81
 
82
+ _cset(:pyenv_configure_home) { capture("echo $HOME").chomp }
83
+ _cset(:pyenv_configure_shell) { capture("echo $SHELL").chomp }
84
+ _cset(:pyenv_configure_files) {
85
+ if fetch(:pyenv_configure_basenames, nil)
86
+ [ pyenv_configure_basenames ].flatten.map { |basename|
87
+ File.join(pyenv_configure_home, basename)
88
+ }
89
+ else
90
+ case File.basename(pyenv_configure_shell)
91
+ when /bash/
92
+ [ File.join(pyenv_configure_home, '.bash_profile') ]
93
+ when /zsh/
94
+ [ File.join(pyenv_configure_home, '.zshenv') ]
95
+ else # other sh compatible shell such like dash
96
+ [ File.join(pyenv_configure_home, '.profile') ]
97
+ end
98
+ end
99
+ }
100
+ _cset(:pyenv_configure_script) {
101
+ (<<-EOS).gsub(/^\s*/, '')
102
+ # Configured by capistrano-pyenv. Do not edit directly.
103
+ export PATH="#{pyenv_path}/bin:$PATH"
104
+ eval "$(pyenv init -)"
105
+ EOS
106
+ }
107
+ _cset(:pyenv_configure_signature, '##pyenv:configure')
82
108
  task(:configure, :except => { :no_release => true }) {
83
- # nop
109
+ if fetch(:pyenv_use_configure, true)
110
+ script = File.join('/tmp', "pyenv.#{$$}")
111
+ config = [ pyenv_configure_files ].flatten
112
+ config_map = Hash[ config.map { |f| [f, File.join('/tmp', "#{File.basename(f)}.#{$$}")] } ]
113
+ begin
114
+ execute = []
115
+ put(pyenv_configure_script, script)
116
+ config_map.each { |file, temp|
117
+ ## (1) copy original config to temporaly file and then modify
118
+ execute << "( cp -fp #{file} #{temp} || touch #{temp} )"
119
+ execute << "sed -i -e '/^#{Regexp.escape(pyenv_configure_signature)}/,/^#{Regexp.escape(pyenv_configure_signature)}/d' #{temp}"
120
+ execute << "echo #{pyenv_configure_signature.dump} >> #{temp}"
121
+ execute << "cat #{script} >> #{temp}"
122
+ execute << "echo #{pyenv_configure_signature.dump} >> #{temp}"
123
+ ## (2) update config only if it is needed
124
+ execute << "cp -fp #{file} #{file}.orig"
125
+ execute << "( diff -u #{file} #{temp} || mv -f #{temp} #{file} )"
126
+ }
127
+ run(execute.join(' && '))
128
+ ensure
129
+ remove = [ script ] + config_map.values
130
+ run("rm -f #{remove.join(' ')}") rescue nil
131
+ end
132
+ end
84
133
  }
85
134
 
86
135
  _cset(:pyenv_platform) {
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module PyEnv
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-pyenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano