s3cp 1.1.9 → 1.1.10
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/History.txt +5 -0
- data/bin/s3edit +4 -0
- data/bin/s3edit~ +4 -0
- data/lib/s3cp/s3cat.rb +24 -3
- data/lib/s3cp/s3cp.rb +4 -17
- data/lib/s3cp/utils.rb +14 -0
- data/lib/s3cp/version.rb +1 -1
- metadata +33 -30
data/History.txt
CHANGED
data/bin/s3edit
ADDED
data/bin/s3edit~
ADDED
data/lib/s3cp/s3cat.rb
CHANGED
@@ -35,6 +35,10 @@ op = OptionParser.new do |opts|
|
|
35
35
|
options[:tty] = tty
|
36
36
|
end
|
37
37
|
|
38
|
+
opts.on("--edit", "Edit mode") do |edit|
|
39
|
+
options[:edit] = edit
|
40
|
+
end
|
41
|
+
|
38
42
|
opts.on_tail("-h", "--help", "Show this message") do
|
39
43
|
puts op
|
40
44
|
exit
|
@@ -61,7 +65,7 @@ S3CP.load_config()
|
|
61
65
|
|
62
66
|
@s3 = S3CP.connect().buckets[@bucket]
|
63
67
|
|
64
|
-
if options[:tty]
|
68
|
+
if options[:tty] || options[:edit]
|
65
69
|
# store contents to file to display with PAGER
|
66
70
|
size = @s3.objects[@prefix].content_length
|
67
71
|
|
@@ -69,7 +73,7 @@ if options[:tty]
|
|
69
73
|
p.file_transfer_mode
|
70
74
|
end
|
71
75
|
|
72
|
-
file = Tempfile.new('
|
76
|
+
file = Tempfile.new(File.basename(@prefix) + '_')
|
73
77
|
out = File.new(file.path, "wb")
|
74
78
|
begin
|
75
79
|
@s3.objects[@prefix].read_as_stream do |chunk|
|
@@ -80,7 +84,24 @@ if options[:tty]
|
|
80
84
|
ensure
|
81
85
|
out.close()
|
82
86
|
end
|
83
|
-
|
87
|
+
if options[:edit]
|
88
|
+
before_md5 = S3CP.md5(file.path)
|
89
|
+
system "#{ENV['EDITOR'] || 'vi'} #{file.path}"
|
90
|
+
if ($? == 0)
|
91
|
+
if (S3CP.md5(file.path) != before_md5)
|
92
|
+
ARGV.clear
|
93
|
+
ARGV << file.path
|
94
|
+
ARGV << url
|
95
|
+
load "s3cp/s3cp.rb"
|
96
|
+
else
|
97
|
+
puts "File unchanged."
|
98
|
+
end
|
99
|
+
else
|
100
|
+
puts "Edit aborted (result code #{$?})."
|
101
|
+
end
|
102
|
+
else
|
103
|
+
system "#{ENV['PAGER'] || 'less'} #{file.path}"
|
104
|
+
end
|
84
105
|
file.delete()
|
85
106
|
else
|
86
107
|
@s3.objects[@prefix].read_as_stream do |chunk|
|
data/lib/s3cp/s3cp.rb
CHANGED
@@ -237,19 +237,6 @@ def with_headers(msg)
|
|
237
237
|
msg
|
238
238
|
end
|
239
239
|
|
240
|
-
def md5(filename)
|
241
|
-
digest = Digest::MD5.new()
|
242
|
-
file = File.open(filename, 'r')
|
243
|
-
begin
|
244
|
-
file.each_line do |line|
|
245
|
-
digest << line
|
246
|
-
end
|
247
|
-
ensure
|
248
|
-
file.close()
|
249
|
-
end
|
250
|
-
digest.hexdigest
|
251
|
-
end
|
252
|
-
|
253
240
|
def operation(options)
|
254
241
|
operation = "Copy"
|
255
242
|
operation = "Move" if options[:move]
|
@@ -275,7 +262,7 @@ def local_to_s3(bucket_to, key, file, options = {})
|
|
275
262
|
log(with_headers("#{operation(options)} #{file} to s3://#{bucket_to}/#{key}"))
|
276
263
|
|
277
264
|
expected_md5 = if options[:checksum] || options[:sync]
|
278
|
-
md5(file)
|
265
|
+
S3CP.md5(file)
|
279
266
|
end
|
280
267
|
|
281
268
|
actual_md5 = if options[:sync]
|
@@ -378,7 +365,7 @@ def s3_to_local(bucket_from, key_from, dest, options = {})
|
|
378
365
|
end
|
379
366
|
|
380
367
|
actual_md5 = if options[:sync] && File.exist?(dest)
|
381
|
-
md5(dest)
|
368
|
+
S3CP.md5(dest)
|
382
369
|
end
|
383
370
|
|
384
371
|
if !options[:sync] || (expected_md5 != actual_md5)
|
@@ -411,14 +398,14 @@ def s3_to_local(bucket_from, key_from, dest, options = {})
|
|
411
398
|
end
|
412
399
|
|
413
400
|
if options[:checksum] && expected_md5 != nil
|
414
|
-
actual_md5 = md5(dest)
|
401
|
+
actual_md5 = S3CP.md5(dest)
|
415
402
|
if actual_md5 != expected_md5
|
416
403
|
STDERR.puts "Warning: invalid MD5 checksum. Expected: #{expected_md5} Actual: #{actual_md5}"
|
417
404
|
end
|
418
405
|
end
|
419
406
|
|
420
407
|
retries += 1
|
421
|
-
end until options[:checksum] == false || expected_md5.nil? || md5(dest) == expected_md5
|
408
|
+
end until options[:checksum] == false || expected_md5.nil? || S3CP.md5(dest) == expected_md5
|
422
409
|
|
423
410
|
@s3.buckets[bucket_from].objects[key_from].delete() if options[:move]
|
424
411
|
end
|
data/lib/s3cp/utils.rb
CHANGED
@@ -96,6 +96,20 @@ module S3CP
|
|
96
96
|
(n * (10.0 ** decimals)).round * (10.0 ** (-decimals))
|
97
97
|
end
|
98
98
|
|
99
|
+
# Calculate the MD5 checksum for the given file
|
100
|
+
def md5(filename)
|
101
|
+
digest = Digest::MD5.new()
|
102
|
+
file = File.open(filename, 'r')
|
103
|
+
begin
|
104
|
+
file.each_line do |line|
|
105
|
+
digest << line
|
106
|
+
end
|
107
|
+
ensure
|
108
|
+
file.close()
|
109
|
+
end
|
110
|
+
digest.hexdigest
|
111
|
+
end
|
112
|
+
|
99
113
|
# Return a formatted string for a file size.
|
100
114
|
#
|
101
115
|
# Valid units are "b" (bytes), "kb" (kilobytes), "mb" (megabytes),
|
data/lib/s3cp/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3cp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 10
|
10
|
+
version: 1.1.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Boisvert
|
@@ -15,11 +15,9 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-12-13 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
prerelease: false
|
22
|
-
name: extensions
|
23
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
22
|
none: false
|
25
23
|
requirements:
|
@@ -32,9 +30,9 @@ dependencies:
|
|
32
30
|
version: "0.6"
|
33
31
|
requirement: *id001
|
34
32
|
type: :runtime
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
33
|
prerelease: false
|
37
|
-
name:
|
34
|
+
name: extensions
|
35
|
+
- !ruby/object:Gem::Dependency
|
38
36
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
37
|
none: false
|
40
38
|
requirements:
|
@@ -48,9 +46,9 @@ dependencies:
|
|
48
46
|
version: 1.5.1
|
49
47
|
requirement: *id002
|
50
48
|
type: :runtime
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
49
|
prerelease: false
|
53
|
-
name:
|
50
|
+
name: highline
|
51
|
+
- !ruby/object:Gem::Dependency
|
54
52
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
53
|
none: false
|
56
54
|
requirements:
|
@@ -64,9 +62,9 @@ dependencies:
|
|
64
62
|
version: 1.6.3
|
65
63
|
requirement: *id003
|
66
64
|
type: :runtime
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
65
|
prerelease: false
|
69
|
-
name:
|
66
|
+
name: aws-sdk
|
67
|
+
- !ruby/object:Gem::Dependency
|
70
68
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
69
|
none: false
|
72
70
|
requirements:
|
@@ -80,9 +78,9 @@ dependencies:
|
|
80
78
|
version: 0.10.0
|
81
79
|
requirement: *id004
|
82
80
|
type: :runtime
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
81
|
prerelease: false
|
85
|
-
name:
|
82
|
+
name: progressbar
|
83
|
+
- !ruby/object:Gem::Dependency
|
86
84
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
85
|
none: false
|
88
86
|
requirements:
|
@@ -96,9 +94,9 @@ dependencies:
|
|
96
94
|
version: 2.5.0
|
97
95
|
requirement: *id005
|
98
96
|
type: :development
|
99
|
-
- !ruby/object:Gem::Dependency
|
100
97
|
prerelease: false
|
101
|
-
name:
|
98
|
+
name: rspec
|
99
|
+
- !ruby/object:Gem::Dependency
|
102
100
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
103
101
|
none: false
|
104
102
|
requirements:
|
@@ -112,6 +110,8 @@ dependencies:
|
|
112
110
|
version: 0.8.7
|
113
111
|
requirement: *id006
|
114
112
|
type: :development
|
113
|
+
prerelease: false
|
114
|
+
name: rake
|
115
115
|
description:
|
116
116
|
email:
|
117
117
|
- alex.boisvert@gmail.com
|
@@ -122,6 +122,7 @@ executables:
|
|
122
122
|
- s3cp_complete
|
123
123
|
- s3dir
|
124
124
|
- s3du
|
125
|
+
- s3edit
|
125
126
|
- s3ls
|
126
127
|
- s3mod
|
127
128
|
- s3mv
|
@@ -135,34 +136,36 @@ extra_rdoc_files:
|
|
135
136
|
- README.md
|
136
137
|
- History.txt
|
137
138
|
files:
|
138
|
-
- lib/s3cp/
|
139
|
+
- lib/s3cp/s3cat.rb
|
140
|
+
- lib/s3cp/s3tree.rb
|
139
141
|
- lib/s3cp/s3ls.rb
|
140
|
-
- lib/s3cp/version.rb
|
141
142
|
- lib/s3cp/s3du.rb
|
142
143
|
- lib/s3cp/s3mod.rb
|
143
|
-
- lib/s3cp/
|
144
|
-
- lib/s3cp/s3tree.rb
|
145
|
-
- lib/s3cp/s3cp.rb
|
146
|
-
- lib/s3cp/s3cat.rb
|
144
|
+
- lib/s3cp/completion.rb
|
147
145
|
- lib/s3cp/s3buckets.rb
|
148
|
-
- lib/s3cp/
|
146
|
+
- lib/s3cp/version.rb
|
147
|
+
- lib/s3cp/s3cp.rb
|
149
148
|
- lib/s3cp/s3stat.rb
|
149
|
+
- lib/s3cp/utils.rb
|
150
|
+
- lib/s3cp/s3rm.rb
|
150
151
|
- lib/s3cp/s3up.rb
|
151
152
|
- History.txt
|
152
153
|
- README.md
|
153
|
-
- bin/
|
154
|
-
- bin/s3mv
|
155
|
-
- bin/s3rm
|
154
|
+
- bin/s3edit~
|
156
155
|
- bin/s3dir
|
156
|
+
- bin/s3mv
|
157
|
+
- bin/s3cat
|
158
|
+
- bin/s3ls
|
159
|
+
- bin/s3edit
|
157
160
|
- bin/s3buckets
|
161
|
+
- bin/s3tree
|
158
162
|
- bin/s3mod
|
159
|
-
- bin/
|
160
|
-
- bin/s3cat
|
163
|
+
- bin/s3up
|
161
164
|
- bin/s3cp_complete
|
165
|
+
- bin/s3du
|
162
166
|
- bin/s3cp
|
163
|
-
- bin/
|
167
|
+
- bin/s3rm
|
164
168
|
- bin/s3stat
|
165
|
-
- bin/s3tree
|
166
169
|
homepage:
|
167
170
|
licenses: []
|
168
171
|
|