handy 0.0.7 → 0.0.9

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
@@ -1,16 +1,17 @@
1
1
  # A Rails3 compliant gem which provides followings rake tasks#
2
2
 
3
3
  ##rake handy:db:backup##
4
- Creates a dump of data and structure which can been safely backed up
4
+ Creates a dump of data and structure which can been safely backed up.
5
+ file is backuped at <tt>tmp</tt> directory like this <tt>tmp/2011-02-10-22-05-40.sql.gz</tt>
5
6
 
6
7
  ##rake handy:db:restore file=xyz.sql.gz##
7
- restores the data and structure from file
8
+ restores the data and structure from file
8
9
 
9
10
  ##rake handy:db:db2db##
10
11
  Restores the data from production database to staging database. More options can be specified.
11
-
12
+
12
13
  ##rake handy:db:dump2s3##
13
- Creates a backup and then stores that backup on s3.
14
+ Creates a backup and then stores that backup on s3.
14
15
 
15
16
  s3 login information can be passed as per [http://gist.github.com/619432](http://github.com/neerajdotname/handy) .
16
17
 
@@ -19,9 +20,9 @@ s3 login information can be passed as per [http://gist.github.com/619432](http:/
19
20
  Prints a list of all files stored on s3.
20
21
 
21
22
  ##rake handy:db:dump2s3:restore file=xxxx.sql.gz##
22
- Restores the database with the data from s3. Sweet!!
23
+ Restores the database with the data from s3. Sweet!!
23
24
 
24
25
  ##rake handy:web:ping site=www.page41.com##
25
- Pings a site.
26
+ Pings a site.
26
27
 
27
28
  Copyright (c) 2010 Neeraj Singh. See LICENSE for details.
@@ -0,0 +1,20 @@
1
+ before "deploy:update_code", "user_confirmation_for_production_deployment"
2
+ task :user_confirmation_for_production_deployment, roles => :app do
3
+ if "#{stage}" == 'production'
4
+ message = %Q{
5
+ ****************************************************************************************************************
6
+ * You are pushing to production.
7
+ *
8
+ * production is deployed from production branch. So make sure that you merged your changes to production branch.
9
+ *
10
+ * You have pushed your changes to github. Right.
11
+ *
12
+ * continue(y/n)
13
+ ****************************************************************************************************************
14
+ }
15
+ answer = Capistrano::CLI.ui.ask(message)
16
+ abort "deployment to production was stopped" unless answer == 'y'
17
+ end
18
+ end
19
+
20
+
data/lib/handy/dump2s3.rb CHANGED
@@ -3,16 +3,22 @@ module Handy
3
3
 
4
4
  attr_accessor :bucket_name, :access_key_id, :secret_access_key, :bucket_instance
5
5
 
6
+ # This module relies on following things to be present:
7
+ #
8
+ # AppConfig.s3_bucket_name
9
+ # AppConfig.s3_secret_access_key_id
10
+ # AppConfig.s3_secret_secret_access_key
11
+ #
6
12
  def initialize(env)
7
- file = Rails.root.join('config', 'amazon_s3.yml')
8
- unless File.exists?(file)
9
- raise "file config/amazon_s3.yml was not found. Create a file as per http://gist.github.com/619432"
10
- end
11
- config = YAML.load_file(file)
12
- @bucket_name = config[env]['bucket_name']
13
- @access_key_id = config[env]['access_key_id']
14
- @secret_access_key = config[env]['secret_access_key']
13
+ @bucket_name = AppConfig.s3_bucket_name
14
+ @access_key_id = AppConfig.s3_access_key_id
15
+ @secret_access_key = AppConfig.s3_secret_access_key
15
16
  @s3_instance = Aws::S3.new(access_key_id, secret_access_key)
17
+
18
+ if @bucket_name.nil? || @access_key_id.nil? || @secret_access_key.nil?
19
+ raise "looks like aws/s3 credentials are not set properly"
20
+ end
21
+
16
22
  @bucket_instance = Aws::S3::Bucket.create(@s3_instance, bucket_name)
17
23
  begin
18
24
  @bucket_instance.keys
data/lib/handy/tasks.rb CHANGED
@@ -2,10 +2,15 @@ namespace :handy do
2
2
  namespace :web do
3
3
  desc "Ping a site"
4
4
  task :ping => :environment do
5
- puts "Usage: rake handy:web:ping site=www.xxx.com"
6
- site = ENV['site']
7
- cmd = "curl http://#{site}> /dev/null 2>&1 &"
8
- system(cmd)
5
+ begin
6
+ puts "Usage: rake handy:web:ping site=www.xxx.com"
7
+ site = ENV['site']
8
+ cmd = "curl http://#{site}> /dev/null 2>&1 &"
9
+ system(cmd)
10
+ rescue => e
11
+ HoptoadNotifier.notify(e, :parameters => {:site => site})
12
+ puts e.message.inspect + e.backtrace.join('\n')
13
+ end
9
14
  end
10
15
  end
11
16
 
@@ -13,15 +18,20 @@ namespace :handy do
13
18
 
14
19
  desc "Load schema and data from a local sql file."
15
20
  task :restore => :environment do
16
- puts "Usage: rake handy:db:restore file=xxxxxxxxx.sql[.gz]"
17
- file_name = ENV['file']
18
- raise "file was not supplied. Check Usage." unless file_name
19
- file = File.join(Rails.root, 'tmp', file_name)
20
- raise "file was not found" unless File.exists?(file)
21
- Rake::Task["db:drop"].invoke
22
- Rake::Task["db:create"].invoke
21
+ begin
22
+ puts "Usage: rake handy:db:restore file=xxxxxxxxx.sql[.gz]"
23
+ file_name = ENV['file']
24
+ raise "file was not supplied. Check Usage." unless file_name
25
+ file = File.join(Rails.root, 'tmp', file_name)
26
+ raise "file was not found" unless File.exists?(file)
27
+ Rake::Task["db:drop"].invoke
28
+ Rake::Task["db:create"].invoke
23
29
 
24
- Handy::Restore.run(file, Rails.env)
30
+ Handy::Restore.run(file, Rails.env)
31
+ rescue => e
32
+ HoptoadNotifier.notify(e, :parameters => {:file => file})
33
+ puts e.message.inspect + e.backtrace.join('\r\n')
34
+ end
25
35
  end
26
36
 
27
37
  desc <<-DESC
@@ -31,49 +41,76 @@ namespace :handy do
31
41
  Files are backed at Rails.root/../../shared/db_backups on the remote server
32
42
  DESC
33
43
  task :backup => [:environment] do
34
- timestamp = ENV['timestamp'] || Time.zone.now.strftime("%Y-%m-%d-%H-%M-%S")
35
- file = "#{timestamp}.sql"
36
- backup_dir = File.join (Rails.root, 'tmp')
37
- FileUtils.mkdir_p(backup_dir) unless File.exists?(backup_dir) && File.directory?(backup_dir)
38
- backup_file = File.join(backup_dir, "#{file}.gz")
44
+ begin
45
+ timestamp = ENV['timestamp'] || Time.zone.now.strftime("%Y-%m-%d-%H-%M-%S")
46
+ file = "#{timestamp}.sql"
47
+ backup_dir = File.join (Rails.root, 'tmp')
48
+ FileUtils.mkdir_p(backup_dir) unless File.exists?(backup_dir) && File.directory?(backup_dir)
49
+ backup_file = File.join(backup_dir, "#{file}.gz")
39
50
 
40
- Handy::Backup.run(Rails.env, file, backup_file)
51
+ Handy::Backup.run(Rails.env, file, backup_file)
52
+ rescue => e
53
+ HoptoadNotifier.notify(e, :parameters => {:file => file})
54
+ puts e.message.inspect + e.backtrace.join('\n')
55
+ end
41
56
  end
42
57
 
43
58
 
44
59
  desc "Copy production database to staging database. Or copy data from any database to any other datbase."
45
60
  task :db2db => :environment do
46
- puts "Usage: handy:db:db2db from_env=production to_env=staging"
47
- from_env = ENV['from_env'] || 'production'
48
- to_env = ENV['to_env'] || 'staging'
49
- file = "#{Rails.root}/tmp/#{from_env}.data"
61
+ begin
62
+ puts "Usage: handy:db:db2db from_env=production to_env=staging"
63
+ from_env = ENV['from_env'] || 'production'
64
+ to_env = ENV['to_env'] || 'staging'
65
+ file = "#{Rails.root}/tmp/#{from_env}.data"
50
66
 
51
- Handy::Db2db.run(from_env, to_env, file)
67
+ Handy::Db2db.run(from_env, to_env, file)
68
+ rescue => e
69
+ HoptoadNotifier.notify(e, :parameters => {:from_env => from_env, :to_env => to_env })
70
+ puts e.message.inspect + e.backtrace.join('\n')
71
+ end
52
72
  end
53
73
 
54
74
  desc "Copy database dump to s3"
55
75
  task :dump2s3 => :environment do
56
- timestamp = Time.zone.now.strftime("%Y-%m-%d-%H-%M-%S")
57
- file = "#{timestamp}.sql.gz"
58
- ENV['file'] = file
59
- Rake::Task["handy:db:backup"].invoke
76
+ begin
77
+ timestamp = Time.zone.now.strftime("%Y-%m-%d-%H-%M-%S")
78
+ file = "#{timestamp}.sql.gz"
79
+ ENV['file'] = file
80
+ Rake::Task["handy:db:backup"].invoke
60
81
 
61
- Handy::Dump2s3.run(Rails.env, file)
82
+ Handy::Dump2s3.run(Rails.env, file)
83
+ rescue => e
84
+ HoptoadNotifier.notify(e, :parameters => {:file => file})
85
+ puts e.message.inspect + e.backtrace.join('\n')
86
+ end
62
87
  end
63
88
 
64
89
  namespace :dump2s3 do
65
90
 
66
91
  desc "list all files stored at s3"
67
92
  task :list => :environment do
68
- Handy::Dump2s3.list(Rails.env)
93
+ begin
94
+ Handy::Dump2s3.list(Rails.env)
95
+ rescue => e
96
+ HoptoadNotifier.notify(e)
97
+ a = e.message.inspect
98
+ b = e.backtrace.join('\n')
99
+ puts a + b
100
+ end
69
101
  end
70
102
 
71
103
  desc "restore data from s3"
72
104
  task :restore => :environment do
73
- file = ENV['file']
74
- raise "No file was specified. Usage: rake handy:db:dump2s3:restore file=xxxx" if file.blank?
75
- Handy::Dump2s3.restore(Rails.env, file)
76
- Rake::Task["handy:db:restore"].invoke
105
+ begin
106
+ file = ENV['file']
107
+ raise "No file was specified. Usage: rake handy:db:dump2s3:restore file=xxxx" if file.blank?
108
+ Handy::Dump2s3.restore(Rails.env, file)
109
+ Rake::Task["handy:db:restore"].invoke
110
+ rescue => e
111
+ HoptoadNotifier.notify(e, :parameters => {:file => file})
112
+ puts e.message.inspect + e.backtrace.join('\n')
113
+ end
77
114
  end
78
115
 
79
116
  end
data/lib/handy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Handy
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.9'
3
3
  end
data/lib/handy.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'aws'
2
- #require 'aws/s3'
3
2
 
4
3
  require 'handy/util'
5
4
  require 'handy/backup'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Neeraj Singh
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-31 00:00:00 -04:00
18
+ date: 2011-02-19 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -65,6 +65,7 @@ files:
65
65
  - Rakefile
66
66
  - lib/handy.rb
67
67
  - lib/handy/backup.rb
68
+ - lib/handy/capistrano/user_confirmation.rb
68
69
  - lib/handy/db2db.rb
69
70
  - lib/handy/dump2s3.rb
70
71
  - lib/handy/railtie.rb
@@ -80,8 +81,8 @@ homepage: http://github.com/neerajdotname/handy
80
81
  licenses: []
81
82
 
82
83
  post_install_message:
83
- rdoc_options:
84
- - --charset=UTF-8
84
+ rdoc_options: []
85
+
85
86
  require_paths:
86
87
  - lib
87
88
  required_ruby_version: !ruby/object:Gem::Requirement