Class: Deb::Fog::Manifest

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

bucket, bucket=, debianize_op, fog, fog=, fog_escape, fog_exists?, fog_path, fog_read, fog_remove, fog_store, gpg_options, gpg_options=, is_public, is_public=, prefix, prefix=, safesystem, signing_key, signing_key=, template

Constructor Details

#initializeManifest

Returns a new instance of Manifest.



13
14
15
16
17
18
# File 'lib/deb/fog/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/fog/manifest.rb', line 9

def architecture
  @architecture
end

#codenameObject

Returns the value of attribute codename.



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

def codename
  @codename
end

#componentObject

Returns the value of attribute component.



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

def component
  @component
end

#filesObject

Returns the value of attribute files.



11
12
13
# File 'lib/deb/fog/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/fog/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::Fog::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/fog/manifest.rb', line 21

def retrieve(codename, component, architecture)
  m = if s = Deb::Fog::Utils.fog_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/fog/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

#delete_package(pkg, versions = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/deb/fog/manifest.rb', line 58

def delete_package(pkg, versions=nil)
  deleted = []
  new_packages = @packages.select { |p|
      # Include packages we didn't name
      if p.name != pkg
         p
      # Also include the packages not matching a specified version
      elsif (!versions.nil? and p.name == pkg and !versions.include? p.version)
          p
      end
  }
  deleted = @packages - new_packages
  @packages = new_packages
  deleted
end

#generateObject



74
75
76
# File 'lib/deb/fog/manifest.rb', line 74

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

#hashfile(path) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/deb/fog/manifest.rb', line 113

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/fog/manifest.rb', line 44

def packages
  @packages
end

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

Yields:

  • (f)


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/deb/fog/manifest.rb', line 78

def write_to_fog
  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?
      fog_store(pkg.filename, pkg.url_filename, 'application/octet-stream; charset=binary')
    end
  end

  # generate the Packages file
  pkgs_temp = Tempfile.new("Packages")
  pkgs_temp.write manifest
  puts "package contents: #{manifest}!!!!! to dists/#{@codename}/#{@component}/binary-#{@architecture}/Packages"
  pkgs_temp.close
  f = "dists/#{@codename}/#{@component}/binary-#{@architecture}/Packages"
  yield f if block_given?
  fog_store(pkgs_temp.path, f, 'text/plain; charset=us-ascii')
  @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?
  fog_store(gztemp.path, f, 'application/x-gzip; charset=binary')
  @files["#{@component}/binary-#{@architecture}/Packages.gz"] = hashfile(gztemp.path)
  gztemp.unlink

  nil
end