sdbcli 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
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.5'
4
+ Version = '0.3.6'
5
5
  HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.sdbcli_history')
6
6
  HISTSIZE = 500
7
7
 
@@ -95,7 +95,7 @@ module SimpleDB
95
95
 
96
96
  def region_to_endpoint(region)
97
97
  if /\A[^.]+\Z/ =~ region
98
- region = SimpleDB::REGIONS.key(region)
98
+ region = SimpleDB::REGIONS[region]
99
99
  raise SimpleDB::Error, 'Unknown region' unless region
100
100
  end
101
101
 
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: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 5
10
- version: 0.3.5
9
+ - 6
10
+ version: 0.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel
@@ -42,7 +42,6 @@ extra_rdoc_files: []
42
42
  files:
43
43
  - README
44
44
  - bin/sdbcli
45
- - bin/sdbcli.orig
46
45
  - lib/sdbcli/sdb-client.rb
47
46
  - lib/sdbcli/sdb-driver.rb
48
47
  - lib/sdbcli/sdb-parser.tab.rb
data/bin/sdbcli.orig DELETED
@@ -1,208 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $LOAD_PATH << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
3
-
4
- Version = '0.3.1'
5
- HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.sdbcli_history')
6
-
7
- require 'rubygems'
8
- require 'sdbcli'
9
-
10
- require 'optparse'
11
- require 'readline'
12
- require 'strscan'
13
- require 'syck' if /\A1\.9/ =~ RUBY_VERSION
14
- require 'yaml'
15
-
16
- access_key_id = ENV['AWS_ACCESS_KEY_ID']
17
- secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
18
- sdb_endpoint = ENV['SDB_ENDPOINT'] || ENV['REGION_NAME'] || 'sdb.amazonaws.com'
19
- command = nil
20
- enable_completion = false
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.on('', '--enable-comp') { enable_completion = true }
28
- opt.parse!
29
-
30
- unless access_key_id and secret_access_key and sdb_endpoint
31
- puts opt.help
32
- exit 1
33
- end
34
- end
35
-
36
- if /\A[^.]+\Z/ =~ sdb_endpoint
37
- if sdb_endpoint == 'us-east-1'
38
- sdb_endpoint = 'sdb.amazonaws.com'
39
- else
40
- sdb_endpoint = "sdb.#{sdb_endpoint}.amazonaws.com"
41
- end
42
- end
43
-
44
- $runner = SimpleDB::Runner.new(access_key_id, secret_access_key, sdb_endpoint)
45
-
46
- def output_error(msg)
47
- $stderr.puts "ERROR: #{msg}\n\n"
48
- end
49
-
50
- def execute(src, show_rows = false)
51
- ss = StringScanner.new(src.dup)
52
-
53
- while query = ss.scan_until(/(?:;|\\G)/i)
54
- src.replace(ss.rest.strip)
55
- query.strip!
56
-
57
- if query =~ /\s*\\G\Z/i
58
- query = query.sub(/\s*\\G\Z/i, '')
59
- inline = false
60
- else
61
- query = query.strip.sub(/\s*;\Z/, '')
62
- inline = true
63
- end
64
-
65
- if query.empty?
66
- output_error('No query specified')
67
- next
68
- end
69
-
70
- out = $runner.execute(query, inline)
71
-
72
- if out
73
- str = YAML.dump(out).sub(/(?:\r\n|\r|\n)*\Z/, "\n")
74
-
75
- if show_rows and out.kind_of?(Array)
76
- str << "# #{out.length} rows in set\n"
77
- end
78
-
79
- str << "\n"
80
- puts str
81
- end
82
- end
83
-
84
- ss.rest.strip
85
- end
86
-
87
- if not $stdin.tty? or command
88
- src = command || $stdin.read.strip
89
-
90
- unless src =~ /\s*(?:;|\\G)\Z/i
91
- src << ';'
92
- end
93
-
94
- begin
95
- execute(src)
96
- exit 0
97
- rescue Racc::ParseError
98
- output_error 'Parse error'
99
- exit 1
100
- rescue => e
101
- output_error e.message.strip
102
- exit 1
103
- end
104
- end
105
-
106
- def help
107
- <<-EOS
108
- SHOW domains
109
- displays a domain list
110
-
111
- CREATE domain domain_name
112
- creates a domain
113
-
114
- DROP DOMAIN domain_name
115
- deletes a domain
116
-
117
- GET [attr_list] FROM domain_name WHERE itemName = '...'
118
- gets the attribute of an item
119
-
120
- INSERT INTO domain_name (itemName, attr1, ...) values ('name', 'val1', ...)
121
- creates an item
122
-
123
- UPDATE domain_name set attr1 = 'val1', ... where itemName = '...'
124
- updates an item
125
-
126
- DELETE [attr1, ...] FROM domain_name itemName = '...'
127
- deletes the attribute of an item or an item
128
-
129
- SELECT output_list FROM domain_name [where expression] [sort_instructions] [limit limit]
130
- queries using the SELECT statement
131
-
132
- DESC domain_name
133
- displays information about the domain;
134
-
135
- EOS
136
- end
137
-
138
- if File.exist?(HISTORY_FILE)
139
- open(HISTORY_FILE) do |f|
140
- f.each_line do |line|
141
- line = line.strip
142
- Readline::HISTORY.push(line) unless line.empty?
143
- end
144
- end
145
- end
146
-
147
- at_exit do
148
- unless Readline::HISTORY.empty?
149
- open(HISTORY_FILE, 'wb') do |f|
150
- Readline::HISTORY.each do |line|
151
- next if /\A\s*\Z/ =~ line
152
- f.puts line
153
- end
154
- end
155
- end
156
- end
157
-
158
- src = ''
159
- region = $runner.region || 'unknown'
160
- prompt1 = "#{region}> "
161
- prompt2 = "#{' ' * (region.length - 1)}-> "
162
- prompt = prompt1
163
-
164
- $keywords = SimpleDB::Parser::KEYWORDS + ['SELECT', 'COUNT(*)', 'itemName']
165
- $keywords.delete('ITEMNAME')
166
-
167
- begin
168
- $runner.driver.show_domains.each {|i| $keywords << i }
169
- rescue Exception
170
- end
171
-
172
- Readline.completion_proc = proc {|word|
173
- $keywords.grep(/\A#{Regexp.quote word}/i)
174
- }
175
-
176
- while buf = Readline.readline(prompt, true)
177
- if /\A\s*\Z/ =~ buf
178
- Readline::HISTORY.pop
179
- next
180
- end
181
-
182
- if src.empty? and buf =~ /\A\.(.+)/
183
- r = /\A#{Regexp.compile($1.downcase)}/
184
-
185
- if r =~ 'help'
186
- puts help
187
- elsif r =~ 'exit' or r =~ 'quit'
188
- exit
189
- elsif r =~ 'version'
190
- puts "sdbcli #{Version}"
191
- else
192
- output_error('Unknown command')
193
- end
194
- else
195
- rv = nil
196
-
197
- begin
198
- src << (' ' + buf)
199
- execute(src, true)
200
- rescue Racc::ParseError
201
- output_error 'Parse error'
202
- rescue => e
203
- output_error e.message.strip
204
- end
205
-
206
- prompt = src.empty? ? prompt1 : prompt2
207
- end
208
- end