capistrano-utils 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-utils.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Wael M. Nasreddine
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Capistrano::Utils
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-utils'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-utils
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Wael M. Nasreddine"]
5
+ gem.email = ["wael.nasreddine@gmail.com"]
6
+ gem.description = 'Capistrano utils'
7
+ gem.summary = gem.description
8
+ gem.homepage = 'http://technogate.github.com/contao'
9
+ gem.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
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'
17
+
18
+ gem.add_dependency 'rake'
19
+ gem.add_dependency 'capistrano'
20
+ end
@@ -0,0 +1,152 @@
1
+ require 'highline'
2
+
3
+ unless Capistrano::Configuration.respond_to?(:instance)
4
+ abort 'capistrano/ext/helpers requires capistrano 2'
5
+ end
6
+
7
+ Capistrano::Configuration.instance.load do
8
+ # Taken from the capistrano code.
9
+ def _cset(name, *args, &block)
10
+ unless exists?(name)
11
+ set(name, *args, &block)
12
+ end
13
+ end
14
+
15
+ # Taken from Stackoverflow
16
+ # 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
19
+ end
20
+
21
+ def link_file(source_file, destination_file)
22
+ if remote_file_exists?(source_file)
23
+ begin
24
+ run "#{try_sudo} ln -nsf #{source_file} #{destination_file}"
25
+ rescue Capistrano::CommandError
26
+ abort "Unable to create a link for '#{source_file}' at '#{destination_file}'"
27
+ end
28
+ end
29
+ end
30
+
31
+ # Return an array of arrays of files to link
32
+ #
33
+ # @param [String] Absolute path to folder from which to link
34
+ # @param [String] Absolute path to folder to which to link
35
+ # @return [Array]
36
+ def exhaustive_list_of_files_to_link(from, to)
37
+ script = <<-END
38
+ exhaustive_list_of_files_to_link() {
39
+ files="";
40
+
41
+ for f in `ls -A1 ${1}`; do
42
+ file="${2}/${f}";
43
+ f="${1}/${f}";
44
+ if [ -e "${file}" ]; then
45
+ files="${files} `exhaustive_list_of_files_to_link ${f} ${file}`";
46
+ else
47
+ files="${files} ${f}:${file}";
48
+ fi;
49
+ done;
50
+ echo "${files}";
51
+ };
52
+ END
53
+
54
+ script << "exhaustive_list_of_files_to_link '#{from}' '#{to}';"
55
+
56
+ begin
57
+ files = capture(script).strip.split(' ')
58
+ files.map {|f| f.split(':')}
59
+ rescue Capistrano::CommandError
60
+ abort "Unable to get files list"
61
+ end
62
+ end
63
+
64
+ def link_files(path, files = {})
65
+ files.each do |f|
66
+ file_name = f.dup.gsub(/\//, '_')
67
+ unless remote_file_exists?("#{path}/#{file_name}")
68
+ begin
69
+ run <<-CMD
70
+ #{try_sudo} cp -a #{latest_release}/#{f} #{path}/#{file_name}
71
+ CMD
72
+ rescue Capistrano::CommandError
73
+ if remote_file_exists?("#{latest_release}/#{f}.default")
74
+ run <<-CMD
75
+ #{try_sudo} cp #{latest_release}/#{f}.default #{path}/#{file_name}
76
+ CMD
77
+ else
78
+ run <<-CMD
79
+ #{try_sudo} touch #{path}/#{file_name}
80
+ CMD
81
+ logger.info "WARNING: You should edit '#{path}/#{file_name}' or re-create it as a folder if that's your intention."
82
+ end
83
+ end
84
+ end
85
+
86
+ link_file File.join(path, file_name), File.join(fetch(:latest_release), f)
87
+ end
88
+ end
89
+
90
+ def gen_pass( len = 8 )
91
+ chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
92
+ newpass = ""
93
+ 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
94
+ return newpass
95
+ end
96
+
97
+ 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]
101
+
102
+ ui = HighLine.new
103
+ ui.ask("#{what}? ") do |q|
104
+ q.overwrite = false
105
+ q.default = default
106
+ q.validate = validate
107
+ q.responses[:not_valid] = what
108
+ unless echo
109
+ q.echo = "*"
110
+ end
111
+ end
112
+ end
113
+
114
+ # Read a remote file
115
+ def read(file)
116
+ capture("cat #{file}")
117
+ end
118
+
119
+ # ask_for_confirmation(what)
120
+ # This function asks the user for confirmation (confirm running the task)
121
+ # If the user answers no, then the task won't be executed.
122
+ def ask_for_confirmation(what, options = {})
123
+ unless exists?(:force) and fetch(:force) == true
124
+ # Ask for a confirmation
125
+ response = ask(what, options)
126
+ if response =~ /(no?)|(a(bort)?|\n)/i
127
+ abort "Canceled by the user."
128
+ end
129
+ end
130
+ end
131
+
132
+ def find_and_execute_db_task(task)
133
+ db_server_app = fetch :db_server_app
134
+
135
+ case db_server_app.to_sym
136
+ when :mysql
137
+ find_and_execute_task "db:mysql:#{task}"
138
+ else
139
+ abort "The database server #{db_server_app} is not supported"
140
+ end
141
+ end
142
+
143
+ def format_credentials(credentials)
144
+ <<-EOS.gsub(/\A\s+/, '')
145
+ adapter: #{fetch :db_server_app}
146
+ hostname: #{credentials[:hostname]}
147
+ port: #{credentials[:port]}
148
+ username: #{credentials[:username]}
149
+ password: #{credentials[:password]}
150
+ EOS
151
+ end
152
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Wael M. Nasreddine
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: capistrano
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Capistrano utils
47
+ email:
48
+ - wael.nasreddine@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - capistrano-utils.gemspec
59
+ - lib/capistrano/ext/helpers.rb
60
+ homepage: http://technogate.github.com/contao
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: 1.9.2
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 2457733596994320068
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.23
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Capistrano utils
87
+ test_files: []