Class: Deb::S3::Manifest

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/deb/s3/manifest.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

access_policy, access_policy=, bucket, bucket=, debianize_op, s3_escape, s3_exists?, s3_read, s3_remove, s3_store, safesystem, signing_key, signing_key=, template

Constructor Details

#initializeManifest


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

def initialize
  @packages = []
  @component = nil
  @architecture = nil
  @files = {}
end

Instance Attribute Details

#architectureObject

Returns the value of attribute architecture


9
10
11
# File 'lib/deb/s3/manifest.rb', line 9

def architecture
  @architecture
end

#codenameObject

Returns the value of attribute codename


7
8
9
# File 'lib/deb/s3/manifest.rb', line 7

def codename
  @codename
end

#componentObject

Returns the value of attribute component


8
9
10
# File 'lib/deb/s3/manifest.rb', line 8

def component
  @component
end

#filesObject

Returns the value of attribute files


11
12
13
# File 'lib/deb/s3/manifest.rb', line 11

def files
  @files
end

Class Method Details

.parse_packages(str) ⇒ Object


34
35
36
37
38
39
40
41
# File 'lib/deb/s3/manifest.rb', line 34

def parse_packages(str)
  m = self.new
  str.split("\n\n").each do |s|
    next if s.chomp.empty?
    m.packages << Deb::S3::Package.parse_string(s)
  end
  m
end

.retrieve(codename, component, architecture) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/deb/s3/manifest.rb', line 21

def retrieve(codename, component, architecture)
  m = if s = Deb::S3::Utils.s3_read("dists/#{codename}/#{component}/binary-#{architecture}/Packages")
    self.parse_packages(s)
  else
    self.new
  end

  m.codename = codename
  m.component = component
  m.architecture = architecture
  m
end

Instance Method Details

#add(pkg, preserve_versions) ⇒ Object


48
49
50
51
52
53
54
55
56
# File 'lib/deb/s3/manifest.rb', line 48

def add(pkg, preserve_versions)
  if preserve_versions
    @packages.delete_if { |p| p.name == pkg.name && p.version == pkg.version }
  else
    @packages.delete_if { |p| p.name == pkg.name }
  end
  @packages << pkg
  pkg
end

#generateObject


58
59
60
# File 'lib/deb/s3/manifest.rb', line 58

def generate
  @packages.collect { |pkg| pkg.generate }.join("\n")
end

#hashfile(path) ⇒ Object


96
97
98
99
100
101
102
103
# File 'lib/deb/s3/manifest.rb', line 96

def hashfile(path)
  {
    :size   => File.size(path),
    :sha1   => Digest::SHA1.file(path).hexdigest,
    :sha256 => Digest::SHA2.file(path).hexdigest,
    :md5    => Digest::MD5.file(path).hexdigest
  }
end

#packagesObject


44
45
46
# File 'lib/deb/s3/manifest.rb', line 44

def packages
  @packages
end

#write_to_s3 {|f| ... } ⇒ Object

Yields:

  • (f)

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/deb/s3/manifest.rb', line 62

def write_to_s3
  manifest = self.generate

  # store any packages that need to be stored
  @packages.each do |pkg|
    if pkg.needs_uploading?
      yield pkg.url_filename if block_given?
      s3_store(pkg.filename, pkg.url_filename_encoded)
    end
  end

  # generate the Packages file
  pkgs_temp = Tempfile.new("Packages")
  pkgs_temp.write manifest
  pkgs_temp.close
  f = "dists/#{@codename}/#{@component}/binary-#{@architecture}/Packages"
  yield f if block_given?
  s3_store(pkgs_temp.path, f)
  @files["#{@component}/binary-#{@architecture}/Packages"] = hashfile(pkgs_temp.path)
  pkgs_temp.unlink

  # generate the Packages.gz file
  gztemp = Tempfile.new("Packages.gz")
  gztemp.close
  Zlib::GzipWriter.open(gztemp.path) { |gz| gz.write manifest }
  f = "dists/#{@codename}/#{@component}/binary-#{@architecture}/Packages.gz"
  yield f if block_given?
  s3_store(gztemp.path, f)
  @files["#{@component}/binary-#{@architecture}/Packages.gz"] = hashfile(gztemp.path)
  gztemp.unlink

  nil
end