ruby-s3cmd 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ruby-s3cmd/s3cmd.rb +36 -385
  2. metadata +3 -8
@@ -222,56 +222,18 @@
222
222
  #
223
223
  attr_accessor :path_to_s3cmd
224
224
 
225
- #
226
- # Returns a new RubyS3CMD::S3Cmd Object
227
- #
228
- def initialize()
229
- end
230
-
231
225
  #
232
226
  # Show the help message and exit
233
227
  #
234
228
  def help
235
- tmp = Tempfile.new('tmp')
236
- command = option_string() + "--help " + " 2> " + tmp.path
237
- success = system(command)
238
- if success
239
- begin
240
- while (line = tmp.readline)
241
- line.chomp
242
- selected_string = line
243
- end
244
- rescue EOFError
245
- tmp.close
246
- end
247
- return selected_string
248
- else
249
- tmp.close!
250
- return success
251
- end
229
+ send_command "--help"
252
230
  end
253
231
 
254
232
  #
255
233
  # Show s3cmd version and exit.
256
234
  #
257
235
  def version
258
- tmp = Tempfile.new('tmp')
259
- command = option_string() + "--version " + " 2> " + tmp.path
260
- success = system(command)
261
- if success
262
- begin
263
- while (line = tmp.readline)
264
- line.chomp
265
- selected_string = line
266
- end
267
- rescue EOFError
268
- tmp.close
269
- end
270
- return selected_string
271
- else
272
- tmp.close!
273
- return success
274
- end
236
+ send_command "--version"
275
237
  end
276
238
 
277
239
  #
@@ -279,440 +241,129 @@
279
241
  # runs.
280
242
  #
281
243
  def configure
282
- tmp = Tempfile.new('tmp')
283
- command = option_string() + "--configure " + " 2> " + tmp.path
284
- success = system(command)
285
- if success
286
- begin
287
- while (line = tmp.readline)
288
- line.chomp
289
- selected_string = line
290
- end
291
- rescue EOFError
292
- tmp.close
293
- end
294
- return selected_string
295
- else
296
- tmp.close!
297
- return success
298
- end
244
+ send_command "--configure"
299
245
  end
300
246
 
301
247
  #
302
248
  # Dump current configuration after parsing config files and command line options and exit.
303
249
  #
304
250
  def dump_config
305
- tmp = Tempfile.new('tmp')
306
- command = option_string() + "--dump-config " + " 2> " + tmp.path
307
- success = system(command)
308
- if success
309
- begin
310
- while (line = tmp.readline)
311
- line.chomp
312
- selected_string = line
313
- end
314
- rescue EOFError
315
- tmp.close
316
- end
317
- return selected_string
318
- else
319
- tmp.close!
320
- return success
321
- end
251
+ send_command "--dump-config"
322
252
  end
323
253
 
324
254
  # Make bucket
325
255
  def mb(bucket) # s3://BUCKET
326
- tmp = Tempfile.new('tmp')
327
- command = option_string() + "mb " + bucket.to_s + " 2> " + tmp.path
328
- success = system(command)
329
- if success
330
- begin
331
- while (line = tmp.readline)
332
- line.chomp
333
- selected_string = line
334
- end
335
- rescue EOFError
336
- tmp.close
337
- end
338
- return selected_string
339
- else
340
- tmp.close!
341
- return success
342
- end
256
+ send_command "mb", bucket
343
257
  end
344
258
 
345
259
  # Remove bucket
346
260
  def rb(bucket) # s3://BUCKET
347
- tmp = Tempfile.new('tmp')
348
- command = option_string() + "rb " + bucket.to_s + " 2> " + tmp.path
349
- success = system(command)
350
- if success
351
- begin
352
- while (line = tmp.readline)
353
- line.chomp
354
- selected_string = line
355
- end
356
- rescue EOFError
357
- tmp.close
358
- end
359
- return selected_string
360
- else
361
- tmp.close!
362
- return success
363
- end
261
+ send_command "rb", bucket
364
262
  end
365
263
 
366
264
  # List objects or buckets
367
265
  def ls(bucket) # s3://BUCKET[/PREFIX]]
