geordi 0.2.3 → 0.2.5

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/README.md CHANGED
@@ -23,7 +23,7 @@ More information at http://makandra.com/notes/807-shell-script-to-quickly-switch
23
23
  b
24
24
  -
25
25
 
26
- Run the given command under `bundle exec` if a `Gemfile` is present in your working directory. If no `Gemfile` is present it just runs the given command:
26
+ Runs the given command under `bundle exec` if a `Gemfile` is present in your working directory. If no `Gemfile` is present just runs the given command:
27
27
 
28
28
  b spec spec/models
29
29
 
@@ -43,7 +43,7 @@ More information at http://makandra.com/notes/1008-dump-your-database-with-dumpl
43
43
  install-gems-remotely
44
44
  ---------------------
45
45
 
46
- Installs all gems in your `Gemfile.lock` as well as vendored gems on the given host:
46
+ Installs all gems in your `Gemfile.lock`, as well as vendored gems, to the given host:
47
47
 
48
48
  install-gems-remotely my.server.com
49
49
 
@@ -63,7 +63,7 @@ This script is considered legacy and will be removed eventually. You should [fix
63
63
  power-rake
64
64
  ----------
65
65
 
66
- Runs the given rake task in each Rails environment in `development`, `test`, `cucumber`, `performance`, if it exists:
66
+ Runs the given rake task in each Rails environment in `development`, `test`, `cucumber`, `performance`, if existing:
67
67
 
68
68
  power-rake db:migrate
69
69
 
@@ -83,9 +83,11 @@ More information at http://makandra.com/notes/520-create-a-remote-branch-in-git
83
83
  remove-executable-flags
84
84
  -----------------------
85
85
 
86
- Recursively removes executable flags from files in the working directory that probably shouldn't have them:
86
+ Recursively removes executable flags from files in the working directory that probably shouldn't have them (like Ruby, HTML, CSS, image, Rake and similar files).
87
87
 
88
88
  remove-executable-flags
89
+
90
+ More information at http://makandra.com/notes/659-recursively-remove-unnecessary-execute-flags
89
91
 
90
92
 
91
93
  shell-for
@@ -97,3 +99,13 @@ Opens an SSH shell on the given [Capistrano multistage](https://github.com/capis
97
99
 
98
100
  More information at http://makandra.com/notes/1209-script-to-open-an-ssh-shell-to-a-capistrano-deployment-target
99
101
 
102
+
103
+ dump-for
104
+ --------
105
+
106
+ Dumps the database on your server for a given [Capistrano multistage](https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension) deployment target, then copies the dump to your project root.
107
+
108
+ dump-for production
109
+
110
+ More information at http://makandra.com/notes/1237-script-to-create-and-copy-a-production-dump-to-your-project-root
111
+
data/bin/dump-for ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def unquote(line)
4
+ if line
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
+ require 'rubygems'
22
+ require 'net/ssh'
23
+
24
+ stage = ARGV.shift
25
+
26
+ find_project_root or raise 'Call me from inside a Rails project'
27
+
28
+ data = if stage
29
+ deploy_file = Dir['config/deploy/*.rb'].find do |file|
30
+ file.match(/\/#{stage}.rb$/)
31
+ end
32
+ deploy_file or raise "Unknown stage: #{stage}"
33
+
34
+ File.open(deploy_file).readlines
35
+ else
36
+ []
37
+ end + File.open("config/deploy.rb").readlines
38
+
39
+ user = unquote data.find{ |line| line =~ /^set :user,/}
40
+ server = unquote data.find{ |line| line =~ /^server / }
41
+ deploy_to = unquote data.find{ |line| line =~ /^set :deploy_to,/}
42
+ environment = unquote data.find{ |line| line =~ /^set :rails_env,/}
43
+ (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"
44
+
45
+ path = deploy_to + "/current"
46
+ if path.match /#\{.*\}/
47
+ puts %(NOTE: "#{path}" is not a valid path.)
48
+ puts %(NOTE: You will need to fetch the dump yourself.)
49
+ raise ""
50
+ end
51
+
52
+ command = %(ssh #{user}@#{server} -t "cd #{path} && dumple #{environment} --for_download")
53
+ system command
54
+
55
+ puts "Downloading dump_for_download..."
56
+ exec "scp #{user}@#{server}:~/dumps/dump_for_download.dump #{@project_root}"
57
+
58
+ rescue Exception => e
59
+ $stderr.puts e.message
60
+ exit 1
61
+ end
data/bin/dumple CHANGED
@@ -11,46 +11,64 @@ if ARGV.include?("-i")
11
11
  exit
12
12
  end
13
13
 
14
- require "yaml"
14
+ ###
15
15
 
16
+ require "yaml"
16
17
  config_path = 'config/database.yml'
17
- unless File.exist?(config_path)
18
- if fail_gently
19
- puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
20
- puts "* *"
21
- puts "* *"
22
- puts "* Script is not called from inside a Rails project, *"
23
- puts "* *"
24
- puts "* THE DATABASE WILL NOT BE DUMPED. *"
25
- puts "* *"
26
- puts "* *"
27
- puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
28
- sleep 5
29
- exit
30
- else
31
- raise "Call me from inside a Rails project."
18
+
19
+ begin
20
+ # go to project root
21
+ current = Dir.pwd
22
+ until (File.exists? config_path)
23
+ Dir.chdir '..'
24
+ if current == Dir.pwd
25
+ if fail_gently
26
+ puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
27
+ puts "* *"
28
+ puts "* *"
29
+ puts "* Script is not called from inside a Rails project, *"
30
+ puts "* *"
31
+ puts "* THE DATABASE WILL NOT BE DUMPED. *"
32
+ puts "* *"
33
+ puts "* *"
34
+ puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
35
+ sleep 5
36
+ exit
37
+ else
38
+ raise "Call me from inside a Rails project."
39
+ end
40
+ end
41
+ current = Dir.pwd
32
42
  end
33
- end
34
- config = YAML::load(File.open(config_path))
35
43
 
36
- environment = ARGV.reject{ |arg| arg[0].chr == '-' }.first || 'production'
37
- config = config[environment] or raise "No production environment found. Please do `dumple [env_name]`"
44
+ config = YAML::load(File.open(config_path))
38
45
 
39
- dump_dir = "#{ENV['HOME']}/dumps"
40
- unless File.directory?(dump_dir)
41
- Dir.mkdir(dump_dir)
42
- system("chmod 700 #{dump_dir}")
43
- end
44
- dump_path = "#{dump_dir}/#{config['database']}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.dump"
46
+ environment = ARGV.reject{ |arg| arg[0].chr == '-' }.first || 'production'
47
+ config = config[environment] or raise "No #{environment} database found.\nUsage: dumple ENVIRONMENT"
45
48
 
46
- puts
47
- puts "Dumping database for environment \"#{environment}\"..."
49
+ dump_dir = "#{ENV['HOME']}/dumps"
50
+ unless File.directory?(dump_dir)
51
+ Dir.mkdir(dump_dir)
52
+ system("chmod 700 #{dump_dir}")
53
+ end
54
+
55
+ if ARGV.find{ |arg| arg == '--for_download'}
56
+ dump_path = "#{dump_dir}/dump_for_download.dump"
57
+ else
58
+ dump_path = "#{dump_dir}/#{config['database']}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.dump"
59
+ end
48
60
 
49
- system "mysqldump -u\"#{config['username']}\" -p\"#{config['password']}\" #{config['database']} -r #{dump_path}"
50
- system "chmod 600 #{dump_path}"
61
+ puts
62
+ puts "Dumping database for \"#{environment}\" environment ..."
51
63
 
52
- dump_size_kb = (File.size(dump_path) / 1024).round
64
+ system "mysqldump -u\"#{config['username']}\" -p\"#{config['password']}\" #{config['database']} -r #{dump_path}"
65
+ system "chmod 600 #{dump_path}"
53
66
 
54
- puts "Dumped to #{dump_path} (#{dump_size_kb} KB)"
55
- puts
67
+ dump_size_kb = (File.size(dump_path) / 1024).round
56
68
 
69
+ puts "Dumped to #{dump_path} (#{dump_size_kb} KB)"
70
+ puts
71
+ rescue Exception => e
72
+ $stderr.puts e.message
73
+ exit 1
74
+ end
@@ -1,4 +1,9 @@
1
1
  #!/bin/sh
2
+ if [ -z "$1" ]; then
3
+ echo "Please specify the remote server name"
4
+ exit 1
5
+ fi
6
+ mkdir -p tmp
2
7
  if ls vendor/gems/*/*.gemspec > /dev/null 2>&1; then
3
8
  tar cf tmp/gemfiles_for_remote_install Gemfile Gemfile.lock vendor/gems/*/*.gemspec
4
9
  else
@@ -8,4 +13,4 @@ scp tmp/gemfiles_for_remote_install $1:~
8
13
  stty_orig=`stty -g`
9
14
  stty -echo
10
15
  ssh -t $1 "mkdir /tmp/install_gems; mv gemfiles_for_remote_install /tmp/install_gems; cd /tmp/install_gems; tar xf gemfiles_for_remote_install; bundle install; rm -rf /tmp/install_gems"
11
- stty $stty_orig
16
+ stty $stty_orig
data/bin/power-deploy CHANGED
@@ -1,4 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  stage = ARGV[0]
4
+ puts "NOTE: This Script is considered legacy and will be removed eventually."
5
+ puts "NOTE: You should fix your deploy scripts (see http://makandra.com/notes/1176-which-capistrano-hooks-to-use-for-events-to-happen-on-both-cap-deploy-and-cap-deploy-migrations)"
6
+ puts "Note: and use `cap deploy:migrations` (see http://makandra.com/notes/1000-deploy-and-migrate-with-a-single-capistrano-command) instead."
7
+ puts
4
8
  exec "cap #{stage} deploy && cap #{stage} deploy:migrate && cap #{stage} deploy:restart"
data/bin/power-rake CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  for env in %w[development test cucumber performance]
4
4
  if File.exists? "config/environments/#{env}.rb"
5
- call = ['rake'] + ARGV + ["RAILS_ENV=#{env}"]
5
+ call = ['b', 'rake'] + ARGV + ["RAILS_ENV=#{env}"]
6
6
  puts call.join(' ')
7
7
  system *call
8
8
  end
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- puts "Removing execute flags:"
3
+ puts "Removing executable-flags:"
4
4
  for pattern in %w[*.rb *.html *.erb *.haml *.yml *.css *.sass *.rake *.png *.jpg *.gif *.pdf *.txt *.rdoc Rakefile VERSION README Capfile]
5
5
  puts "- #{pattern}"
6
- `find . -name "#{pattern}" -exec chmod -x {} \`
6
+ `find . -name "#{pattern}" -exec chmod -x {} \ `
7
7
  end
8
8
  puts "Done."
data/bin/shell-for CHANGED
@@ -1,42 +1,56 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- def quoted_text(line)
4
- line.match(/["'].*["']/).to_s.gsub(/["']/, '')
3
+ def unquote(line)
4
+ if line
5
+ line.match(/["'](.*)["']/)
6
+ $1
7
+ end
5
8
  end
6
9
 
7
- def read_deploy_files
8
- all_deploy_files = Dir["config/deploy/*.rb"]
9
-
10
- deploy_file = all_deploy_files.find do |file|
11
- file.match(/\/#{@stage}.rb$/)
12
- end
13
- raise "Unknown stage: #{@stage}" unless deploy_file
14
-
15
- @specific = File.open(deploy_file).readlines
16
- @for_all = File.open("config/deploy.rb").readlines
17
- end
18
-
19
- def build_command
20
- path = quoted_text(@deploy_to) + "/current"
21
-
22
- @command = "ssh #{quoted_text(@user)}@#{quoted_text(@server)}"
23
- @command += %( -t "cd #{path} && bash --login") unless path.match /#\{/
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
+ current
24
18
  end
25
19
 
26
20
  begin
27
- @stage = ARGV.shift
21
+ stage = ARGV.shift
22
+
23
+ find_project_root or raise 'Call me from inside a Rails project'
28
24
 
29
- raise "Usage: shell_for DEPLOYMENT_STAGE" unless @stage
30
- raise "Run me from inside a Rails project" unless File.exists?("config/deploy.rb")
25
+ data = if stage
26
+ deploy_file = Dir['config/deploy/*.rb'].find do |file|
27
+ file.match(/\/#{stage}.rb$/)
28
+ end
29
+ deploy_file or raise "Unknown stage: #{stage}"
30
+
31
+ File.open(deploy_file).readlines
32
+ else
33
+ []
34
+ end + File.open("config/deploy.rb").readlines
31
35
 
32
- read_deploy_files
33
- @user = @specific.find{ |line| line =~ /^set :user, /} || @for_all.find{ |line| line =~ /^set :user, / }
34
- @server = @specific.find{ |line| line =~ /^server / } || @for_all.find{ |line| line =~ /^server / }
35
- @deploy_to = @specific.find{ |line| line =~ /^set :deploy_to, /} || @for_all.find{ |line| line =~ /^set :deploy_to, / }
36
+ user = unquote data.find{ |line| line =~ /^set :user, /}
37
+ server = unquote data.find{ |line| line =~ /^server / }
38
+ deploy_to = unquote data.find{ |line| line =~ /^set :deploy_to, /}
36
39
 
37
- build_command
40
+ (user and server and deploy_to) or raise "Could not find required data (user, server and deploy-target).\nUsage: shell-for DEPLOYMENT_STAGE"
38
41
 
39
- exec @command
42
+ path = deploy_to + "/current"
43
+ command = %(ssh #{user}@#{server})
44
+
45
+ if path.match /#\{.*\}/
46
+ puts %(NOTE: "#{path}" is not a valid path.)
47
+ puts %(NOTE: Connecting to deploy user home.)
48
+ sleep 2
49
+ else
50
+ command += %( -t "cd #{path} && bash --login")
51
+ end
52
+
53
+ exec command
40
54
 
41
55
  rescue Exception => e
42
56
  $stderr.puts e.message
@@ -1,3 +1,3 @@
1
1
  module Geordi
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.5'
3
3
  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: 17
5
- prerelease: false
4
+ hash: 29
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 5
10
+ version: 0.2.5
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-05-26 00:00:00 +02:00
18
+ date: 2011-05-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -25,13 +25,14 @@ email:
25
25
  executables:
26
26
  - apache-site
27
27
  - b
28
+ - dump-for
28
29
  - dumple
29
30
  - install-gems-remotely
30
31
  - install-gems-remotely.sh
31
32
  - power-deploy
32
33
  - power-rake
33
34
  - remotify-local-branch
34
- - remove-execute-flags
35
+ - remove-executable-flags
35
36
  - shell-for
36
37
  extensions: []
37
38
 
@@ -44,13 +45,14 @@ files:
44
45
  - Rakefile
45
46
  - bin/apache-site
46
47
  - bin/b
48
+ - bin/dump-for
47
49
  - bin/dumple
48
50
  - bin/install-gems-remotely
49
51
  - bin/install-gems-remotely.sh
50
52
  - bin/power-deploy
51
53
  - bin/power-rake
52
54
  - bin/remotify-local-branch
53
- - bin/remove-execute-flags
55
+ - bin/remove-executable-flags
54
56
  - bin/shell-for
55
57
  - geordi.gemspec
56
58
  - lib/geordi/version.rb
@@ -84,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  requirements: []
85
87
 
86
88
  rubyforge_project: geordi
87
- rubygems_version: 1.3.7
89
+ rubygems_version: 1.5.2
88
90
  signing_key:
89
91
  specification_version: 3
90
92
  summary: Collection of command line tools we use in our daily work with Ruby, Rails and Linux at makandra.