ruby-s3cmd-anfleene 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ commit dc9430c54968dd5c0d9ec665f7d12c4fa0be142a
2
+ Author: Joel Bryan Juliano <jjuliano@clinic-it.com>
3
+ Date: Tue Dec 28 15:11:50 2010 +0800
4
+
5
+ Fix comments and documentations
6
+
7
+ commit 8e2c880131ea108695d6f8dd9e59cca0973c58ec
8
+ Author: Joel Bryan Juliano <jjuliano@clinic-it.com>
9
+ Date: Tue Dec 28 13:09:10 2010 +0800
10
+
11
+ Removed the yardoc documentations
12
+
13
+ commit 447bf1cb796f3601ba1809e09045f443d724dbee
14
+ Author: Joel Bryan Juliano <jjuliano@clinic-it.com>
15
+ Date: Tue Dec 28 12:29:02 2010 +0800
16
+
17
+ Added yardoc API documentation
18
+
19
+ commit 20174fe74c38d47dc7b5ae5d9d673e68ca085a2c
20
+ Author: Joel Bryan Juliano <jjuliano@clinic-it.com>
21
+ Date: Tue Dec 28 12:27:27 2010 +0800
22
+
23
+ bump to version 0.1.1
24
+
25
+ commit 914690cbaee71217f78deeb48a204ffe8c098bcc
26
+ Author: Joel Bryan Juliano <jjuliano@clinic-it.com>
27
+ Date: Tue Dec 28 11:55:44 2010 +0800
28
+
29
+ changed the version module name
30
+
31
+ commit f1655df0fd2b0fa0e7b313d6140814220f468654
32
+ Author: Joel Bryan Juliano <jjuliano@clinic-it.com>
33
+ Date: Mon Dec 27 19:52:32 2010 +0000
34
+
35
+ Added basic usage instructions
36
+
37
+ commit dcda2467fc9f4b51807ac94898f252454500ad7f
38
+ Author: Joel Bryan Juliano <jjuliano@clinic-it.com>
39
+ Date: Mon Dec 27 19:15:24 2010 +0000
40
+
41
+ Added github page as homepage in gemspec
42
+
43
+ commit 164d7524024ec1f7ccd9d308943b3d8790a61316
44
+ Author: Joel Bryan Juliano <jjuliano@clinic-it.com>
45
+ Date: Mon Dec 27 19:10:30 2010 +0000
46
+
47
+ Initial Commit
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Joel Bryan Juliano <joelbryan.juliano@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,19 @@
1
+ README for ruby-s3cmd
2
+ =====================
3
+
4
+ Ruby-s3cmd is a gem providing a ruby interface to s3cmd Amazon S3 client.
5
+
6
+ To install, type 'gem install ruby-s3cmd'
7
+
8
+ Usage:
9
+
10
+ require 'rubygems'
11
+ require 'ruby-s3cmd'
12
+
13
+ s3cmd = RubyS3Cmd::S3Cmd.new
14
+ s3cmd.exclude = "*.jpg"
15
+ s3cmd.rinclude = "[0-9].*.jpg"
16
+ s3cmd.show_config
17
+ => "s3cmd --exclude *.jpg --rinclude [0-9].*.jpg "
18
+ s3cmd.sync("/local/path", "s3://test-bucket/backup/")
19
+
@@ -0,0 +1,12 @@
1
+ # = ruby-s3cmd - A gem providing a ruby interface to s3cmd Amazon S3 client.
2
+ #
3
+ # Homepage:: http://github.com/jjuliano/ruby-s3cmd
4
+ # Author:: Joel Bryan Juliano
5
+ # Copyright:: (cc) 2011 Joel Bryan Juliano
6
+ # License:: MIT
7
+ #
8
+
9
+ require 'tempfile'
10
+
11
+ Dir[File.join(File.dirname(__FILE__), 'ruby-s3cmd/**/*.rb')].sort.reverse.each { |lib| require lib }
12
+
@@ -0,0 +1,391 @@
1
+ # = ruby-s3cmd - A gem providing a ruby interface to s3cmd Amazon S3 client.
2
+ #
3
+ # Homepage:: http://github.com/jjuliano/ruby-s3cmd
4
+ # Author:: Joel Bryan Juliano
5
+ # Copyright:: (cc) 2011 Joel Bryan Juliano
6
+ # License:: MIT
7
+ #
8
+
9
+ #
10
+ # class RubyS3CMD::S3Cmd.new( array, str, array)
11
+ #
12
+ class RubyS3Cmd::S3Cmd
13
+
14
+ #
15
+ # Options common for all commands (where it makes sense indeed)
16
+ #
17
+
18
+ #
19
+ # Recursive upload, download or removal. When used with del it can remove all the files in a bucket.
20
+ #
21
+ attr_accessor :recursive
22
+
23
+ #
24
+ # Force overwrite and other dangerous operations. Can be used to remove a non-empty buckets with s3cmd
25
+ # rb --force s3://bkt
26
+ #
27
+ attr_accessor :force
28
+
29
+ #
30
+ # Specify datacentre where to create the bucket. Possible values are US (default) or EU.
31
+ #
32
+ attr_accessor :bucket_location
33
+
34
+ #
35
+ # Print sizes in human readable form.
36
+ #
37
+ attr_accessor :human_readable_sizes
38
+
39
+ #
40
+ # Include MD5 sums in bucket listings (only for ls command).
41
+ #
42
+ attr_accessor :list_md5
43
+
44
+ #
45
+ # Display or don't display progress meter. When running on TTY (e.g. console or xterm) the default is
46
+ # to display progress meter. If not on TTY (e.g. output is redirected somewhere or running from cron)
47
+ # the default is to not display progress meter.
48
+ #
49
+ attr_accessor :progress, :no_progress
50
+
51
+ #
52
+ # Override autodetected terminal and filesystem encoding (character set).
53
+ #
54
+ attr_accessor :encoding
55
+
56
+ #
57
+ # Enable verbose output.
58
+ #
59
+ attr_accessor :verbose
60
+
61
+ #
62
+ # Enable debug output.
63
+ #
64
+ attr_accessor :debug
65
+
66
+ #
67
+ # Config file related options.
68
+ #
69
+
70
+ #
71
+ # Config file name. Defaults to $HOME/.s3cfg
72
+ #
73
+ attr_accessor :config
74
+
75
+ #
76
+ # Options specific for file transfer commands (sync, put and get):
77
+ #
78
+
79
+ #
80
+ # Only show what should be uploaded or downloaded but don't actually do it. May still perform S3
81
+ # requests to get bucket listings and other in formation though.
82
+ #
83
+ attr_accessor :dry_run
84
+
85
+ #
86
+ # Delete remote objects with no corresponding local file when syncing to S3 or delete local files with
87
+ # no corresponding object in S3 when syncing from S3.
88
+ #
89
+ attr_accessor :delete_removed
90
+
91
+ #
92
+ # Don't delete remote objects. Default for sync command.
93
+ #
94
+ attr_accessor :no_delete_removed
95
+
96
+ #
97
+ # Preserve filesystem attributes (mode, ownership, timestamps). Default for sync command.
98
+ #
99
+ attr_accessor :preserve
100
+
101
+ #
102
+ # Don't store filesystem attributes with uploaded files.
103
+ #
104
+ attr_accessor :no_preserve
105
+
106
+ #
107
+ # Exclude files matching GLOB (a.k.a. shell-style wildcard) from sync. See FILE TRANSFERS section and
108
+ # http://s3tools.org/s3cmd-sync for more information.
109
+ #
110
+ attr_accessor :exclude # GLOB
111
+
112
+ #
113
+ # Same as --exclude but reads GLOBs from the given FILE instead of expecting them on the command line.
114
+ #
115
+ attr_accessor :exclude_from # FILE
116
+
117
+ #
118
+ # Same as --exclude but works with REGEXPs (Regular expressions).
119
+ #
120
+ attr_accessor :rexclude # REGEXP
121
+
122
+ #
123
+ # Same as --exclude-from but works with REGEXPs.
124
+ #
125
+ attr_accessor :rexclude_from # FILE
126
+
127
+ #
128
+ # Filenames and paths matching GLOB or REGEXP will be included even if previously excluded by one of
129
+ # --(r)exclude(-from) patterns
130
+ #
131
+ attr_accessor :include # GLOB
132
+ attr_accessor :include_from # FILE
133
+ attr_accessor :rinclude # REGEXP
134
+ attr_accessor :rinclude_from # FILE
135
+
136
+ #
137
+ # Continue getting a partially downloaded file (only for get command). This comes handy once download
138
+ # of a large file, say an ISO image, from a S3 bucket fails and a partially downloaded file is left on
139
+ # the disk. Unfortunately put command doesn't support restarting of failed upload due to Amazon S3
140
+ # limitations.
141
+ #
142
+ attr_accessor :continue
143
+
144
+ #
145
+ # Skip over files that exist at the destination (only for get and sync commands).
146
+ #
147
+ attr_accessor :skip_existing
148
+
149
+ #
150
+ # Default MIME-type to be set for objects stored.
151
+ #
152
+ attr_accessor :mime_type # MIME/TYPE
153
+
154
+ #
155
+ # Guess MIME‐type of files by their extension. Falls back to default MIME‐Type as specified by
156
+ # --mime-type option
157
+ #
158
+ attr_accessor :guess_mime_type
159
+
160
+ #
161
+ # Add a given HTTP header to the upload request. Can be used multiple times with different header
162
+ # names. For instance set 'Expires' or 'Cache-Control' headers (or both) using this options if you
163
+ # like.
164
+ #
165
+ attr_accessor :add_header # NAME:VALUE
166
+
167
+ #
168
+ # Store objects with permissions allowing read for anyone. See http://s3tools.org/s3cmd-public for
169
+ # details and hints for storing publicly accessible files.
170
+ #
171
+ attr_accessor :acl_public
172
+
173
+ #
174
+ # Store objects with default ACL allowing access for you only.
175
+ #
176
+ attr_accessor :acl_private
177
+
178
+ #
179
+ # Use GPG encryption to protect stored objects from unauthorized access. See http://s3tools.org/s3cmd-
180
+ # public for details about encryption.
181
+ #
182
+ attr_accessor :encrypt
183
+
184
+ #
185
+ # Don't encrypt files.
186
+ #
187
+ attr_accessor :no_encrypt
188
+
189
+ #
190
+ # Options for CloudFront commands
191
+ #
192
+ # See http://s3tools.org/s3cmd-cloudfront for more details.
193
+ #
194
+
195
+ #
196
+ # Enable given CloudFront distribution (only for cfmodify command)
197
+ #
198
+ attr_accessor :enable
199
+
200
+ #
201
+ # Enable given CloudFront distribution (only for cfmodify command)
202
+ #
203
+ attr_accessor :disable
204
+
205
+ #
206
+ # Add given CNAME to a CloudFront distribution (only for cfcreate and cfmodify commands)
207
+ #
208
+ attr_accessor :cf_add_cname # CNAME
209
+
210
+ #
211
+ # Remove given CNAME from a CloudFront distribution (only for cfmodify command)
212
+ #
213
+ attr_accessor :cf_remove_cname # CNAME
214
+
215
+ #
216
+ # Set COMMENT for a given CloudFront distribution (only for cfcreate and cfmodify commands)
217
+ #
218
+ attr_accessor :cf_comment # COMMENT
219
+
220
+ #
221
+ # Sets the executable path, otherwise the environment path will be used.
222
+ #
223
+ attr_accessor :path_to_s3cmd
224
+
225
+ #
226
+ # Show the help message and exit
227
+ #
228
+ def help
229
+ send_command "--help"
230
+ end
231
+
232
+ #
233
+ # Show s3cmd version and exit.
234
+ #
235
+ def version
236
+ send_command "--version"
237
+ end
238
+
239
+ #
240
+ # Invoke interactive (re)configuration tool. Don't worry, you won't lose your settings on subsequent
241
+ # runs.
242
+ #
243
+ def configure
244
+ send_command "--configure"
245
+ end
246
+
247
+ #
248
+ # Dump current configuration after parsing config files and command line options and exit.
249
+ #
250
+ def dump_config
251
+ send_command "--dump-config"
252
+ end
253
+
254
+ # Make bucket
255
+ def mb(bucket) # s3://BUCKET
256
+ send_command "mb", bucket
257
+ end
258
+
259
+ # Remove bucket
260
+ def rb(bucket) # s3://BUCKET
261
+ send_command "rb", bucket
262
+ end
263
+
264
+ # List objects or buckets
265
+ def ls(bucket) # s3://BUCKET[/PREFIX]]
266
+ send_command "ls", bucket
267
+ end
268
+
269
+ # List all object in all buckets
270
+ def la
271
+ send_command "la"
272
+ end
273
+
274
+ # Put file into bucket (i.e. upload to S3)
275
+ def put(files, bucket) # FILE [FILE...] s3://BUCKET[/PREFIX]
276
+ send_command "put", files, bucket
277
+ end
278
+
279
+ # Get file from bucket (i.e. download from S3)
280
+ def get(bucket, local_file=nil) # s3://BUCKET/OBJECT LOCAL_FILE
281
+ send_command "get", bucket, local_file
282
+ end
283
+
284
+ # Delete file from bucket
285
+ def del(bucket) # s3://BUCKET/OBJECT
286
+ send_command "del"
287
+ end
288
+
289
+ # Backup a directory tree to S3
290
+ # Restore a tree from S3 to local directory
291
+ def sync(src_object, dest_object=nil) # LOCAL_DIR s3://BUCKET[/PREFIX] or s3://BUCKET[/PREFIX] LOCAL_DIR
292
+ send_command "sync", src_object, dest_object
293
+ end
294
+
295
+ # Make a copy of a file (cp) or move a file (mv). Destination can be in the same bucket with a dif‐
296
+ # ferent name or in another bucket with the same or different name. Adding --acl-public will make the
297
+ # destination object publicly accessible (see below).
298
+ def cp(src_bucket, dest_bucket) # s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]
299
+ send_command "cp", src_bucket, dest_bucket
300
+ end
301
+
302
+ # Make a copy of a file (cp) or move a file (mv). Destination can be in the same bucket with a dif‐
303
+ # ferent name or in another bucket with the same or different name. Adding --acl-public will make the
304
+ # destination object publicly accessible (see below).
305
+ def mv(src_bucket, dest_bucket) # s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]
306
+ send_command "mv", src_bucket, dest_bucket
307
+ end
308
+
309
+ # Modify Access control list for Bucket or Files. Use with --acl-public or --acl-private
310
+ def setacl(bucket) # s3://BUCKET[/OBJECT]
311
+ send_command "setacl", bucket
312
+ end
313
+
314
+ # Get various information about a Bucket or Object
315
+ def info(bucket) # s3://BUCKET[/OBJECT]
316
+ send_command "info", bucket
317
+ end
318
+
319
+ # Disk usage - amount of data stored in S3
320
+ def du(bucket) # [s3://BUCKET[/PREFIX]]
321
+ send_command "du", bucket
322
+ end
323
+
324
+ # Commands for CloudFront management
325
+
326
+ # List CloudFront distribution points
327
+ def cflist
328
+ send_command "cflist"
329
+ end
330
+
331
+ # Display CloudFront distribution point parameters
332
+ def cfinfo(dist_id) # [cf://DIST_ID]
333
+ send_command "cfinfo", dist_id
334
+ end
335
+
336
+ # Create CloudFront distribution point
337
+ def cfcreate(bucket) # s3://BUCKET
338
+ send_command "cfcreate", bucket
339
+ end
340
+
341
+ # Delete CloudFront distribution point
342
+ def cfdelete(dist_id) # cf://DIST_ID
343
+ send_command "cfdelete", dist_id
344
+ end
345
+
346
+ # Change CloudFront distribution point parameters
347
+ def cfmodify(dist_id) # cf://DIST_ID
348
+ send_command "cfmodify", dist_id
349
+ end
350
+
351
+ def send_command(*command)
352
+ tmp = Tempfile.new('tmp')
353
+ success = system("#{option_string + command.join(" ") } > #{tmp.path}")
354
+ return tmp.readlines.map(&:chomp) if success
355
+ tmp.close!
356
+
357
+ success
358
+ end
359
+
360
+ def show_config
361
+ option_string
362
+ end
363
+
364
+ private
365
+
366
+ def option_string()
367
+
368
+ unless @path_to_s3cmd
369
+ ostring = "s3cmd "
370
+ else
371
+ ostring = @path_to_s3cmd + " "
372
+ end
373
+
374
+ self.instance_variables.each do |i|
375
+ tmp_value = self.instance_variable_get "#{i}"
376
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
377
+ unless tmp_string == "--path-to-s3cmd"
378
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
379
+ ostring += "#{tmp_string} "
380
+ else
381
+ ostring += "#{tmp_string} #{tmp_value} "
382
+ end
383
+ end
384
+ end
385
+
386
+ return ostring
387
+
388
+ end
389
+
390
+ end
391
+