commonthread-fluffy 0.0.3 → 0.1.0
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/.gitignore +1 -0
- data/VERSION +1 -1
- data/fluffy.gemspec +3 -3
- data/lib/fluffy.rb +273 -53
- data/lib/fluffy/s3_io.rb +4 -1
- metadata +3 -3
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/fluffy.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{fluffy}
|
5
|
-
s.version = "0.0
|
5
|
+
s.version = "0.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ben Wyrosdick"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-24}
|
10
10
|
s.email = %q{ben.wyrosdick@gmail.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
34
34
|
s.require_paths = ["lib"]
|
35
35
|
s.rubygems_version = %q{1.3.4}
|
36
|
-
s.summary = %q{
|
36
|
+
s.summary = %q{Makes writing to S3 tranparent using File}
|
37
37
|
s.test_files = [
|
38
38
|
"test/fluffy_test.rb",
|
39
39
|
"test/test_helper.rb"
|
data/lib/fluffy.rb
CHANGED
@@ -2,92 +2,312 @@ require File.join(File.dirname(__FILE__), 'fluffy/s3_path')
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'fluffy/s3_io')
|
3
3
|
|
4
4
|
require 'right_aws'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'pathname'
|
5
7
|
|
6
|
-
File
|
7
|
-
|
8
|
+
RealFile = File
|
9
|
+
#RealFileUtils = FileUtils
|
10
|
+
RealDir = Dir
|
11
|
+
#RealFileUtils::Dir = RealDir
|
12
|
+
#RealFileUtils::File = RealFile
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
14
|
+
module Fluffy
|
15
|
+
#module FileUtils
|
16
|
+
# extend self
|
12
17
|
|
13
|
-
def
|
14
|
-
|
15
|
-
end
|
18
|
+
# def mkdir_p(path)
|
19
|
+
# RealFileUtils.mkdir_p(path)
|
20
|
+
# end
|
21
|
+
|
22
|
+
# def rm(path)
|
23
|
+
# RealFileUtils.rm(path)
|
24
|
+
# end
|
25
|
+
|
26
|
+
# def rm_r(path)
|
27
|
+
# RealFileUtils.rm_r(path)
|
28
|
+
# end
|
29
|
+
|
30
|
+
# def rm_rf(path)
|
31
|
+
# RealFileUtils.rm_rf(path)
|
32
|
+
# end
|
33
|
+
|
34
|
+
# def ln_s(target, path)
|
35
|
+
# raise Errno::EEXIST, path if File.exists?(path)
|
36
|
+
# RealFileUtils.ln_s(target, path)
|
37
|
+
# end
|
38
|
+
|
39
|
+
# def cp(src, dest)
|
40
|
+
# RealFileUtils.cp(src, dest)
|
41
|
+
# #dst_file = FileSystem.find(dest)
|
42
|
+
# #src_file = FileSystem.find(src)
|
43
|
+
|
44
|
+
# #if !src_file
|
45
|
+
# # raise Errno::ENOENT, src
|
46
|
+
# #end
|
47
|
+
|
48
|
+
# #if File.directory? src_file
|
49
|
+
# # raise Errno::EISDIR, src
|
50
|
+
# #end
|
51
|
+
|
52
|
+
# #if dst_file and File.directory?(dst_file)
|
53
|
+
# # FileSystem.add(File.join(dest, src), src_file.entry.clone(dst_file))
|
54
|
+
# #else
|
55
|
+
# # FileSystem.delete(dest)
|
56
|
+
# # FileSystem.add(dest, src_file.entry.clone)
|
57
|
+
# #end
|
58
|
+
# end
|
59
|
+
|
60
|
+
# def cp_r(src, dest)
|
61
|
+
# RealFileUtils.cp_r(src, dest)
|
62
|
+
# ## This error sucks, but it conforms to the original Ruby
|
63
|
+
# ## method.
|
64
|
+
# #raise "unknown file type: #{src}" unless dir = FileSystem.find(src)
|
65
|
+
|
66
|
+
# #new_dir = FileSystem.find(dest)
|
67
|
+
|
68
|
+
# #if new_dir && !File.directory?(dest)
|
69
|
+
# # raise Errno::EEXIST, dest
|
70
|
+
# #end
|
71
|
+
|
72
|
+
# #if !new_dir && !FileSystem.find(dest+'/../')
|
73
|
+
# # raise Errno::ENOENT, dest
|
74
|
+
# #end
|
75
|
+
|
76
|
+
# ## This last bit is a total abuse and should be thought hard
|
77
|
+
# ## about and cleaned up.
|
78
|
+
# #if new_dir
|
79
|
+
# # if src[-2..-1] == '/.'
|
80
|
+
# # dir.values.each{|f| new_dir[f.name] = f.clone(new_dir) }
|
81
|
+
# # else
|
82
|
+
# # new_dir[dir.name] = dir.entry.clone(new_dir)
|
83
|
+
# # end
|
84
|
+
# #else
|
85
|
+
# # FileSystem.add(dest, dir.entry.clone)
|
86
|
+
# #end
|
87
|
+
# end
|
88
|
+
|
89
|
+
# def mv(src, dest)
|
90
|
+
# RealFileUtils.mv(src, dest)
|
91
|
+
# #if target = FileSystem.find(src)
|
92
|
+
# # FileSystem.add(dest, target.entry.clone)
|
93
|
+
# # FileSystem.delete(src)
|
94
|
+
# #else
|
95
|
+
# # raise Errno::ENOENT, src
|
96
|
+
# #end
|
97
|
+
# end
|
98
|
+
|
99
|
+
# def chown(user, group, list, options={})
|
100
|
+
# RealFileUtils.chown(user, group, list, options)
|
101
|
+
# #list = Array(list)
|
102
|
+
# #list.each do |f|
|
103
|
+
# # unless File.exists?(f)
|
104
|
+
# # raise Errno::ENOENT, f
|
105
|
+
# # end
|
106
|
+
# #end
|
107
|
+
# #list
|
108
|
+
# end
|
109
|
+
|
110
|
+
# def chown_R(user, group, list, options={})
|
111
|
+
# RealFileUtils.chown_R(user, group, list, options={})
|
112
|
+
# #chown(user, group, list, options={})
|
113
|
+
# end
|
114
|
+
|
115
|
+
# def touch(list, options={})
|
116
|
+
# RealFileUtils.touch(list, options)
|
117
|
+
# #Array(list).each do |f|
|
118
|
+
# # directory = File.dirname(f)
|
119
|
+
# # # FIXME this explicit check for '.' shouldn't need to happen
|
120
|
+
# # if File.exists?(directory) || directory == '.'
|
121
|
+
# # FileSystem.add(f, MockFile.new)
|
122
|
+
# # else
|
123
|
+
# # raise Errno::ENOENT, f
|
124
|
+
# # end
|
125
|
+
# #end
|
126
|
+
# end
|
127
|
+
|
128
|
+
# def cd(dir)
|
129
|
+
# RealFileUtils.cd(dir)
|
130
|
+
# end
|
131
|
+
# alias_method :chdir, :cd
|
16
132
|
|
17
|
-
|
133
|
+
# def method_missing(meth, *args, &block)
|
134
|
+
# RealFileUtils.send(meth, *args, &block)
|
135
|
+
# end
|
136
|
+
#end
|
18
137
|
|
19
|
-
|
20
|
-
|
21
|
-
s3io = Fluffy::S3Io.new(s3_path, key, mode)
|
138
|
+
class File
|
139
|
+
PATH_SEPARATOR = '/'
|
22
140
|
|
23
|
-
|
24
|
-
|
25
|
-
|
141
|
+
@@s3_paths = []
|
142
|
+
|
143
|
+
def self.register_s3(file_path, access_key_id, secret_access_key, bucket, start_path = '')
|
144
|
+
File.s3_paths << Fluffy::S3Path.new(File.expand_path(file_path), access_key_id, secret_access_key, bucket, start_path)
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.s3_paths
|
148
|
+
return @@s3_paths
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.join(*parts)
|
152
|
+
RealFile.join(parts)
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.exist?(path)
|
156
|
+
Fluffy.cloud_runner(RealFile, :exist?, path) do |s3_path, key|
|
157
|
+
s3_path.bucket.key(key).exists?
|
26
158
|
end
|
159
|
+
end
|
27
160
|
|
28
|
-
|
161
|
+
def self.const_missing(name)
|
162
|
+
RealFile.const_get(name)
|
163
|
+
end
|
164
|
+
|
165
|
+
class << self
|
166
|
+
alias_method :exists?, :exist?
|
29
167
|
end
|
30
|
-
end
|
31
168
|
|
32
|
-
|
169
|
+
def self.directory?(path)
|
170
|
+
Fluffy.cloud_runner(RealFile, :directory?, path) do |s3_path, key|
|
171
|
+
#FIXME Look for a directory
|
172
|
+
end
|
173
|
+
end
|
33
174
|
|
34
|
-
|
35
|
-
|
36
|
-
s3_path.bucket.key(key).exists?
|
175
|
+
def self.symlink?(path)
|
176
|
+
RealFile.symlink?(path)
|
37
177
|
end
|
38
|
-
end
|
39
178
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
def file?(filename)
|
45
|
-
exists?(filename)
|
46
|
-
end
|
179
|
+
def self.file?(path)
|
180
|
+
RealFile.file?(path)
|
181
|
+
end
|
47
182
|
|
48
|
-
|
183
|
+
def self.expand_path(*args)
|
184
|
+
RealFile.expand_path(*args)
|
185
|
+
end
|
49
186
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
187
|
+
def self.basename(*args)
|
188
|
+
RealFile.basename(*args)
|
189
|
+
end
|
190
|
+
|
191
|
+
def self.dirname(path)
|
192
|
+
RealFile.dirname(path)
|
193
|
+
end
|
194
|
+
|
195
|
+
def self.readlink(path)
|
196
|
+
RealFile.readlink(path)
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.open(path, mode='r', &block)
|
200
|
+
Fluffy.cloud_runner(RealFile, :open, path, block) do |s3_path, key|
|
201
|
+
s3io = Fluffy::S3Io.new(s3_path, key, mode)
|
202
|
+
|
203
|
+
if block_given?
|
204
|
+
block_val = yield(s3io)
|
205
|
+
s3io.close
|
206
|
+
return block_val
|
207
|
+
end
|
208
|
+
|
209
|
+
return s3io
|
54
210
|
end
|
55
211
|
end
|
56
|
-
end
|
57
|
-
end
|
58
212
|
|
59
|
-
|
60
|
-
|
213
|
+
def self.read(path)
|
214
|
+
open(path).read
|
215
|
+
end
|
61
216
|
|
62
|
-
|
63
|
-
|
64
|
-
s3_path.bucket.key(key).delete
|
217
|
+
def self.readlines(path)
|
218
|
+
open(path).readlines
|
65
219
|
end
|
66
|
-
end
|
67
220
|
|
68
|
-
|
69
|
-
|
221
|
+
def self.unlink(*filepaths)
|
222
|
+
filepaths.each do |filename|
|
223
|
+
Fluffy.cloud_runner(RealFile, :unlink, filename) do |s3_path, key|
|
224
|
+
s3_path.bucket.key(key).delete
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def self.new(path, mode = nil)
|
230
|
+
Fluffy.cloud_runner(RealFile, :new, path) do |s3_path, key|
|
231
|
+
open(path, mode)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def self.chmod(mode, *files)
|
236
|
+
#FIXME: Make it work
|
237
|
+
end
|
238
|
+
|
239
|
+
def self.method_missing(meth, *args, &block)
|
240
|
+
RealFile.send(meth, *args, &block)
|
241
|
+
end
|
70
242
|
end
|
71
243
|
|
72
|
-
|
73
|
-
|
244
|
+
class Dir
|
245
|
+
def self.glob(pattern)
|
246
|
+
RealDir.glob(pattern)
|
247
|
+
#if pattern[-1,1] == '*'
|
248
|
+
# blk = proc { |entry| entry.to_s }
|
249
|
+
#else
|
250
|
+
# blk = proc { |entry| entry[1].parent.to_s }
|
251
|
+
#end
|
252
|
+
#(FileSystem.find(pattern) || []).map(&blk).uniq.sort
|
253
|
+
end
|
254
|
+
|
255
|
+
def self.[](pattern)
|
256
|
+
glob(pattern)
|
257
|
+
end
|
258
|
+
|
259
|
+
def self.entries(path)
|
260
|
+
RealDir.entries(path)
|
261
|
+
end
|
262
|
+
|
263
|
+
def self.chdir(dir, &blk)
|
264
|
+
RealDir.chdir(dir, blk)
|
265
|
+
end
|
266
|
+
|
267
|
+
def self.unlink(dirpath)
|
268
|
+
Fluffy.cloud_runner(self, :unlink, dirpath) do |s3_path, key|
|
269
|
+
s3_path.bucket.key(key).delete
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
class << self
|
274
|
+
alias_method :rmdir, :unlink
|
275
|
+
alias_method :delete, :unlink
|
276
|
+
end
|
277
|
+
|
278
|
+
def self.method_missing(meth, *args, &block)
|
279
|
+
RealDir.send(meth, *args, &block)
|
280
|
+
end
|
74
281
|
end
|
75
|
-
end
|
76
282
|
|
77
|
-
|
78
|
-
def self.cloud_runner(klass, method_name, filename, &block)
|
283
|
+
def self.cloud_runner(klass, method_name, filename, method_block=nil, &block)
|
79
284
|
expanded_filename = File.expand_path(filename)
|
80
285
|
if s3_path = File.s3_paths.find {|path| expanded_filename =~ /^#{path.file_path}/}
|
81
286
|
starting_position = s3_path.file_path.length + 1
|
82
|
-
|
83
|
-
|
84
|
-
|
287
|
+
if expanded_filename.length > starting_position
|
288
|
+
key = expanded_filename[starting_position .. -1]
|
289
|
+
yield(s3_path, File.join(s3_path.start_path, key).gsub(/^\W/, ''))
|
290
|
+
elsif method_name == :directory?
|
291
|
+
return true
|
292
|
+
else
|
293
|
+
raise 'You must specify a key'
|
294
|
+
end
|
85
295
|
else
|
86
|
-
klass.send(
|
296
|
+
klass.send(method_name, filename, &method_block)
|
87
297
|
end
|
88
298
|
end
|
89
299
|
end
|
90
300
|
|
301
|
+
Object.class_eval do
|
302
|
+
remove_const(:Dir)
|
303
|
+
remove_const(:File)
|
304
|
+
#remove_const(:FileUtils)
|
305
|
+
end
|
306
|
+
|
307
|
+
#FileUtils = Fluffy::FileUtils
|
308
|
+
File = Fluffy::File
|
309
|
+
Dir = Fluffy::Dir
|
310
|
+
|
91
311
|
## File
|
92
312
|
#
|
93
313
|
# lchmod
|
data/lib/fluffy/s3_io.rb
CHANGED
@@ -57,13 +57,15 @@ module Fluffy
|
|
57
57
|
return data
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
60
|
+
def write(string = nil)
|
61
61
|
string ||= $_
|
62
62
|
string << $\ if $\
|
63
63
|
self.data[self.pos, string.length] = string
|
64
64
|
self.pos += string.length
|
65
65
|
return nil
|
66
66
|
end
|
67
|
+
alias_method :print, :write
|
68
|
+
alias_method :<<, :write
|
67
69
|
|
68
70
|
def puts(*strings)
|
69
71
|
strings.each do |string|
|
@@ -96,6 +98,7 @@ module Fluffy
|
|
96
98
|
|
97
99
|
def flush
|
98
100
|
self.key.put(self.data)
|
101
|
+
self
|
99
102
|
end
|
100
103
|
end
|
101
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonthread-fluffy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Wyrosdick
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -63,7 +63,7 @@ rubyforge_project:
|
|
63
63
|
rubygems_version: 1.2.0
|
64
64
|
signing_key:
|
65
65
|
specification_version: 3
|
66
|
-
summary:
|
66
|
+
summary: Makes writing to S3 tranparent using File
|
67
67
|
test_files:
|
68
68
|
- test/fluffy_test.rb
|
69
69
|
- test/test_helper.rb
|