Class: Deb::Fog::Release

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/deb/fog/release.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

#initializeRelease

Returns a new instance of Release.



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

def initialize
  @codename = nil
  @architectures = []
  @components = []
  @files = {}
  @policy = :public_read
end

Instance Attribute Details

#architecturesObject

Returns the value of attribute architectures.



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

def architectures
  @architectures
end

#codenameObject

Returns the value of attribute codename.



6
7
8
# File 'lib/deb/fog/release.rb', line 6

def codename
  @codename
end

#componentsObject

Returns the value of attribute components.



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

def components
  @components
end

#filesObject

Returns the value of attribute files.



10
11
12
# File 'lib/deb/fog/release.rb', line 10

def files
  @files
end

#policyObject

Returns the value of attribute policy.



11
12
13
# File 'lib/deb/fog/release.rb', line 11

def policy
  @policy
end

Class Method Details

.parse_release(str) ⇒ Object



32
33
34
35
36
# File 'lib/deb/fog/release.rb', line 32

def parse_release(str)
  rel = self.new
  rel.parse(str)
  rel
end

.retrieve(codename) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/deb/fog/release.rb', line 22

def retrieve(codename)
  if s = Deb::Fog::Utils.fog_read("dists/#{codename}/Release")
    self.parse_release(s)
  else
    rel = self.new
    rel.codename = codename
    rel
  end
end

Instance Method Details

#filenameObject



39
40
41
# File 'lib/deb/fog/release.rb', line 39

def filename
  "dists/#{@codename}/Release"
end

#generateObject



72
73
74
# File 'lib/deb/fog/release.rb', line 72

def generate
  template("release.erb").result(binding)
end

#parse(str) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/deb/fog/release.rb', line 43

def parse(str)
  parse = lambda do |field|
    value = str[/^#{field}: .*/]
    if value.nil?
      return nil
    else
      return value.split(": ",2).last
    end
  end

  # grab basic fields
  self.codename = parse.call("Codename")
  self.architectures = (parse.call("Architectures") || "").split(/\s+/)
  self.components = (parse.call("Components") || "").split(/\s+/)

  # find all the hashes
  str.scan(/^\s+([^\s]+)\s+(\d+)\s+(.+)$/).each do |(hash,size,name)|
    self.files[name] ||= { :size => size.to_i }
    case hash.length
    when 32
      self.files[name][:md5] = hash
    when 40
      self.files[name][:sha1] = hash
    when 64
      self.files[name][:sha256] = hash
    end
  end
end

#update_manifest(manifest) ⇒ Object



112
113
114
115
116
# File 'lib/deb/fog/release.rb', line 112

def update_manifest(manifest)
  self.components << manifest.component unless self.components.include?(manifest.component)
  self.architectures << manifest.architecture unless self.architectures.include?(manifest.architecture)
  self.files.merge!(manifest.files)
end

#validate_othersObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/deb/fog/release.rb', line 118

def validate_others
  to_apply = []
  self.components.each do |comp|
    %w(amd64 i386).each do |arch|
      next if self.files.has_key?("#{comp}/binary-#{arch}/Packages")

      m = Deb::Fog::Manifest.new
      m.codename = self.codename
      m.component = comp
      m.architecture = arch
      if block_given?
        m.write_to_fog { |f| yield f }
      else
        m.write_to_fog
      end
      to_apply << m
    end
  end

  to_apply.each { |m| self.update_manifest(m) }
end

#write_to_fog {|self.filename| ... } ⇒ Object

Yields:



76
77
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
# File 'lib/deb/fog/release.rb', line 76

def write_to_fog
  # validate some other files are present
  if block_given?
    self.validate_others { |f| yield f }
  else
    self.validate_others
  end

  # generate the Release file
  release_tmp = Tempfile.new("Release")
  release_tmp.puts self.generate
  release_tmp.close
  yield self.filename if block_given?
  fog_store(release_tmp.path, self.filename, 'text/plain; charset=us-ascii')

  # sign the file, if necessary
  if Deb::Fog::Utils.signing_key
    key_param = Deb::Fog::Utils.signing_key != "" ? "--default-key=#{Deb::Fog::Utils.signing_key}" : ""
    if system("gpg -a #{key_param} #{Deb::Fog::Utils.gpg_options} -b #{release_tmp.path}")
      local_file = release_tmp.path+".asc"
      remote_file = self.filename+".gpg"
      yield remote_file if block_given?
      raise "Unable to locate Release signature file" unless File.exists?(local_file)
      fog_store(local_file, remote_file, 'application/pgp-signature; charset=us-ascii')
      File.unlink(local_file)
    else
      raise "Signing the Release file failed."
    end
  else
    # remove an existing Release.gpg, if it was there
    fog_remove(self.filename+".gpg")
  end

  release_tmp.unlink
end