geordi 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/console-for +7 -19
- data/bin/cuc +3 -1
- data/bin/dump-for +12 -54
- data/bin/rs +3 -1
- data/bin/shell-for +8 -54
- data/lib/geordi/version.rb +1 -1
- data/lib/geordi.rb +62 -0
- metadata +7 -6
data/bin/console-for
CHANGED
@@ -1,25 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + "/../lib/geordi"
|
3
|
+
include Geordi
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
until (File.exists? 'Capfile')
|
6
|
-
Dir.chdir '..'
|
7
|
-
return nil if current == Dir.pwd
|
8
|
-
current = Dir.pwd
|
9
|
-
end
|
10
|
-
current
|
11
|
-
end
|
12
|
-
|
13
|
-
begin
|
14
|
-
stage = ARGV.shift
|
15
|
-
root = find_project_root or raise 'Call me from inside a Rails project!'
|
5
|
+
catching_errors do
|
6
|
+
retrieve_data!
|
16
7
|
|
17
8
|
if File.exists? "#{root}/script/console" # => Rails 2
|
18
|
-
|
9
|
+
system "shell-for #{env} --no-bash script/console #{env}"
|
19
10
|
else
|
20
|
-
|
11
|
+
system "shell-for #{env} --no-bash bundle exec rails console #{env}"
|
21
12
|
end
|
22
|
-
|
23
|
-
$stderr.puts e.message
|
24
|
-
exit 1
|
25
|
-
end
|
13
|
+
end
|
data/bin/cuc
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
# Print some whitespace
|
4
4
|
4.times { puts }
|
5
|
+
puts "Running Cucumber tests..."
|
6
|
+
puts "========================="
|
5
7
|
|
6
8
|
# Check if cucumber_spinner is available
|
7
9
|
spinner_available = File.exists?('Gemfile') && File.open('Gemfile').read.scan(/cucumber_spinner/).any?
|
@@ -17,4 +19,4 @@ if use_parallel_tests
|
|
17
19
|
exec *['b', 'rake', 'parallel:features', ARGV].flatten
|
18
20
|
else
|
19
21
|
exec *["b", "cucumber", format_args, ARGV].flatten
|
20
|
-
end
|
22
|
+
end
|
data/bin/dump-for
CHANGED
@@ -1,61 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + "/../lib/geordi"
|
3
|
+
include Geordi
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
line.match(/["'](.*)["']/)
|
6
|
-
$1
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def find_project_root
|
11
|
-
current = Dir.pwd
|
12
|
-
until (File.exists? 'Capfile')
|
13
|
-
Dir.chdir '..'
|
14
|
-
return nil if current == Dir.pwd
|
15
|
-
current = Dir.pwd
|
16
|
-
end
|
17
|
-
@project_root = current
|
18
|
-
end
|
19
|
-
|
20
|
-
begin
|
21
|
-
stage = ARGV.shift
|
22
|
-
dump_name = "dump_for_download.dump"
|
5
|
+
catching_errors do
|
6
|
+
retrieve_data!
|
23
7
|
|
24
|
-
|
8
|
+
command = %(ssh #{user}@#{server} -t "cd #{path} && dumple #{env} --for_download")
|
9
|
+
success = system command
|
25
10
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
File.open(deploy_file).readlines
|
11
|
+
if success
|
12
|
+
puts "Downloading dump_for_download..."
|
13
|
+
system "scp #{user}@#{server}:~/dumps/dump_for_download.dump #{root}/tmp/#{env}.dump"
|
14
|
+
puts
|
15
|
+
puts "Dumped the #{env.upcase} database to: #{File.basename root}/tmp/#{env}.dump"
|
33
16
|
else
|
34
|
-
|
35
|
-
end + File.open("config/deploy.rb").readlines
|
36
|
-
|
37
|
-
user = unquote data.find{ |line| line =~ /^set :user,/}
|
38
|
-
server = unquote data.find{ |line| line =~ /^server / }
|
39
|
-
deploy_to = unquote data.find{ |line| line =~ /^set :deploy_to,/}
|
40
|
-
environment = unquote data.find{ |line| line =~ /^set :rails_env,/}
|
41
|
-
(user and server and deploy_to and environment) or raise "Could not find required data (user, server, deploy target and environment).\nUsage: dump-for DEPLOYMENT_STAGE"
|
42
|
-
|
43
|
-
path = deploy_to + "/current"
|
44
|
-
if path.match /#\{.*\}/
|
45
|
-
puts %(NOTE: "#{path}" is not a valid path.)
|
46
|
-
puts %(NOTE: You will need to fetch the dump yourself.)
|
47
|
-
raise ""
|
17
|
+
raise "An error occurred. Aborting..."
|
48
18
|
end
|
49
|
-
|
50
|
-
command = %(ssh #{user}@#{server} -t "cd #{path} && dumple #{environment} --for_download")
|
51
|
-
system command
|
52
|
-
|
53
|
-
puts "Downloading dump_for_download..."
|
54
|
-
system "scp #{user}@#{server}:~/dumps/#{dump_name} #{@project_root}/tmp/#{environment}.dump"
|
55
|
-
puts
|
56
|
-
puts "Dumped the #{environment.upcase} database to PROJECT_ROOT/tmp/#{environment}.dump"
|
57
|
-
|
58
|
-
rescue Exception => e
|
59
|
-
$stderr.puts e.message
|
60
|
-
exit 1
|
61
19
|
end
|
data/bin/rs
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
# Print some whitespace
|
4
4
|
4.times { puts }
|
5
|
+
puts "Running RSpec tests..."
|
6
|
+
puts "======================"
|
5
7
|
|
6
8
|
# Check if we're looking at a Rails 2 / rspec 1 project
|
7
9
|
rspec1 = File.exists?('script/spec')
|
@@ -25,4 +27,4 @@ if use_parallel_tests
|
|
25
27
|
else
|
26
28
|
# Run rspec behind bundler
|
27
29
|
exec *["b", rspec_args, spinner_args, ARGV].flatten
|
28
|
-
end
|
30
|
+
end
|
data/bin/shell-for
CHANGED
@@ -1,63 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + "/../lib/geordi"
|
3
|
+
include Geordi
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def find_project_root
|
11
|
-
current = Dir.pwd
|
12
|
-
until (File.exists? 'Capfile')
|
13
|
-
Dir.chdir '..'
|
14
|
-
return nil if current == Dir.pwd
|
15
|
-
current = Dir.pwd
|
16
|
-
end
|
17
|
-
@project_root = current
|
18
|
-
end
|
19
|
-
|
20
|
-
begin
|
21
|
-
stage = ARGV.shift
|
22
|
-
no_bash = ARGV.shift if ARGV.first == '--no-bash'
|
23
|
-
remote_command = ARGV.join(' ').strip
|
5
|
+
catching_errors do
|
6
|
+
retrieve_data!
|
7
|
+
no_bash = ARGV.delete('--no-bash')
|
8
|
+
remote_command = ARGV.join(' ').strip
|
24
9
|
|
25
|
-
find_project_root or raise 'Call me from inside a Rails project!'
|
26
|
-
|
27
|
-
data = if stage
|
28
|
-
deploy_file = Dir["#{@project_root}/config/deploy/*.rb"].find do |file|
|
29
|
-
file.match(/\/#{stage}.rb$/)
|
30
|
-
end
|
31
|
-
deploy_file or raise "Stage does not exist: #{stage}"
|
32
|
-
|
33
|
-
File.open(deploy_file).readlines
|
34
|
-
else
|
35
|
-
[]
|
36
|
-
end + File.open("#{@project_root}/config/deploy.rb").readlines
|
37
|
-
|
38
|
-
user = unquote data.find{ |line| line =~ /^set :user, /}
|
39
|
-
server = unquote data.find{ |line| line =~ /^server / }
|
40
|
-
deploy_to = unquote data.find{ |line| line =~ /^set :deploy_to, /}
|
41
|
-
|
42
|
-
(user and server and deploy_to) or raise "Could not find required data (user, server and deploy-target).\nUsage: shell-for DEPLOYMENT_STAGE"
|
43
|
-
|
44
|
-
path = deploy_to + "/current"
|
45
10
|
ssh = %(ssh #{user}@#{server})
|
46
11
|
|
47
|
-
commands = []
|
48
|
-
if path.match /#\{.*\}/
|
49
|
-
puts %(NOTE: "#{path}" is not a valid path.)
|
50
|
-
puts %(NOTE: Connecting to deploy user home.)
|
51
|
-
sleep 2
|
52
|
-
else
|
53
|
-
commands << "cd #{path}"
|
54
|
-
end
|
12
|
+
commands = [ "cd #{path}" ]
|
55
13
|
commands << remote_command unless remote_command.empty?
|
56
14
|
commands << "bash --login" unless no_bash
|
57
15
|
|
58
16
|
exec ssh + %( -t "#{commands.join(' && ')}")
|
59
|
-
|
60
|
-
rescue Exception => e
|
61
|
-
$stderr.puts e.message
|
62
|
-
exit 1
|
63
|
-
end
|
17
|
+
end
|
data/lib/geordi/version.rb
CHANGED
data/lib/geordi.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Geordi
|
2
|
+
|
3
|
+
attr_accessor :stage, :user, :server, :path, :env, :root
|
4
|
+
|
5
|
+
def catching_errors(&block)
|
6
|
+
begin
|
7
|
+
yield
|
8
|
+
rescue Exception => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def retrieve_data!
|
15
|
+
@stage = ARGV.shift
|
16
|
+
@root = find_project_root!
|
17
|
+
|
18
|
+
{}.tap do |data|
|
19
|
+
@lines = if stage
|
20
|
+
deploy_file = Dir['config/deploy/*.rb'].find do |file|
|
21
|
+
file.match(/\/#{stage}.rb$/)
|
22
|
+
end
|
23
|
+
deploy_file or raise "Stage does not exist: #{stage}"
|
24
|
+
|
25
|
+
File.open(deploy_file).readlines
|
26
|
+
else
|
27
|
+
[]
|
28
|
+
end
|
29
|
+
@lines += File.open("config/deploy.rb").readlines
|
30
|
+
|
31
|
+
@user = retrieve! "user", /^set :user,/
|
32
|
+
@server = retrieve! "server", /^server /
|
33
|
+
@path = retrieve!("deploy_to", /^set :deploy_to,/) + '/current'
|
34
|
+
@env = retrieve! "environment", /^set :rails_env,/
|
35
|
+
|
36
|
+
# fix
|
37
|
+
%w[user server path env].each do |attr|
|
38
|
+
self.send(attr).gsub! /#\{site_id\}/, stage.sub(/_.*/, '')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_project_root!
|
44
|
+
current = Dir.pwd
|
45
|
+
until (File.exists? 'Capfile')
|
46
|
+
Dir.chdir '..'
|
47
|
+
raise 'Call me from inside a Rails project!' if current == Dir.pwd
|
48
|
+
current = Dir.pwd
|
49
|
+
end
|
50
|
+
current
|
51
|
+
end
|
52
|
+
|
53
|
+
def retrieve!(name, regex)
|
54
|
+
if line = @lines.find{ |line| line =~ regex }
|
55
|
+
line.match(/["'](.*)["']/)
|
56
|
+
$1
|
57
|
+
else
|
58
|
+
raise "Could not find :#{name} for stage '#{stage}'!\nAborting..."
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geordi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Henning Koch
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-22 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- bin/shell-for
|
66
66
|
- bin/tests
|
67
67
|
- geordi.gemspec
|
68
|
+
- lib/geordi.rb
|
68
69
|
- lib/geordi/version.rb
|
69
70
|
has_rdoc: true
|
70
71
|
homepage: http://makandra.com
|
@@ -96,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
97
|
requirements: []
|
97
98
|
|
98
99
|
rubyforge_project: geordi
|
99
|
-
rubygems_version: 1.
|
100
|
+
rubygems_version: 1.5.2
|
100
101
|
signing_key:
|
101
102
|
specification_version: 3
|
102
103
|
summary: Collection of command line tools we use in our daily work with Ruby, Rails and Linux at makandra.
|