capistrano-utils 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |gem|
4
- gem.authors = ["Wael M. Nasreddine"]
5
- gem.email = ["wael.nasreddine@gmail.com"]
6
- gem.description = 'Capistrano utils'
4
+ gem.authors = ['Wael M. Nasreddine']
5
+ gem.email = ['wael.nasreddine@gmail.com']
6
+ gem.description = 'Capistrano small recipes and methods'
7
7
  gem.summary = gem.description
8
8
  gem.homepage = 'http://technogate.github.com/contao'
9
9
  gem.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
@@ -11,9 +11,9 @@ Gem::Specification.new do |gem|
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "capistrano-utils"
15
- gem.require_paths = ["lib"]
16
- gem.version = '0.0.1'
14
+ gem.name = 'capistrano-utils'
15
+ gem.require_paths = ['lib']
16
+ gem.version = '0.0.2'
17
17
 
18
18
  gem.add_dependency 'rake'
19
19
  gem.add_dependency 'capistrano'
@@ -0,0 +1,10 @@
1
+ require 'capistrano/ext/helpers'
2
+
3
+ unless Capistrano::Configuration.respond_to?(:instance)
4
+ abort 'capistrano/ext/contao requires capistrano 2'
5
+ end
6
+
7
+ Capistrano::Configuration.instance(:must_exist).load do
8
+ set :repository,
9
+ fetch(:project_repository, `git remote show -n origin | awk '/git@github/{print $3}' | head -n 1`.strip)
10
+ end
@@ -1,10 +1,11 @@
1
+ require 'digest/sha1'
1
2
  require 'highline'
2
3
 
3
4
  unless Capistrano::Configuration.respond_to?(:instance)
4
5
  abort 'capistrano/ext/helpers requires capistrano 2'
5
6
  end
6
7
 
7
- Capistrano::Configuration.instance.load do
8
+ Capistrano::Configuration.instance(:must_exist).load do
8
9
  # Taken from the capistrano code.
9
10
  def _cset(name, *args, &block)
10
11
  unless exists?(name)
@@ -14,8 +15,9 @@ Capistrano::Configuration.instance.load do
14
15
 
15
16
  # Taken from Stackoverflow
16
17
  # http://stackoverflow.com/questions/1661586/how-can-you-check-to-see-if-a-file-exists-on-the-remote-server-in-capistrano
17
- def remote_file_exists?(full_path)
18
- 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
18
+ def remote_file_exists?(full_path, options = {})
19
+ options[:via] = :sudo if options.delete(:use_sudo)
20
+ 'true' == capture("test -e #{full_path}; if [ $? -eq 0 ]; then echo true; fi", options).strip
19
21
  end
20
22
 
21
23
  def link_file(source_file, destination_file)
@@ -95,25 +97,57 @@ exhaustive_list_of_files_to_link() {
95
97
  end
96
98
 
97
99
  def ask(what, options = {})
98
- default = options[:default]
99
- validate = options[:validate] || /(y(es)?)|(no?)|(a(bort)?|\n)/i
100
- echo = (options[:echo].nil?) ? true : options[:echo]
100
+ options[:validate] = /(y(es)?)|(no?)|(a(bort)?|\n)/i unless options.key?(:validate)
101
+ options[:echo] = true if options[:echo].nil?
101
102
 
102
103
  ui = HighLine.new
103
104
  ui.ask("#{what}? ") do |q|
104
105
  q.overwrite = false
105
- q.default = default
106
- q.validate = validate
106
+ q.default = options[:default]
107
+ q.validate = options[:validate]
107
108
  q.responses[:not_valid] = what
108
- unless echo
109
- q.echo = "*"
110
- end
109
+ q.echo = "*" unless options[:echo]
111
110
  end
112
111
  end
113
112
 
114
113
  # Read a remote file
115
- def read(file)
116
- capture("cat #{file}")
114
+ def read(file, options = {})
115
+ options[:via] = :sudo if options.delete(:use_sudo)
116
+ capture("cat #{file}", options)
117
+ end
118
+
119
+ def write(content, path = nil, options = {})
120
+ random_file = random_tmp_file(path)
121
+ put content, random_file
122
+ return random_file if path.nil?
123
+
124
+ commands = <<-CMD
125
+ cp #{random_file} #{path}; \
126
+ rm -f #{random_file}
127
+ CMD
128
+
129
+ begin
130
+ if options[:use_sudo]
131
+ sudo commands
132
+ else
133
+ run commands
134
+ end
135
+ rescue Capistrano::CommandError
136
+ logger.important "Error uploading the file #{path}"
137
+ abort "Error uploading the file #{path}"
138
+ end
139
+ end
140
+
141
+ def generate_random_file_name(data = nil)
142
+ if data
143
+ "#{fetch :application}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S-%L')}_#{Digest::SHA1.hexdigest data}"
144
+ else
145
+ "#{fetch :application}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S-%L')}"
146
+ end
147
+ end
148
+
149
+ def random_tmp_file(data = nil)
150
+ "/tmp/#{generate_random_file_name data}"
117
151
  end
118
152
 
119
153
  # ask_for_confirmation(what)
@@ -129,6 +163,22 @@ exhaustive_list_of_files_to_link() {
129
163
  end
130
164
  end
131
165
 
166
+ def arguments
167
+ index = ARGV.index(main_task) + 1
168
+ abort 'Too many arguments' if ARGV.size - 1 > index
169
+ abort 'Too few arguments' if ARGV.size - 1 < index
170
+ task ARGV[index] { } # Defines a task by the argument name
171
+ ARGV[index]
172
+ end
173
+
174
+ def exists_and_not_empty?(key)
175
+ exists?(key) && fetch(key).present?
176
+ end
177
+
178
+ def main_task
179
+ task_call_frames.find { |t| ARGV.include? t.task.fully_qualified_name }.task.fully_qualified_name
180
+ end
181
+
132
182
  def find_and_execute_db_task(task)
133
183
  db_server_app = fetch :db_server_app
134
184
 
@@ -149,4 +199,12 @@ exhaustive_list_of_files_to_link() {
149
199
  password: #{credentials[:password]}
150
200
  EOS
151
201
  end
202
+
203
+ def match_from_content(contents, part)
204
+ contents.
205
+ match(fetch "db_credentials_#{part}_regex".to_sym).
206
+ try(:[], fetch("db_credentials_#{part}_regex_match".to_sym)).
207
+ try(:chomp)
208
+ end
209
+
152
210
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-06-30 00:00:00.000000000 Z
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: Capistrano utils
46
+ description: Capistrano small recipes and methods
47
47
  email:
48
48
  - wael.nasreddine@gmail.com
49
49
  executables: []
@@ -56,6 +56,7 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - capistrano-utils.gemspec
59
+ - lib/capistrano/ext/git.rb
59
60
  - lib/capistrano/ext/helpers.rb
60
61
  homepage: http://technogate.github.com/contao
61
62
  licenses: []
@@ -77,11 +78,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  version: '0'
78
79
  segments:
79
80
  - 0
80
- hash: 2457733596994320068
81
+ hash: 359484762941975859
81
82
  requirements: []
82
83
  rubyforge_project:
83
84
  rubygems_version: 1.8.23
84
85
  signing_key:
85
86
  specification_version: 3
86
- summary: Capistrano utils
87
+ summary: Capistrano small recipes and methods
87
88
  test_files: []