s3cp 1.0.0 → 1.0.1

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.
@@ -1,3 +1,13 @@
1
+ === 1.0.1 / 2012-03-9
2
+
3
+ * Added: New command `s3up` to upload STDIN to S3
4
+ e.g. some_cmd | s3up s3://bucket/path/to/destination
5
+
6
+ Note: `s3up` does not yet directly stream data to S3 since right_aws gem
7
+ requires the upload size to be known in advance. `s3up` currently
8
+ persists STDIN into a temp file although this may change in the
9
+ future.
10
+
1
11
  === 1.0.0 / 2012-03-9
2
12
 
3
13
  Pop the champagne! It's time we called this a one-oh!! :)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 's3cp/s3up'
3
+
@@ -0,0 +1,100 @@
1
+ # Copyright (C) 2010-2012 Alex Boisvert and Bizo Inc. / All rights reserved.
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one or more contributor
4
+ # license agreements. See the NOTICE file distributed with this work for
5
+ # additional information regarding copyright ownership. The ASF licenses this
6
+ # file to you under the Apache License, Version 2.0 (the "License"); you may not
7
+ # use this file except in compliance with the License. You may obtain a copy of
8
+ # the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations under
16
+ # the License.
17
+
18
+ require 'rubygems'
19
+ require 'extensions/kernel' if RUBY_VERSION =~ /1.8/
20
+ require 'right_aws'
21
+ require 'optparse'
22
+ require 'tempfile'
23
+
24
+ require 's3cp/utils'
25
+
26
+ # Parse arguments
27
+ options = {}
28
+ options[:tty] = $stdout.isatty
29
+ options[:headers] = []
30
+
31
+ op = OptionParser.new do |opts|
32
+ opts.banner = "s3up [s3_path]"
33
+ opts.separator ''
34
+ opts.separator 'Uploads data from STDIN to S3.'
35
+
36
+ opts.on('--headers \'Header1: Header1Value\',\'Header2: Header2Value\'', Array, "Headers to set on the item in S3." ) do |h|
37
+ options[:headers] = h
38
+ end
39
+
40
+ opts.separator " e.g.,"
41
+ opts.separator " HTTP headers: \'Content-Type: image/jpg\'"
42
+ opts.separator " AMZ headers: \'x-amz-acl: public-read\'"
43
+ opts.separator ""
44
+
45
+ opts.on_tail("-h", "--help", "Show this message") do
46
+ puts op
47
+ exit
48
+ end
49
+ end
50
+ op.parse!(ARGV)
51
+
52
+ unless ARGV.size > 0
53
+ puts op
54
+ exit
55
+ end
56
+
57
+ def headers_array_to_hash(header_array)
58
+ headers = {}
59
+ header_array.each do |header|
60
+ header_parts = header.split(": ", 2)
61
+ if header_parts.size == 2
62
+ headers[header_parts[0].downcase] = header_parts[1] # RightAWS gem expect lowercase header names :(
63
+ else
64
+ log("Header ignored because of error splitting [#{header}]. Expected colon delimiter; e.g. Header: Value")
65
+ end
66
+ end
67
+ headers
68
+ end
69
+ @headers = headers_array_to_hash(options[:headers])
70
+
71
+ url = ARGV[0]
72
+
73
+ bucket, key = S3CP.bucket_and_key(url)
74
+ fail "Your URL looks funny, doesn't it?" unless bucket
75
+
76
+ @s3 = S3CP.connect()
77
+
78
+ # copy all of STDIN to a temp file
79
+ temp = Tempfile.new('s3cp')
80
+ f = File.new("newfile2.zip", "wb")
81
+ while true
82
+ begin
83
+ data = STDIN.sysread(4 * 1024)
84
+ temp.syswrite(data)
85
+ rescue EOFError => e
86
+ break
87
+ end
88
+ end
89
+ temp.close
90
+ temp.open
91
+
92
+ # upload temp file
93
+ begin
94
+ @s3.interface.put(bucket, key, temp, @headers)
95
+ ensure
96
+ # cleanup
97
+ temp.close
98
+ temp.delete
99
+ end
100
+
@@ -16,5 +16,5 @@
16
16
  # the License.
17
17
 
18
18
  module S3CP
19
- VERSION = "1.0.0"
19
+ VERSION = "1.0.1"
20
20
  end
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Boisvert
@@ -141,6 +141,7 @@ executables:
141
141
  - s3mod
142
142
  - s3rm
143
143
  - s3stat
144
+ - s3up
144
145
  extensions: []
145
146
 
146
147
  extra_rdoc_files:
@@ -154,6 +155,7 @@ files:
154
155
  - lib/s3cp/s3stat.rb
155
156
  - lib/s3cp/s3cp.rb
156
157
  - lib/s3cp/utils.rb
158
+ - lib/s3cp/s3up.rb
157
159
  - lib/s3cp/s3mod.rb
158
160
  - lib/s3cp/s3cat.rb
159
161
  - lib/s3cp/completion.rb
@@ -161,6 +163,7 @@ files:
161
163
  - README.md
162
164
  - bin/s3mod
163
165
  - bin/s3ls
166
+ - bin/s3up
164
167
  - bin/s3cp
165
168
  - bin/s3cp_complete
166
169
  - bin/s3stat