Module: Deb::Fog::Utils
Defined Under Namespace
Classes: SafeSystemError
Class Method Summary collapse
- .bucket ⇒ Object
- .bucket=(v) ⇒ Object
- .debianize_op(op) ⇒ Object
- .fog ⇒ Object
- .fog=(v) ⇒ Object
-
.fog_escape(string) ⇒ Object
from fog, Fog::AWS.escape.
- .fog_exists?(path) ⇒ Boolean
- .fog_path(path) ⇒ Object
- .fog_read(path) ⇒ Object
- .fog_remove(path) ⇒ Object
- .fog_store(path, filename = nil, content_type = 'application/octet-stream; charset=binary') ⇒ Object
- .gpg_options ⇒ Object
- .gpg_options=(v) ⇒ Object
- .is_public ⇒ Object
- .is_public=(v) ⇒ Object
- .prefix ⇒ Object
- .prefix=(v) ⇒ Object
- .safesystem(*args) ⇒ Object
- .signing_key ⇒ Object
- .signing_key=(v) ⇒ Object
- .template(path) ⇒ Object
Class Method Details
.bucket ⇒ Object
10 |
# File 'lib/deb/fog/utils.rb', line 10 def bucket; @bucket end |
.bucket=(v) ⇒ Object
11 |
# File 'lib/deb/fog/utils.rb', line 11 def bucket= v; @bucket = v end |
.debianize_op(op) ⇒ Object
31 32 33 34 35 |
# File 'lib/deb/fog/utils.rb', line 31 def debianize_op(op) # Operators in debian packaging are <<, <=, =, >= and >> # So any operator like < or > must be replaced {:< => "<<", :> => ">>"}[op.to_sym] or op end |
.fog ⇒ Object
8 |
# File 'lib/deb/fog/utils.rb', line 8 def fog; @fog end |
.fog=(v) ⇒ Object
9 |
# File 'lib/deb/fog/utils.rb', line 9 def fog= v; @fog = v end |
.fog_escape(string) ⇒ Object
from fog, Fog::AWS.escape
48 49 50 51 52 |
# File 'lib/deb/fog/utils.rb', line 48 def fog_escape(string) string.gsub(/([^a-zA-Z0-9_.\-~]+)/) { "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase } end |
.fog_exists?(path) ⇒ Boolean
54 55 56 57 |
# File 'lib/deb/fog/utils.rb', line 54 def fog_exists?(path) return true if Deb::Fog::Utils.bucket.files.head(File.basename(path)) return false end |
.fog_path(path) ⇒ Object
43 44 45 |
# File 'lib/deb/fog/utils.rb', line 43 def fog_path(path) File.join(*[Deb::Fog::Utils.prefix, path].compact) end |
.fog_read(path) ⇒ Object
59 60 61 62 63 |
# File 'lib/deb/fog/utils.rb', line 59 def fog_read(path) #puts "blerg: #{Deb::Fog::Utils.bucket.files}" return nil unless fog_exists?(path) Deb::Fog::Utils.bucket.files[fog_path(path)].read end |
.fog_remove(path) ⇒ Object
85 86 87 |
# File 'lib/deb/fog/utils.rb', line 85 def fog_remove(path) Deb::Fog::Utils.bucket.files[fog_path(path)].destroy if fog_exists?(path) end |
.fog_store(path, filename = nil, content_type = 'application/octet-stream; charset=binary') ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/deb/fog/utils.rb', line 65 def fog_store(path, filename=nil, content_type='application/octet-stream; charset=binary') filename = File.basename(path) unless filename obj = Deb::Fog::Utils.bucket.files.head(filename) # check if the object already exists unless obj.nil? file_md5 = Digest::MD5.file(path) # puts "#{filename} - #{file_md5} vs #{obj.etag.gsub('"', '')}" return if file_md5.to_s == obj.etag.gsub('"', '') end # upload the file file = Deb::Fog::Utils.bucket.files.create( :key => fog_path(filename), :body => File.open(path), :public => Deb::Fog::Utils.is_public, :content_type => content_type ) # obj.write(Pathname.new(path), :acl => Deb::Fog::Utils.access_policy, :content_type => content_type) end |
.gpg_options ⇒ Object
16 |
# File 'lib/deb/fog/utils.rb', line 16 def ; @gpg_options end |
.gpg_options=(v) ⇒ Object
17 |
# File 'lib/deb/fog/utils.rb', line 17 def v; @gpg_options = v end |
.is_public ⇒ Object
12 |
# File 'lib/deb/fog/utils.rb', line 12 def is_public; @is_public end |
.is_public=(v) ⇒ Object
13 |
# File 'lib/deb/fog/utils.rb', line 13 def is_public= v; @is_public = v end |
.prefix ⇒ Object
18 |
# File 'lib/deb/fog/utils.rb', line 18 def prefix; @prefix end |
.prefix=(v) ⇒ Object
19 |
# File 'lib/deb/fog/utils.rb', line 19 def prefix= v; @prefix = v end |
.safesystem(*args) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/deb/fog/utils.rb', line 23 def safesystem(*args) success = system(*args) if !success raise SafeSystemError, "'system(#{args.inspect})' failed with error code: #{$?.exitstatus}" end return success end |
.signing_key ⇒ Object
14 |
# File 'lib/deb/fog/utils.rb', line 14 def signing_key; @signing_key end |
.signing_key=(v) ⇒ Object
15 |
# File 'lib/deb/fog/utils.rb', line 15 def signing_key= v; @signing_key = v end |
.template(path) ⇒ Object
37 38 39 40 41 |
# File 'lib/deb/fog/utils.rb', line 37 def template(path) template_file = File.join(File.dirname(__FILE__), "templates", path) template_code = File.read(template_file) ERB.new(template_code, nil, "-") end |