Class: Sprinkle::Package::Package

Inherits:
Object
  • Object
show all
Includes:
Rendering
Defined in:
lib/sprinkle/package.rb,
lib/sprinkle/installers/install_package.rb

Overview

:nodoc:

Defined Under Namespace

Classes: ContextError

Constant Summary collapse

@@installer_methods =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rendering

#render, #template, #template_search_path

Constructor Details

#initialize(name, metadata = {}, &block) ⇒ Package


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/sprinkle/package.rb', line 134

def initialize(name,  = {}, &block)
  raise 'No package name supplied' unless name

  @name = name
  @metadata = 
  @provides = [:provides]
  @dependencies = []
  @recommends = []
  @optional = []
  @verifications = []
  @install_queues ||= [[]]
  @block = block
  @use_sudo = nil
  @version = nil
  # this should probably not be done twice
  self.instance_eval(&block)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


120
121
122
# File 'lib/sprinkle/package.rb', line 120

def name
  @name
end

#providesObject

Returns the value of attribute provides


120
121
122
# File 'lib/sprinkle/package.rb', line 120

def provides
  @provides
end

#verificationsObject

Returns the value of attribute verifications


120
121
122
# File 'lib/sprinkle/package.rb', line 120

def verifications
  @verifications
end

Class Method Details

.add_api(&block) ⇒ Object


127
128
129
130
131
132
# File 'lib/sprinkle/package.rb', line 127

def self.add_api(&block)
  before = self.instance_methods
  self.class_eval(&block)
  added = self.instance_methods - before
  @@installer_methods += added.map(&:to_sym)
end

Instance Method Details

#argsObject


181
182
183
# File 'lib/sprinkle/package.rb', line 181

def args
  @_args ||= []
end

#defaults(s = nil) ⇒ Object


177
178
179
# File 'lib/sprinkle/package.rb', line 177

def defaults(s=nil)
  s ? @defaults = s : @defaults ||= Hash.new
end

#dependenciesObject


261
262
263
# File 'lib/sprinkle/package.rb', line 261

def dependencies
  @dependencies.map {|a,b| a }
end

#description(s = nil) ⇒ Object


152
153
154
# File 'lib/sprinkle/package.rb', line 152

def description(s=nil)
  s ? @description = s : @description
end

#get(x) ⇒ Object

Raises:


192
193
194
# File 'lib/sprinkle/package.rb', line 192

def get(x)
  raise ContextError, "Cannot call get inside a package, must be inside an Installer block"
end

#install_package(*names, &block) ⇒ Object Also known as: install_packages

:nodoc:


65
66
67
68
# File 'lib/sprinkle/installers/install_package.rb', line 65

def install_package(*names, &block) #:nodoc:
  ActiveSupport::Deprecation.warn("install_package will be removed from sprinkle 0.8, please use yum or smart installers instead.")
  @installers << Sprinkle::Installers::InstallPackage.new(self, names, &block)
end

#installersObject


289
290
291
# File 'lib/sprinkle/package.rb', line 289

def installers
  @install_queues.last
end

#instance(*args) ⇒ Object


160
161
162
163
164
165
166
167
# File 'lib/sprinkle/package.rb', line 160

def instance(*args)
  p=Package.new(name, @metadata) {}
  p.opts = defaults.merge(args.extract_options!)
  p.args = args
  p.instance_variable_set("@block", @block)
  p.instance_eval(&@block)
  p
end

#optional(*packages) ⇒ Object


257
258
259
# File 'lib/sprinkle/package.rb', line 257

def optional(*packages)
  add_dependencies packages, :optional
end

#optsObject


185
186
187
# File 'lib/sprinkle/package.rb', line 185

def opts
  @_opts ||= defaults.clone
end

#process(deployment, roles) ⇒ Object


208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/sprinkle/package.rb', line 208

