ath 0.1.9 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8939b048b2425519025c650b50603dd3d565c04
4
- data.tar.gz: 33353d8d4dd31d11f0d18e19e19b32a2c4bf7213
3
+ metadata.gz: 21a47438e2f1e99a854aa23c1bd7301e217e3266
4
+ data.tar.gz: 014b49b565e36d3ca64e4e5f3c7c5ab1de54e0b1
5
5
  SHA512:
6
- metadata.gz: d6d15ebfccc697c9c9c48f67e1ff75f464dbdd76a5cdb6aa932b04e8b1850d352db7051980dd94bfbf2afc181a72325d84a9d34bd4304766e83c285f1495af17
7
- data.tar.gz: 4f1fae796e638899475bc0a1f9af55e072373833a91ddf641068719dc762a6ec9f024ec09b037d2312babf3339c8de9f631a99aefcccc8007208a742d413c877
6
+ metadata.gz: e59acba379c679e781eef4a4324e38a8ff5b69962d91c6fa4bd5abda578405dbbe8dfa1848a590251e25ec813ce3335f72df4a83e144171474f68e20a549c743
7
+ data.tar.gz: faa08d22bb15c6bcad6fbe1477ade5b1247e1bc57c52823358bf286dc62e9db2f766882d607c8437ba1985d8cc4b3babcded8c2f2c36bd44d7d3cdf10ed9874a
@@ -0,0 +1,2 @@
1
+ elb_logs
2
+ elb_logs2
data/README.md CHANGED
@@ -98,6 +98,7 @@ default> /help
98
98
  /pager PAGER
99
99
  /region [REGION]
100
100
  /result QUERY_EXECUTION_ID
101
+ /save QUERY_EXECUTION_ID [PATH]
101
102
  /stop QUERY_EXECUTION_ID
102
103
  /use DATABASE
103
104
  ```
data/lib/ath/command.rb CHANGED
@@ -76,6 +76,15 @@ class Ath::Command
76
76
  else
77
77
  out = "Usage: /result QUERY_EXECUTION_ID"
78
78
  end
79
+ when 'save'
80
+ if @arg
81
+ query_execution_id, path = @arg.split(/\s+/, 2)
82
+ path ||= Dir.pwd
83
+ path = @shell.driver.save_query_execution_result(query_execution_id: query_execution_id, path: path)
84
+ out = "Save to #{path}"
85
+ else
86
+ out = "Usage: /result QUERY_EXECUTION_ID [PATH]"
87
+ end
79
88
  when 'stop'
80
89
  if @arg
81
90
  @shell.driver.stop_query_execution(query_execution_id: @arg)
@@ -107,6 +116,7 @@ class Ath::Command
107
116
  /pager PAGER
108
117
  /region [REGION]
109
118
  /result QUERY_EXECUTION_ID
119
+ /save QUERY_EXECUTION_ID [PATH]
110
120
  /stop QUERY_EXECUTION_ID
111
121
  /use DATABASE
112
122
  EOS
data/lib/ath/driver.rb CHANGED
@@ -19,10 +19,26 @@ class Ath::Driver
19
19
  end
20
20
 
21
21
  def get_query_execution_result(query_execution_id:)
22
- query_execution = @athena.get_query_execution(query_execution_id: query_execution_id).query_execution
23
- output_location = query_execution.result_configuration.output_location
24
- bucket, key = output_location.sub(%r{\As3://}, '').split('/', 2)
25
22
  tmp = Tempfile.create('ath')
23
+ bucket, key = get_query_execution_result_output_location(query_execution_id: query_execution_id)
24
+ download_query_execution_result(bucket: bucket, key: key, file: tmp)
25
+ end
26
+
27
+ def save_query_execution_result(query_execution_id:, path:)
28
+ bucket, key = get_query_execution_result_output_location(query_execution_id: query_execution_id)
29
+
30
+ if File.directory?(path)
31
+ path = File.join(path, File.basename(key))
32
+ end
33
+
34
+ open(path, 'wb') do |file|
35
+ download_query_execution_result(bucket: bucket, key: key, file: file)
36
+ end
37
+
38
+ path
39
+ end
40
+
41
+ def download_query_execution_result(bucket:, key:, file:)
26
42
  head = @s3.head_object(bucket: bucket, key: key)
27
43
 
28
44
  if @options[:progress] and head.content_length >= 1024 ** 2
@@ -30,7 +46,7 @@ class Ath::Driver
30
46
 
31
47
  begin
32
48
  @s3.get_object(bucket: bucket, key: key) do |chunk|
33
- tmp.write(chunk)
49
+ file.write(chunk)
34
50
 
35
51
  begin
36
52
  download_progressbar.progress += chunk.length
@@ -43,12 +59,18 @@ class Ath::Driver
43
59
  end
44
60
  else
45
61
  @s3.get_object(bucket: bucket, key: key) do |chunk|
46
- tmp.write(chunk)
62
+ file.write(chunk)
47
63
  end
48
64
  end
49
65
 
50
- tmp.flush
51
- tmp
66
+ file.flush
67
+ file
68
+ end
69
+
70
+ def get_query_execution_result_output_location(query_execution_id:)
71
+ query_execution = @athena.get_query_execution(query_execution_id: query_execution_id).query_execution
72
+ output_location = query_execution.result_configuration.output_location
73
+ output_location.sub(%r{\As3://}, '').split('/', 2)
52
74
  end
53
75
 
54
76
  def start_query_execution(query_string:)
data/lib/ath/scanner.rb CHANGED
@@ -8,7 +8,7 @@ class Ath::Scanner
8
8
  ss = StringScanner.new(line)
9
9
 
10
10
  if self.empty? and (tok = ss.scan %r{/\w+(?:\s+.*)?\z})
11
- cmd, arg = tok.split(/\s+/, 2)
11
+ cmd, arg = tok.strip.split(/\s+/, 2)
12
12
  cmd.slice!(0)
13
13
  arg.strip! if arg
14
14
  yield(Ath::Command.new(shell: @shell, command: cmd, arg: arg))
data/lib/ath/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ath
2
- VERSION = '0.1.9'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
@@ -97,6 +97,7 @@ files:
97
97
  - ".gitignore"
98
98
  - ".rspec"
99
99
  - ".travis.yml"
100
+ - 22b39199-4070-4100-abed-c7bb63c13d3b.txt
100
101
  - Gemfile
101
102
  - LICENSE.txt
102
103
  - README.md