Module: Deb::S3::Utils

Included in:
Manifest, Package, Package, Release
Defined in:
lib/deb/s3/utils.rb

Class Method Summary collapse

Class Method Details

.access_policyObject


8
# File 'lib/deb/s3/utils.rb', line 8

def access_policy; @access_policy end

.access_policy=(v) ⇒ Object


9
# File 'lib/deb/s3/utils.rb', line 9

def access_policy= v; @access_policy = v end

.bucketObject


6
# File 'lib/deb/s3/utils.rb', line 6

def bucket; @bucket end

.bucket=(v) ⇒ Object


7
# File 'lib/deb/s3/utils.rb', line 7

def bucket= v; @bucket = v end

.debianize_op(op) ⇒ Object


21
22
23
24
25
# File 'lib/deb/s3/utils.rb', line 21

def debianize_op(op)
  # Operators in debian packaging are <<, <=, =, >= and >>
  # So any operator like < or > must be replaced
  {:< => "<<", :> => ">>"}[op.to_sym] or op
end

.s3_escape(string) ⇒ Object

from fog, Fog::AWS.escape


34
35
36
37
38
# File 'lib/deb/s3/utils.rb', line 34

def s3_escape(string)
  string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
    "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
  }
end

.s3_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/deb/s3/utils.rb', line 40

def s3_exists?(path)
  AWS::S3::S3Object.exists?(path, Deb::S3::Utils.bucket)
end

.s3_read(path) ⇒ Object


44
45
46
47
48
49
50
51
# File 'lib/deb/s3/utils.rb', line 44

def s3_read(path)
  return nil unless s3_exists?(path)
  s = ""
  AWS::S3::S3Object.stream(path, Deb::S3::Utils.bucket) do |chunk|
    s += chunk
  end
  s
end

.s3_remove(path) ⇒ Object


61
62
63
# File 'lib/deb/s3/utils.rb', line 61

def s3_remove(path)
  AWS::S3::S3Object.delete(path, Deb::S3::Utils.bucket) if s3_exists?(path)
end

.s3_store(path, filename = nil) ⇒ Object


53
54
55
56
57
58
59
# File 'lib/deb/s3/utils.rb', line 53

def s3_store(path, filename=nil)
  filename = File.basename(path) unless filename
  File.open(path) do |file|
    AWS::S3::S3Object.store(filename, file,
      Deb::S3::Utils.bucket, :access => Deb::S3::Utils.access_policy)
  end
end

.safesystem(*args) ⇒ Object


13
14
15
16
17
18
19
# File 'lib/deb/s3/utils.rb', line 13

def safesystem(*args)
  success = system(*args)
  if !success
    raise "'system(#{args.inspect})' failed with error code: #{$?.exitstatus}"
  end
  return success
end

.signing_keyObject


10
# File 'lib/deb/s3/utils.rb', line 10

def signing_key; @signing_key end

.signing_key=(v) ⇒ Object


11
# File 'lib/deb/s3/utils.rb', line 11

def signing_key= v; @signing_key = v end

.template(path) ⇒ Object


27
28
29
30
31
# File 'lib/deb/s3/utils.rb', line 27

def template(path)
  template_file = File.join(File.dirname(__FILE__), "templates", path)
  template_code = File.read(template_file)
  ERB.new(template_code, nil, "-")
end