snatchdb 1.0.1 → 1.0.2
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/snatch +17 -1
- data/lib/snatch.rb +10 -0
- data/lib/snatch/session.rb +5 -1
- data/lib/snatch/version.rb +1 -1
- metadata +2 -2
data/bin/snatch
CHANGED
@@ -39,6 +39,22 @@ optparse = OptionParser.new do |opts|
|
|
39
39
|
File.open(file, 'w') { |f| f.write(SAMPLE_SCHEMA) }
|
40
40
|
puts "File #{file} has been created. Edit and snatch!" ; exit
|
41
41
|
end
|
42
|
+
|
43
|
+
opts.on('-l', '--list', 'List all available config files') do
|
44
|
+
files = Dir[File.join(Snatch.root, '*.yml')]
|
45
|
+
|
46
|
+
unless files.empty?
|
47
|
+
puts "Configuration files:"
|
48
|
+
files.each do |path|
|
49
|
+
puts " - #{File.basename(path, '.yml')}" if Snatch.valid_config?(path)
|
50
|
+
end
|
51
|
+
puts "TIP: Just type 'snatch NAME' and i will download that database."
|
52
|
+
else
|
53
|
+
puts "No available configs are available."
|
54
|
+
end
|
55
|
+
|
56
|
+
exit
|
57
|
+
end
|
42
58
|
end
|
43
59
|
|
44
60
|
begin
|
@@ -68,6 +84,6 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
|
68
84
|
exit
|
69
85
|
rescue Interrupt
|
70
86
|
puts "Interrupted."
|
71
|
-
rescue StandardError, Snatch::CredentialsError, Snatch::NoDatabaseError => ex
|
87
|
+
rescue StandardError, Snatch::CredentialsError, Snatch::NoServiceError, Snatch::NoDatabaseError => ex
|
72
88
|
puts "ERROR: #{ex.message}"
|
73
89
|
end
|
data/lib/snatch.rb
CHANGED
@@ -15,4 +15,14 @@ module Snatch
|
|
15
15
|
s = Snatch::Session.new(config)
|
16
16
|
s.run!
|
17
17
|
end
|
18
|
+
|
19
|
+
# Returns true if snatch config is valid
|
20
|
+
def self.valid_config?(path)
|
21
|
+
data = YAML.load_file(path)
|
22
|
+
if data.kind_of?(Hash)
|
23
|
+
(data.keys & ['host']).size == 1
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
18
28
|
end
|
data/lib/snatch/session.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Snatch
|
2
2
|
class CredentialsError < Exception ; end
|
3
|
-
class NoDatabaseError
|
3
|
+
class NoDatabaseError < Exception ; end
|
4
|
+
class NoServiceError < Exception ; end
|
4
5
|
|
5
6
|
class Session
|
6
7
|
attr_reader :config, :filename
|
@@ -42,6 +43,9 @@ module Snatch
|
|
42
43
|
|
43
44
|
# Check configuration options
|
44
45
|
def test
|
46
|
+
raise NoServiceError, "No mysql found." unless @ssh.exec!("which mysql") =~ /mysql/i
|
47
|
+
raise NoServiceError, "No mysqldump found." unless @ssh.exec!("which mysqldump") =~ /mysqldump/i
|
48
|
+
|
45
49
|
resp = @ssh.exec!("mysql --execute='SHOW DATABASES;' --user=#{@config[:db_user]} --password=#{@config[:db_password]}")
|
46
50
|
if resp =~ /ERROR 1045/
|
47
51
|
raise CredentialsError, 'Invalid MySQL user or password'
|
data/lib/snatch/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: snatchdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan Sosedoff
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-23 00:00:00 -05:00
|
14
14
|
default_executable: snatch
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|