def process(deployment, roles)
  output_name
  return if meta_package?

  # Run a pre-test to see if the software is already installed. If so,
  # we can skip it, unless we have the force option turned on!
  unless @verifications.empty? || Sprinkle::OPTIONS[:force]
    begin
      process_verifications(deployment, roles, true)

      logger.info "    --> already installed for roles: #{roles}"
      return
    rescue Sprinkle::VerificationFailed
      # Continue
    end
  end

  installers.each do |installer|
    installer.defaults(deployment)
    installer.process(roles)
  end

  process_verifications(deployment, roles)
  logger.info "    --> INSTALLED for roles: #{roles}"
end

#process_verifications(deployment, roles, pre = false) ⇒ Object


234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/sprinkle/package.rb', line 234

def process_verifications(deployment, roles, pre = false)
  return if @verifications.blank?

  if pre
    logger.debug "--> Checking if #{self.name} is already installed for roles: #{roles}"
  else
    logger.debug "--> Verifying #{self.name} was properly installed for roles: #{roles}"
  end

  @verifications.each do |v|
    v.defaults(deployment)
    v.process(roles, pre)
  end
end

#push_file(file, options = {}, &block) ⇒ Object

TODO - remove


197
198
199
200
201
202
# File 'lib/sprinkle/package.rb', line 197

def push_file(file, options ={}, &block)
  ActiveSupport::Deprecation.warn("push_file is depreciated and will be removed in v0.9.  Use the new `file` installer instead.")
  raise "need content" unless options[:content]
  runner "#{"sudo " if sudo?}rm -f #{file}"
  push_text(options[:content], file, options, &block)
end

#recommends(*packages) ⇒ Object


253
254
255
# File 'lib/sprinkle/package.rb', line 253

def recommends(*packages)
  add_dependencies packages, :recommends
end

#requires(*packages) ⇒ Object


249
250
251
# File 'lib/sprinkle/package.rb', line 249

def requires(*packages)
  add_dependencies packages, :dependencies
end

#sudo?Boolean


169
170
171
# File 'lib/sprinkle/package.rb', line 169

def sudo?
  !!@use_sudo
end

#to_sObject


274
275
276
# File 'lib/sprinkle/package.rb', line 274

def to_s
  "#{@name} #{@version}".strip
end

#tree(depth = 1, &block) ⇒ Object


265
266
267
268
269
270
271
272
# File 'lib/sprinkle/package.rb', line 265

def tree(depth = 1, &block)
  packages = []
  packages << tree_for_packages(@recommends, :depth => depth, &block)
  packages << tree_for_packages(@dependencies, :depth => depth, :required => true, &block)
  packages << self
  packages << tree_for_packages(@optional, :depth => depth, &block)
  packages
end

#uninstall_package(*names, &block) ⇒ Object Also known as: uninstall_packages

:nodoc:


70
71
72
73
# File 'lib/sprinkle/installers/install_package.rb', line 70

def uninstall_package(*names, &block) #:nodoc:
  ActiveSupport::Deprecation.warn("uninstall_package will be removed from sprinkle 0.8, please use yum or smart installers instead.")
  @installers << Sprinkle::Installers::UninstallPackage.new(self, names, &block)
end

#use_sudo(flag = true) ⇒ Object


173
174
175
# File 'lib/sprinkle/package.rb', line 173

def use_sudo(flag=true)
  @use_sudo = flag
end

#verify(description = '', &block) ⇒ Object


204
205
206
# File 'lib/sprinkle/package.rb', line 204

def verify(description = '', &block)
  @verifications << Sprinkle::Verify.new(self, description, &block)
end

#version(s = nil) ⇒ Object


156
157
158
# File 'lib/sprinkle/package.rb', line 156

def version(s=nil)
  s ? @version = s : @version
end

#with_private_install_queueObject

allow an installer to request a private install queue from the package for example to allow pre and post hooks to have their own installers that do not mess with the packages installer list

returns: the private queue


283
284
285
286
287
# File 'lib/sprinkle/package.rb', line 283

def with_private_install_queue()
  @install_queues.push []
  yield
  @install_queues.pop
end