awscli 0.0.5 → 0.0.6

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjBjNDc0NmJmYzY0NzA5ZWE0M2Q0ODllNmIwMWI5MDY5ZjE3MjM1ZQ==
4
+ MjlmNjJhN2FmMDg3MTE5ZWEyNmQwZDI1MjQ2MTBkY2Y5MWIxNjQyYQ==
5
5
  data.tar.gz: !binary |-
6
- NjA1MDA0NjJiYzJhNGM5NmFlMTdlN2ViYTBkYmQ1N2U5MzU0MWRhZQ==
6
+ NDk3MDBiZmQ5ODZjMzI2Y2NkNGM0ZmFlMTEyYmM2N2U5NjkwMzAxMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWNiZTg4MGMyOWNlZjIxMTY3MjE3MzYzZmU2NzQ0OTczYWZkOGExMjkxMzlj
10
- OWU0NzY1MjBmNjhmNWRiZDY3ODI4NjRhYTY0ZjZiZWUxMzVkNmFhMDdlOWJm
11
- NWM0MjIxZGEyMzEyY2M2M2I5NmVkZDE0YzcwNTUyYTc4ZmU2OGU=
9
+ M2ZlYmY2NjI4MGFhNjZjOWYzNDFjMjMxMTJjMGNlMmViMDgyNDEzOTJlYzE4
10
+ YzI2MmJhNGNjOGI1Yzg0YzFkZTM1ZjI0NjY1MjBkMDRlNGQ5MTdiYmViNjM4
11
+ NGNhMjZjN2IyMGY4MDg4ZDI3NzJjMGM3NTM5NWM1MzllYTJlOTM=
12
12
  data.tar.gz: !binary |-
13
- ZTYxYzBjYjM5YzQ4M2UwMWFhMGI0ZTEwNTEyODE1ZmFiNThhMjE2NGU2MmNj
14
- YzI4YmViZTliNjYwZjA4MzkwYmJjNjg5NTExMDI1Zjc4ZWUwNjE5YThkNzQ3
15
- MDVjZWVjYzkzODVkZTE1OWU0N2QxZWQ2MTc0NTM4YzA0N2E3NDY=
13
+ NWMxZjRkNDBhNDg4OTUyOTdkYTQ5YTE5MmNhZjg3NWM0NDNmNGE5OWY5YmFi
14
+ ODEwOWViMDBmM2QxMjc2YjdmMDYxZWI5M2Y0Y2VkMjkxYTU0MGUzOGY5MjU3
15
+ NzM5MWRkZmFiZDFiNTQ0M2RmYmEwNDE2MThhYWZiM2JkMjA5NDg=
data/lib/awscli.rb CHANGED
@@ -3,7 +3,7 @@ begin
3
3
  require 'thor'
4
4
  require 'thor/group'
5
5
  require 'fog'
6
- require 'highline'
6
+ require 'highline/import'
7
7
  require 'yaml'
8
8
  rescue LoadError
9
9
  puts "Failed to load gems: fog, highline, thor"
@@ -26,6 +26,13 @@ module AwsCli
26
26
  @s3.delete options[:key]
27
27
  end
28
28
 
29
+ desc "delete_rec", "Delete the bucket and all its contents"
30
+ method_option :key, :aliases => "-k", :type => :string, :required => true, :desc => "name of the bucket to delete"
31
+ def delete_rec
32
+ create_s3_object
33
+ @s3.delete_rec options[:key]
34
+ end
35
+
29
36
  desc "set_acl", "Change access control list for an S3 bucket"
30
37
  method_option :key, :aliases => "-k", :type => :string, :required => true, :desc => "name of the bucket to change acl"
31
38
  method_option :acl, :aliases => "-a", :type => :string, :required => true, :desc => "Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']"
data/lib/awscli/s3.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Awscli
2
2
  module S3
3
+ require 'thread'
3
4
 
4
5
  class Files
5
6
  def initialize connection, options = {}
@@ -78,10 +79,74 @@ module Awscli
78
79
  def delete dir_name
79
80
  dir = @@conn.directories.get(dir_name)
80
81
  abort "Cannot find bucket #{dir_name}" unless dir
82
+ #check if the dir is empty or not
83
+ abort "Bucket is not empty, use rec_delete to force delete bucket" if dir.files.length != 0
81
84
  dir.destroy
82
85
  puts "Deleted Bucket: #{dir_name}"
83
86
  end
84
87
 
88
+ def delete_rec dir_name
89
+ #Forked from https://gist.github.com/bdunagan/1383301
90
+ data_queue = Queue.new
91
+ semaphore = Mutex.new
92
+ threads = Array.new
93
+ total_listed = 0
94
+ total_deleted = 0
95
+ thread_count = 20 #num_of_threads to perform deletion
96
+ dir = @@conn.directories.get(dir_name)
97
+ abort "Cannot find bucket #{dir_name}" unless dir
98
+ if dir.files.length != 0
99
+ if agree("Are you sure want to delete all the objects in the bucket ? ", true)
100
+ puts
101
+ puts "==Deleting all the files in '#{dir_name}'=="
102
+ #fetch files in the bucket
103
+ threads << Thread.new do
104
+ Thread.current[:name] = "get files"
105
+ puts "...started thread '#{Thread.current[:name]}'...\n"
106
+ # Get all the files from this bucket. Fog handles pagination internally
107
+ dir.files.all.each do |file|
108
+ data_queue.enq(file) #add the file into the queue
109
+ total_listed += 1
110
+ end
111
+ # Add a final EOF message to signal the deletion threads to stop.
112
+ thread_count.times {data_queue.enq(:EOF)}
113
+ end
114
+ # Delete all the files in the queue until EOF with N threads.
115
+ thread_count.times do |count|
116
+ threads << Thread.new(count) do |number|
117
+ Thread.current[:name] = "delete files(#{number})"
118
+ puts "...started thread '#{Thread.current[:name]}'...\n"
119
+ # Dequeue until EOF.
120
+ file = nil
121
+ while file != :EOF
122
+ # Dequeue the latest file and delete it. (Will block until it gets a new file.)
123
+ file = data_queue.deq
124
+ file.destroy if file != :EOF
125
+ # Increment the global synchronized counter.
126
+ semaphore.synchronize {total_deleted += 1}
127
+ puts "Deleted #{total_deleted} out of #{total_listed}\n" if (rand(100) == 1)
128
+ end
129
+ end
130
+ end
131
+ # Wait for the threads to finish.
132
+ threads.each do |t|
133
+ begin
134
+ t.join
135
+ rescue RuntimeError => e
136
+ puts "Failure on thread #{t[:name]}: #{e.message}"
137
+ end
138
+ end
139
+ #finally delete the bucket it self
140
+ dir.destroy
141
+ puts "Deleted bucket: #{dir_name} and all its contents"
142
+ end
143
+ else
144
+ #empty bucket
145
+ dir.destroy
146
+ puts "Deleted bucket: #{dir_name}"
147
+ end
148
+ end
149
+
85
150
  def get_acl dir_name
86
151
  dir = @@conn.directories.get(dir_name)
87
152
  abort "Cannot find bucket #{dir_name}" unless dir
@@ -1,3 +1,3 @@
1
1
  module Awscli
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awscli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashrith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-27 00:00:00.000000000 Z
11
+ date: 2013-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake