sdbcli 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sdbcli +50 -26
- data/bin/sdbcli.orig +188 -0
- data/lib/sdbcli/sdb-runner.rb.orig +29 -3
- metadata +4 -3
data/bin/sdbcli
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$LOAD_PATH << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
|
3
3
|
|
4
|
-
Version = '0.3.
|
4
|
+
Version = '0.3.9'
|
5
5
|
HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.sdbcli_history')
|
6
6
|
HISTSIZE = 500
|
7
7
|
|
@@ -40,39 +40,58 @@ end
|
|
40
40
|
|
41
41
|
def execute(src, show_rows = false)
|
42
42
|
ss = StringScanner.new(src.dup)
|
43
|
+
buf = ''
|
44
|
+
|
45
|
+
until ss.eos?
|
46
|
+
if (tok = ss.scan %r{[^-`'";\\/#]+})
|
47
|
+
buf << tok
|
48
|
+
elsif (tok = ss.scan /`(?:[^`]|``)*`/)
|
49
|
+
buf << tok
|
50
|
+
elsif (tok = ss.scan /'(?:[^']|'')*'/) #'
|
51
|
+
buf << tok
|
52
|
+
elsif (tok = ss.scan /"(?:[^"]|"")*"/) #"
|
53
|
+
buf << tok
|
54
|
+
elsif (tok = ss.scan %r{/\*/?(\n|[^/]|[^*]/)*\*/})
|
55
|
+
# nothing to do
|
56
|
+
elsif (tok = ss.scan /--[^\r\n]*(?:\r\n|\r|\n|\Z)/)
|
57
|
+
# nothing to do
|
58
|
+
elsif (tok = ss.scan /#[^\r\n]*(?:\r\n|\r|\n|\Z)/)
|
59
|
+
# nothing to do
|
60
|
+
elsif (tok = ss.scan /(?:;|\\G)/)
|
61
|
+
src.replace(ss.rest)
|
62
|
+
query = buf
|
63
|
+
buf = ''
|
64
|
+
|
65
|
+
if tok == '\G'
|
66
|
+
inline = false
|
67
|
+
else
|
68
|
+
inline = true
|
69
|
+
end
|
43
70
|
|
44
|
-
|
45
|
-
|
46
|
-
|
71
|
+
if query.strip.empty?
|
72
|
+
output_error('No query specified')
|
73
|
+
next
|
74
|
+
end
|
47
75
|
|
48
|
-
|
49
|
-
query = query.sub(/\s*\\G\Z/i, '')
|
50
|
-
inline = false
|
51
|
-
else
|
52
|
-
query = query.strip.sub(/\s*;\Z/, '')
|
53
|
-
inline = true
|
54
|
-
end
|
76
|
+
out = $runner.execute(query, inline)
|
55
77
|
|
56
|
-
|
57
|
-
|
58
|
-
next
|
59
|
-
end
|
78
|
+
if out
|
79
|
+
str = YAML.dump(out).sub(/(?:\r\n|\r|\n)*\Z/, "\n")
|
60
80
|
|
61
|
-
|
81
|
+
if show_rows and out.kind_of?(Array)
|
82
|
+
str << "# #{out.length} #{out.length > 1 ? 'rows' : 'row'} in set\n"
|
83
|
+
end
|
62
84
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
if show_rows and out.kind_of?(Array)
|
67
|
-
str << "# #{out.length} rows in set\n"
|
85
|
+
str << "\n"
|
86
|
+
puts str
|
68
87
|
end
|
69
|
-
|
70
|
-
|
71
|
-
puts str
|
88
|
+
elsif (tok = ss.scan /./)
|
89
|
+
buf << tok
|
72
90
|
end
|
73
91
|
end
|
74
92
|
|
75
|
-
|
93
|
+
src.replace(buf.strip)
|
94
|
+
buf
|
76
95
|
end
|
77
96
|
|
78
97
|
if not $stdin.tty? or command
|
@@ -177,7 +196,12 @@ while buf = Readline.readline(prompt, true)
|
|
177
196
|
rv = nil
|
178
197
|
|
179
198
|
begin
|
180
|
-
src
|
199
|
+
if src.empty?
|
200
|
+
src << buf
|
201
|
+
else
|
202
|
+
src << ("\n" + buf)
|
203
|
+
end
|
204
|
+
|
181
205
|
execute(src, true)
|
182
206
|
rescue => e
|
183
207
|
output_error e.message.strip
|
data/bin/sdbcli.orig
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
|
3
|
+
|
4
|
+
Version = '0.3.8'
|
5
|
+
HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.sdbcli_history')
|
6
|
+
HISTSIZE = 500
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'sdbcli'
|
10
|
+
|
11
|
+
require 'optparse'
|
12
|
+
require 'readline'
|
13
|
+
require 'strscan'
|
14
|
+
require 'syck' if /\A1\.9/ =~ RUBY_VERSION
|
15
|
+
require 'yaml'
|
16
|
+
|
17
|
+
access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
18
|
+
secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
19
|
+
sdb_endpoint = ENV['SDB_ENDPOINT'] || ENV['REGION_NAME'] || 'sdb.amazonaws.com'
|
20
|
+
command = nil
|
21
|
+
|
22
|
+
ARGV.options do |opt|
|
23
|
+
opt.on('-k', '--access-key=ACCESS_KEY') {|v| access_key_id = v }
|
24
|
+
opt.on('-s', '--secret-key=SECRET_KEY') {|v| secret_access_key = v }
|
25
|
+
opt.on('-r', '--region=REGION') {|v| sdb_endpoint = v }
|
26
|
+
opt.on('-e', '--eval=COMMAND') {|v| command = v }
|
27
|
+
opt.parse!
|
28
|
+
|
29
|
+
unless access_key_id and secret_access_key and sdb_endpoint
|
30
|
+
puts opt.help
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
$runner = SimpleDB::Runner.new(access_key_id, secret_access_key, sdb_endpoint)
|
36
|
+
|
37
|
+
def output_error(msg)
|
38
|
+
$stderr.puts "# #{msg}\n\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute(src, show_rows = false)
|
42
|
+
ss = StringScanner.new(src.gsub(%r{/\*/?(?:(?:\r\n|\r|\n)|[^/]|[^*]/)*\*/}m, ''))
|
43
|
+
|
44
|
+
while query = ss.scan_until(/(?:;|\\G)/i)
|
45
|
+
src.replace(ss.rest.strip)
|
46
|
+
query.strip!
|
47
|
+
|
48
|
+
if query =~ /\s*\\G\Z/i
|
49
|
+
query = query.sub(/\s*\\G\Z/i, '')
|
50
|
+
inline = false
|
51
|
+
else
|
52
|
+
query = query.strip.sub(/\s*;\Z/, '')
|
53
|
+
inline = true
|
54
|
+
end
|
55
|
+
|
56
|
+
if query.empty?
|
57
|
+
output_error('No query specified')
|
58
|
+
next
|
59
|
+
end
|
60
|
+
|
61
|
+
out = $runner.execute(query, inline)
|
62
|
+
|
63
|
+
if out
|
64
|
+
str = YAML.dump(out).sub(/(?:\r\n|\r|\n)*\Z/, "\n")
|
65
|
+
|
66
|
+
if show_rows and out.kind_of?(Array)
|
67
|
+
str << "# #{out.length} rows in set\n"
|
68
|
+
end
|
69
|
+
|
70
|
+
str << "\n"
|
71
|
+
puts str
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
ss.rest.strip
|
76
|
+
end
|
77
|
+
|
78
|
+
if not $stdin.tty? or command
|
79
|
+
src = command || $stdin.read.strip
|
80
|
+
|
81
|
+
unless src =~ /\s*(?:;|\\G)\Z/i
|
82
|
+
src << ';'
|
83
|
+
end
|
84
|
+
|
85
|
+
begin
|
86
|
+
execute(src)
|
87
|
+
exit 0
|
88
|
+
rescue => e
|
89
|
+
output_error e.message.strip
|
90
|
+
exit 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def help
|
95
|
+
<<-EOS
|
96
|
+
SHOW DOMAINS
|
97
|
+
displays a domain list
|
98
|
+
|
99
|
+
SHOW REGIONS
|
100
|
+
displays a region list
|
101
|
+
|
102
|
+
CREATE domain domain_name
|
103
|
+
creates a domain
|
104
|
+
|
105
|
+
DROP DOMAIN domain_name
|
106
|
+
deletes a domain
|
107
|
+
|
108
|
+
GET [attr_list] FROM domain_name WHERE itemName = '...'
|
109
|
+
gets the attribute of an item
|
110
|
+
|
111
|
+
INSERT INTO domain_name (itemName, attr1, ...) VALUES ('name', 'val1', ...)
|
112
|
+
creates an item
|
113
|
+
|
114
|
+
UPDATE domain_name set attr1 = 'val1', ... WHERE itemName = '...'
|
115
|
+
updates an item
|
116
|
+
|
117
|
+
DELETE [attr1, ...] FROM domain_name WHERE itemName = '...'
|
118
|
+
deletes the attribute of an item or an item
|
119
|
+
|
120
|
+
SELECT output_list FROM domain_name [WHERE expression] [sort_instructions] [LIMIT limit]
|
121
|
+
queries using the SELECT statement
|
122
|
+
see http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/UsingSelect.html
|
123
|
+
|
124
|
+
DESC domain_name
|
125
|
+
displays information about the domain
|
126
|
+
|
127
|
+
USE region_or_endpoint
|
128
|
+
changes an endpoint
|
129
|
+
|
130
|
+
EOS
|
131
|
+
end
|
132
|
+
|
133
|
+
if File.exist?(HISTORY_FILE)
|
134
|
+
open(HISTORY_FILE) do |f|
|
135
|
+
f.each_line do |line|
|
136
|
+
line = line.strip
|
137
|
+
Readline::HISTORY.push(line) unless line.empty?
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
at_exit do
|
143
|
+
unless Readline::HISTORY.empty?
|
144
|
+
open(HISTORY_FILE, 'wb') do |f|
|
145
|
+
(Readline::HISTORY.to_a.slice(-(Readline::HISTORY.length < HISTSIZE ? Readline::HISTORY.length : HISTSIZE)..-1) || []).each do |line|
|
146
|
+
next if /\A\s*\Z/ =~ line
|
147
|
+
f.puts line
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
src = ''
|
154
|
+
prompt1 = lambda { "#{$runner.region || 'unknown'}> " }
|
155
|
+
prompt2 = lambda { "#{' ' * (($runner.region || 'unknown').length - 1)}-> " }
|
156
|
+
prompt = prompt1.call
|
157
|
+
|
158
|
+
while buf = Readline.readline(prompt, true)
|
159
|
+
if /\A\s*\Z/ =~ buf
|
160
|
+
Readline::HISTORY.pop
|
161
|
+
next
|
162
|
+
end
|
163
|
+
|
164
|
+
if src.empty? and buf =~ /\A\.(.+)/
|
165
|
+
r = /\A#{Regexp.compile($1.downcase)}/
|
166
|
+
|
167
|
+
if r =~ 'help'
|
168
|
+
puts help
|
169
|
+
elsif r =~ 'exit' or r =~ 'quit'
|
170
|
+
exit
|
171
|
+
elsif r =~ 'version'
|
172
|
+
puts "sdbcli #{Version}"
|
173
|
+
else
|
174
|
+
output_error('Unknown command')
|
175
|
+
end
|
176
|
+
else
|
177
|
+
rv = nil
|
178
|
+
|
179
|
+
begin
|
180
|
+
src << (' ' + buf)
|
181
|
+
execute(src, true)
|
182
|
+
rescue => e
|
183
|
+
output_error e.message.strip
|
184
|
+
end
|
185
|
+
|
186
|
+
prompt = src.empty? ? prompt1.call : prompt2.call
|
187
|
+
end
|
188
|
+
end
|
@@ -10,14 +10,14 @@ module SimpleDB
|
|
10
10
|
'sdb.us-west-2.amazonaws.com' => 'us-west-2',
|
11
11
|
'sdb.eu-west-1.amazonaws.com' => 'eu-west-1',
|
12
12
|
'sdb.ap-southeast-1.amazonaws.com' => 'ap-southeast-1',
|
13
|
+
'sdb.ap-southeast-2.amazonaws.com' => 'ap-southeast-2',
|
13
14
|
'sdb.ap-northeast-1.amazonaws.com' => 'ap-northeast-1',
|
14
15
|
'sdb.sa-east-1.amazonaws.com' => 'sa-east-1',
|
15
16
|
}
|
16
17
|
|
17
18
|
class Runner
|
18
|
-
attr_reader :driver
|
19
|
-
|
20
19
|
def initialize(accessKeyId, secretAccessKey, endpoint = 'sdb.amazonaws.com')
|
20
|
+
endpoint = region_to_endpoint(endpoint)
|
21
21
|
@driver = Driver.new(accessKeyId, secretAccessKey, endpoint)
|
22
22
|
end
|
23
23
|
|
@@ -26,6 +26,7 @@ module SimpleDB
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def endpoint=(v)
|
29
|
+
v = region_to_endpoint(v)
|
29
30
|
@driver.endpoint = v
|
30
31
|
end
|
31
32
|
|
@@ -35,6 +36,7 @@ module SimpleDB
|
|
35
36
|
|
36
37
|
def execute(query, inline = true)
|
37
38
|
parsed = Parser.parse(query)
|
39
|
+
p parsed
|
38
40
|
command = parsed.class.name.split('::').last.to_sym
|
39
41
|
|
40
42
|
case command
|
@@ -72,12 +74,36 @@ module SimpleDB
|
|
72
74
|
@driver.drop_domain(parsed.domain)
|
73
75
|
nil
|
74
76
|
when :SHOW
|
75
|
-
|
77
|
+
case parsed.operand
|
78
|
+
when :domains
|
79
|
+
@driver.show_domains
|
80
|
+
when :regions
|
81
|
+
SimpleDB::REGIONS.values.sort
|
82
|
+
else
|
83
|
+
raise 'must not happen'
|
84
|
+
end
|
85
|
+
when :USE
|
86
|
+
self.endpoint = parsed.endpoint
|
87
|
+
nil
|
76
88
|
when :DESCRIBE
|
77
89
|
@driver.describe(parsed.domain)
|
78
90
|
else
|
79
91
|
raise 'must not happen'
|
80
92
|
end
|
81
93
|
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def region_to_endpoint(region)
|
98
|
+
if /\A[^.]+\Z/ =~ region
|
99
|
+
region = SimpleDB::REGIONS.find {|k, v| v == region }
|
100
|
+
raise SimpleDB::Error, 'Unknown region' unless region
|
101
|
+
region = region.first
|
102
|
+
end
|
103
|
+
|
104
|
+
raise SimpleDB::Error, 'Unknown endpoint' unless SimpleDB::REGIONS[region]
|
105
|
+
|
106
|
+
return region
|
107
|
+
end
|
82
108
|
end # Runner
|
83
109
|
end # SimpleDB
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdbcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 9
|
10
|
+
version: 0.3.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- winebarrel
|
@@ -42,6 +42,7 @@ extra_rdoc_files: []
|
|
42
42
|
files:
|
43
43
|
- README
|
44
44
|
- bin/sdbcli
|
45
|
+
- bin/sdbcli.orig
|
45
46
|
- lib/sdbcli/sdb-client.rb
|
46
47
|
- lib/sdbcli/sdb-driver.rb
|
47
48
|
- lib/sdbcli/sdb-parser.tab.rb
|