s3cp 0.1.3 → 0.1.4
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 -1
- data/bin/s3rm +3 -0
- data/lib/s3cp/s3rm.rb +132 -0
- data/lib/s3cp/version.rb +1 -1
- metadata +7 -4
data/History.txt
CHANGED
data/bin/s3rm
ADDED
data/lib/s3cp/s3rm.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'extensions/kernel' if RUBY_VERSION =~ /1.8/
|
3
|
+
require 'right_aws'
|
4
|
+
require 'optparse'
|
5
|
+
require 'date'
|
6
|
+
require 'highline/import'
|
7
|
+
|
8
|
+
require 's3cp/utils'
|
9
|
+
|
10
|
+
# Parse arguments
|
11
|
+
options = {}
|
12
|
+
options[:recursive] = false
|
13
|
+
options[:include_regex] = nil
|
14
|
+
options[:exclude_regex] = nil
|
15
|
+
options[:test] = false
|
16
|
+
options[:silent] = false
|
17
|
+
options[:fail_if_not_exist] = false
|
18
|
+
|
19
|
+
op = OptionParser.new do |opts|
|
20
|
+
opts.banner = "s3rm [path]"
|
21
|
+
opts.separator ''
|
22
|
+
|
23
|
+
opts.on("-r", "--recursive", "Delete S3 keys matching provided prefix.") do
|
24
|
+
options[:recursive] = true
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-i REGEX", "--include REGEX", "Delete only S3 objects matching the following regular expression.") do |regex|
|
28
|
+
options[:include_regex] = regex
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-x REGEX", "--exclude REGEX", "Do not delete any S3 objects matching provided regular expression.") do |regex|
|
32
|
+
options[:exclude_regex] = regex
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("-F", "--fail-if-not-exist", "Fail if no S3 object match provided key, prefix and/or regex") do
|
36
|
+
options[:fail_if_not_exist] = true
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-t", "--test", "Only display matching keys; do not actually delete anything.") do
|
40
|
+
options[:test] = true
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("--silent", "Do not display keys as they are deleted.") do
|
44
|
+
options[:silent] = true
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("--verbose", "Verbose mode") do
|
48
|
+
options[:verbose] = true
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
52
|
+
puts op
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
end
|
56
|
+
op.parse!(ARGV)
|
57
|
+
|
58
|
+
unless ARGV.size > 0
|
59
|
+
puts op
|
60
|
+
exit(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
if options[:include_regex] && !options[:recursive]
|
64
|
+
puts "-i (--include regex) option requires -r (recursive) option."
|
65
|
+
exit(1)
|
66
|
+
end
|
67
|
+
|
68
|
+
if options[:exclude_regex] && !options[:recursive]
|
69
|
+
puts "-x (--exclude regex) option requires -r (recursive) option."
|
70
|
+
exit(1)
|
71
|
+
end
|
72
|
+
|
73
|
+
url = ARGV[0]
|
74
|
+
|
75
|
+
if options[:verbose]
|
76
|
+
puts "URL: #{url}"
|
77
|
+
puts "Options: #{options.inspect}"
|
78
|
+
end
|
79
|
+
|
80
|
+
@bucket, @key = S3CP.bucket_and_key(url)
|
81
|
+
fail "Your URL looks funny, doesn't it?" unless @bucket
|
82
|
+
|
83
|
+
if options[:verbose]
|
84
|
+
puts "bucket #{@bucket}"
|
85
|
+
puts "key #{@key}"
|
86
|
+
end
|
87
|
+
|
88
|
+
include_regex = options[:include_regex] ? Regexp.new(options[:include_regex]) : nil
|
89
|
+
exclude_regex = options[:exclude_regex] ? Regexp.new(options[:exclude_regex]) : nil
|
90
|
+
|
91
|
+
@s3 = S3CP.connect()
|
92
|
+
|
93
|
+
if options[:recursive]
|
94
|
+
total_matching = 0
|
95
|
+
|
96
|
+
@s3.interface.incrementally_list_bucket(@bucket, :prefix => @key) do |page|
|
97
|
+
page[:contents].each do |entry|
|
98
|
+
key = "s3://#{@bucket}/#{entry[:key]}"
|
99
|
+
|
100
|
+
matching = true
|
101
|
+
matching = false if include_regex && !include_regex.match(entry[:key])
|
102
|
+
matching = false if exclude_regex && exclude_regex.match(entry[:key])
|
103
|
+
|
104
|
+
puts "#{key} => #{matching}" if options[:verbose]
|
105
|
+
|
106
|
+
if matching
|
107
|
+
total_matching += 1
|
108
|
+
puts key unless options[:silent] || options[:verbose]
|
109
|
+
@s3.interface.delete(@bucket, entry[:key]) unless options[:test]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
if options[:fail_if_not_exist] && total_matching == 0
|
115
|
+
puts "No matching keys."
|
116
|
+
exit(1)
|
117
|
+
end
|
118
|
+
else
|
119
|
+
# delete a single file; check if it exists
|
120
|
+
if options[:fail_if_not_exist] && @s3.interface.head(@bucket, @key) == nil
|
121
|
+
key = "s3://#{@bucket}/#{@key}"
|
122
|
+
puts "#{key} does not exist."
|
123
|
+
exit(1)
|
124
|
+
end
|
125
|
+
|
126
|
+
begin
|
127
|
+
@s3.interface.delete(@bucket, @key) unless options[:test]
|
128
|
+
rescue => e
|
129
|
+
puts e.to_s
|
130
|
+
raise e unless e.to_s =~ /Not Found/
|
131
|
+
end
|
132
|
+
end
|
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Boisvert
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-18 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -120,6 +120,7 @@ executables:
|
|
120
120
|
- s3cp
|
121
121
|
- s3cat
|
122
122
|
- s3mod
|
123
|
+
- s3rm
|
123
124
|
extensions: []
|
124
125
|
|
125
126
|
extra_rdoc_files:
|
@@ -131,6 +132,7 @@ files:
|
|
131
132
|
- lib/s3cp/s3cp.rb
|
132
133
|
- lib/s3cp/version.rb
|
133
134
|
- lib/s3cp/utils.rb
|
135
|
+
- lib/s3cp/s3rm.rb
|
134
136
|
- lib/s3cp/s3cat.rb
|
135
137
|
- History.txt
|
136
138
|
- README.md
|
@@ -138,6 +140,7 @@ files:
|
|
138
140
|
- bin/s3cat
|
139
141
|
- bin/s3ls
|
140
142
|
- bin/s3mod
|
143
|
+
- bin/s3rm
|
141
144
|
homepage:
|
142
145
|
licenses: []
|
143
146
|
|