368
- tmp = Tempfile.new('tmp')
369
- command = option_string() + "ls " + bucket.to_s + " 2> " + tmp.path
370
- success = system(command)
371
- if success
372
- begin
373
- while (line = tmp.readline)
374
- line.chomp
375
- selected_string = line
376
- end
377
- rescue EOFError
378
- tmp.close
379
- end
380
- return selected_string
381
- else
382
- tmp.close!
383
- return success
384
- end
266
+ send_command "ls", bucket
385
267
  end
386
268
 
387
269
  # List all object in all buckets
388
270
  def la
389
- tmp = Tempfile.new('tmp')
390
- command = option_string() + "la " + " 2> " + tmp.path
391
- success = system(command)
392
- if success
393
- begin
394
- while (line = tmp.readline)
395
- line.chomp
396
- selected_string = line
397
- end
398
- rescue EOFError
399
- tmp.close
400
- end
401
- return selected_string
402
- else
403
- tmp.close!
404
- return success
405
- end
271
+ send_command "la"
406
272
  end
407
273
 
408
274
  # Put file into bucket (i.e. upload to S3)
409
275
  def put(files, bucket) # FILE [FILE...] s3://BUCKET[/PREFIX]
410
- tmp = Tempfile.new('tmp')
411
- command = option_string() + "put " + files.to_s + " " + bucket.to_s + " 2> " + tmp.path
412
- success = system(command)
413
- if success
414
- begin
415
- while (line = tmp.readline)
416
- line.chomp
417
- selected_string = line
418
- end
419
- rescue EOFError
420
- tmp.close
421
- end
422
- return selected_string
423
- else
424
- tmp.close!
425
- return success
426
- end
276
+ send_command "put", files, bucket
427
277
  end
428
278
 
429
279
  # Get file from bucket (i.e. download from S3)
430
- def get(bucket, local_file) # s3://BUCKET/OBJECT LOCAL_FILE
431
- tmp = Tempfile.new('tmp')
432
- command = option_string() + "get " + bucket.to_s + " " + local_file.to_s + " 2> " + tmp.path
433
- success = system(command)
434
- if success
435
- begin
436
- while (line = tmp.readline)
437
- line.chomp
438
- selected_string = line
439
- end
440
- rescue EOFError
441
- tmp.close
442
- end
443
- return selected_string
444
- else
445
- tmp.close!
446
- return success
447
- end
280
+ def get(bucket, local_file=nil) # s3://BUCKET/OBJECT LOCAL_FILE
281
+ send_command "get", bucket, local_file
448
282
  end
449
283
 
450
284
  # Delete file from bucket
451
285
  def del(bucket) # s3://BUCKET/OBJECT
452
- tmp = Tempfile.new('tmp')
453
- command = option_string() + "del " + bucket.to_s + " 2> " + tmp.path
454
- success = system(command)
455
- if success
456
- begin
457
- while (line = tmp.readline)
458
- line.chomp
459
- selected_string = line
460
- end
461
- rescue EOFError
462
- tmp.close
463
- end
464
- return selected_string
465
- else
466
- tmp.close!
467
- return success
468
- end
286
+ send_command "del"
469
287
  end
470
288
 
471
289
  # Backup a directory tree to S3
472
290
  # Restore a tree from S3 to local directory
473
- def sync(src_object, dest_object) # LOCAL_DIR s3://BUCKET[/PREFIX] or s3://BUCKET[/PREFIX] LOCAL_DIR
474
- tmp = Tempfile.new('tmp')
475
- command = option_string() + "sync " + src_object.to_s + " " + dest_object.to_s + " 2> " + tmp.path
476
- success = system(command)
477
- if success
478
- begin
479
- while (line = tmp.readline)
480
- line.chomp
481
- selected_string = line
482
- end
483
- rescue EOFError
484
- tmp.close
485
- end
486
- return selected_string
487
- else
488
- tmp.close!
489
- return success
490
- end
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
491
293
  end
492
294
 
493
295
  # Make a copy of a file (cp) or move a file (mv). Destination can be in the same bucket with a dif‐
494
296
  # ferent name or in another bucket with the same or different name. Adding --acl-public will make the
495
297
  # destination object publicly accessible (see below).
496
298
  def cp(src_bucket, dest_bucket) # s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]
497
- tmp = Tempfile.new('tmp')
498
- command = option_string() + "cp " + src_bucket.to_s + " " + dest_bucket.to_s + " 2> " + tmp.path
499
- success = system(command)
500
- if success
501
- begin
502
- while (line = tmp.readline)
503
- line.chomp
504
- selected_string = line
505
- end
506
- rescue EOFError
507
- tmp.close
508
- end
509
- return selected_string
510
- else
511
- tmp.close!
512
- return success
513
- end
299
+ send_command "cp", src_bucket, dest_bucket
514
300
  end
515
301
 
516
302
  # Make a copy of a file (cp) or move a file (mv). Destination can be in the same bucket with a dif‐
517
303
  # ferent name or in another bucket with the same or different name. Adding --acl-public will make the
518
304
  # destination object publicly accessible (see below).
519
305
  def mv(src_bucket, dest_bucket) # s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]
520
- tmp = Tempfile.new('tmp')
521
- command = option_string() + "mv " + src_bucket.to_s + " " + dest_bucket.to_s + " 2> " + tmp.path
522
- success = system(command)
523
- if success
524
- begin
525
- while (line = tmp.readline)
526
- line.chomp
527
- selected_string = line
528
- end
529
- rescue EOFError
530
- tmp.close
531
- end
532
- return selected_string
533
- else
534
- tmp.close!
535
- return success
536
- end
306
+ send_command "mv", src_bucket, dest_bucket
537
307
  end
538
308
 
539
309
  # Modify Access control list for Bucket or Files. Use with --acl-public or --acl-private
540
310
  def setacl(bucket) # s3://BUCKET[/OBJECT]
541
- tmp = Tempfile.new('tmp')
542
- command = option_string() + "setacl " + bucket.to_s + " 2> " + tmp.path
543
- success = system(command)
544
- if success
545
- begin
546
- while (line = tmp.readline)
547
- line.chomp
548
- selected_string = line
549
- end
550
- rescue EOFError
551
- tmp.close
552
- end
553
- return selected_string
554
- else
555
- tmp.close!
556
- return success
557
- end
311
+ send_command "setacl", bucket
558
312
  end
559
313
 
560
314
  # Get various information about a Bucket or Object
561
315
  def info(bucket) # s3://BUCKET[/OBJECT]
562
- tmp = Tempfile.new('tmp')
563
- command = option_string() + "info " + bucket.to_s + " 2> " + tmp.path
564
- success = system(command)
565
- if success
566
- begin
567
- while (line = tmp.readline)
568
- line.chomp
569
- selected_string = line
570
- end
571
- rescue EOFError
572
- tmp.close
573
- end
574
- return selected_string
575
- else
576
- tmp.close!
577
- return success
578
- end
316
+ send_command "info", bucket
579
317
  end
580
318
 
581
319
  # Disk usage - amount of data stored in S3
582
320
  def du(bucket) # [s3://BUCKET[/PREFIX]]
583
- tmp = Tempfile.new('tmp')
584
- command = option_string() + "du " + bucket.to_s + " 2> " + tmp.path
585
- success = system(command)
586
- if success
587
- begin
588
- while (line = tmp.readline)
589
- line.chomp
590
- selected_string = line
591
- end
592
- rescue EOFError
593
- tmp.close
594
- end
595
- return selected_string
596
- else
597
- tmp.close!
598
- return success
599
- end
321
+ send_command "du", bucket
600
322
  end
601
323
 
602
324
  # Commands for CloudFront management
603
325
 
604
326
  # List CloudFront distribution points
605
327
  def cflist
606
- tmp = Tempfile.new('tmp')
607
- command = option_string() + "cflist " + " 2> " + tmp.path
608
- success = system(command)
609
- if success
610
- begin
611
- while (line = tmp.readline)
612
- line.chomp
613
- selected_string = line
614
- end
615
- rescue EOFError
616
- tmp.close
617
- end
618
- return selected_string
619
- else
620
- tmp.close!
621
- return success
622
- end
328
+ send_command "cflist"
623
329
  end
624
330
 
625
331
  # Display CloudFront distribution point parameters
