Class: Teleport::Infer::Apt
- Inherits:
-
Object
- Object
- Teleport::Infer::Apt
show all
- Includes:
- Util
- Defined in:
- lib/teleport/infer.rb
Defined Under Namespace
Classes: Package
Constant Summary
collapse
- BLACKLIST =
/^(linux-|grub-|cloud-init)/
Constants included
from Util
Util::BLUE, Util::CYAN, Util::GREEN, Util::MAGENTA, Util::RED, Util::RESET, Util::YELLOW
Instance Method Summary
collapse
Methods included from Util
#banner, #chmod, #chown, #copy_metadata, #copy_perms, #cp, #cp_if_necessary, #cp_with_mkdir, #different?, #fails?, #fatal, #gem_if_necessary, #gem_version, #ln, #ln_if_necessary, #md5sum, #mkdir, #mkdir_if_necessary, #mv, #mv_with_mkdir, #package_if_necessary, #package_is_installed?, #process_by_pid?, #rm, #rm_and_mkdir, #rm_if_necessary, #run, #run_capture, #run_capture_lines, #run_quietly, #run_verbose!, #shell, #shell_escape, #succeeds?, #warning, #whoami
Constructor Details
#initialize ⇒ Apt
Returns a new instance of Apt.
248
249
250
251
|
# File 'lib/teleport/infer.rb', line 248
def initialize
@packages = nil
@map = nil
end
|
Instance Method Details
#[](name) ⇒ Object
284
285
286
287
288
289
290
|
# File 'lib/teleport/infer.rb', line 284
def [](name)
if !@map
@map = { }
packages.each { |i| @map[i.name] = i }
end
@map[name]
end
|
#added ⇒ Object
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
# File 'lib/teleport/infer.rb', line 317
def added
ignored = Set.new(ignored_packages)
list = packages.select do |i|
i.status == "install ok installed" && !ignored.include?(i.name)
end
list = list.map(&:name)
roots = []
check = list
while !check.empty?
check = check.map do |i|
if pkg = self[i]
if !pkg.parents.empty?
pkg.parents
else
roots << pkg.name
nil
end
end
end
check = check.compact.flatten.uniq.sort
check -= list
list += check
end
roots = roots.reject { |i| i =~ BLACKLIST }
roots.sort
end
|
#base_packages ⇒ Object
292
293
294
|
# File 'lib/teleport/infer.rb', line 292
def base_packages
packages.select { |i| i.base }.map(&:name)
end
|
#dependencies(list) ⇒ Object
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/teleport/infer.rb', line 302
def dependencies(list)
check = list
while !check.empty?
check = check.map do |i|
if pkg = self[i]
pkg.deps
end
end
check = check.compact.flatten.uniq.sort
check -= list
list += check
end
list.sort
end
|
#ignored_packages ⇒ Object
296
297
298
299
300
|
# File 'lib/teleport/infer.rb', line 296
def ignored_packages
list = packages.select { |i| i.base }.map(&:name)
list += %w(grub-pc installation-report language-pack-en language-pack-gnome-en linux-generic-pae linux-server os-prober ubuntu-desktop ubuntu-minimal ubuntu-standard wireless-crda)
dependencies(list)
end
|
#packages ⇒ Object
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/teleport/infer.rb', line 253
def packages
if !@packages
lines = run_capture_lines("dpkg-query '-f=${Package}\t${Status}\t${Pre-Depends},${Depends},${Recommends}\t${Essential}\t${Priority}\n' -W")
@packages = lines.map do |line|
name, status, deps, essential, priority = line.split("\t")
deps = deps.gsub(/\([^)]+\)/, "")
deps = deps.split(/[,|]/)
deps = deps.map(&:strip).select { |i| !i.empty? }.sort
base = false
base = true if essential == "yes"
base = true if priority =~ /^(important|required|standard)$/
Package.new(name, status, deps, base, [])
end
@packages.each do |pkg|
pkg.deps.each do |i|
if d = self[i]
d.parents << pkg.name
end
end
end
@packages.each do |pkg|
pkg.parents = pkg.parents.sort.uniq
end
end
@packages
end
|