626
332
  def cfinfo(dist_id) # [cf://DIST_ID]
627
- tmp = Tempfile.new('tmp')
628
- command = option_string() + "cfinfo " + dist_id.to_s + " 2> " + tmp.path
629
- success = system(command)
630
- if success
631
- begin
632
- while (line = tmp.readline)
633
- line.chomp
634
- selected_string = line
635
- end
636
- rescue EOFError
637
- tmp.close
638
- end
639
- return selected_string
640
- else
641
- tmp.close!
642
- return success
643
- end
333
+ send_command "cfinfo", dist_id
644
334
  end
645
335
 
646
336
  # Create CloudFront distribution point
647
337
  def cfcreate(bucket) # s3://BUCKET
648
- tmp = Tempfile.new('tmp')
649
- command = option_string() + "cfcreate " + bucket.to_s + " 2> " + tmp.path
650
- success = system(command)
651
- if success
652
- begin
653
- while (line = tmp.readline)
654
- line.chomp
655
- selected_string = line
656
- end
657
- rescue EOFError
658
- tmp.close
659
- end
660
- return selected_string
661
- else
662
- tmp.close!
663
- return success
664
- end
338
+ send_command "cfcreate", bucket
665
339
  end
666
340
 
667
341
  # Delete CloudFront distribution point
668
342
  def cfdelete(dist_id) # cf://DIST_ID
669
- tmp = Tempfile.new('tmp')
670
- command = option_string() + "cfdelete " + dist_id.to_s + " 2> " + tmp.path
671
- success = system(command)
672
- if success
673
- begin
674
- while (line = tmp.readline)
675
- line.chomp
676
- selected_string = line
677
- end
678
- rescue EOFError
679
- tmp.close
680
- end
681
- return selected_string
682
- else
683
- tmp.close!
684
- return success
685
- end
343
+ send_command "cfdelete", dist_id
686
344
  end
687
345
 
688
346
  # Change CloudFront distribution point parameters
689
347
  def cfmodify(dist_id) # cf://DIST_ID
690
- tmp = Tempfile.new('tmp')
691
- command = option_string() + "cfmodify " + dist_id.to_s + " 2> " + tmp.path
692
- success = system(command)
693
- if success
694
- begin
695
- while (line = tmp.readline)
696
- line.chomp
697
- selected_string = line
698
- end
699
- rescue EOFError
700
- tmp.close
701
- end
702
- return selected_string
703
- else
704
- tmp.close!
705
- return success
706
- end
348
+ send_command "cfmodify", dist_id
707
349
  end
708
350
 
709
351
  def show_config
710
- option_string()
352
+ option_string
711
353
  end
712
354
 
713
- private
355
+ protected
356
+
357
+ def send_command(*command)
358
+ tmp = Tempfile.new('tmp')
359
+ success = system("#{option_string + command.join(" ") } > #{tmp.path}")
360
+ return tmp.readlines.map(&:chomp) if success
361
+ tmp.close!
362
+
363
+ success
364
+ end
714
365
 
715
- def option_string()
366
+ def option_string
716
367
 
717
368
  unless @path_to_s3cmd
718
369
  ostring = "s3cmd "
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-s3cmd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 0
10
- version: 0.1.0
8
+ - 2
9
+ version: 0.1.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Joel Bryan Juliano
@@ -47,27 +46,23 @@ rdoc_options: []
47
46
  require_paths:
48
47
  - lib
49
48
  required_ruby_version: !ruby/object:Gem::Requirement
50
- none: false
51
49
  requirements:
52
50
  - - ">="
53
51
  - !ruby/object:Gem::Version
54
- hash: 3
55
52
  segments:
56
53
  - 0
57
54
  version: "0"
58
55
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
56
  requirements:
61
57
  - - ">="
62
58
  - !ruby/object:Gem::Version
63
- hash: 3
64
59
  segments:
65
60
  - 0
66
61
  version: "0"
67
62
  requirements: []
68
63
 
69
64
  rubyforge_project:
70
- rubygems_version: 1.3.7
65
+ rubygems_version: 1.3.6
71
66
  signing_key:
72
67
  specification_version: 3
73
68
  summary: A gem providing a ruby interface to s3cmd Amazon S3 client.