Class: LinuxAdmin::Deb

Inherits:
Object
  • Object
show all
Defined in:
lib/linux_admin/deb.rb

Constant Summary collapse

APT_CACHE_CMD =
'/usr/bin/apt-cache'

Class Method Summary collapse

Class Method Details

.from_line(apt_cache_line, in_description = false) ⇒ Object



10
11
12
13
14
# File 'lib/linux_admin/deb.rb', line 10

def self.from_line(apt_cache_line, in_description=false)
  tag,value = apt_cache_line.split(':')
  tag = tag.strip.downcase
  [tag, value]
end

.from_string(apt_cache_string) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/linux_admin/deb.rb', line 16

def self.from_string(apt_cache_string)
  in_description = false
  apt_cache_string.split("\n").each.with_object({}) do |line,deb|
    tag,value = self.from_line(line)
    if tag == 'description-en'
      in_description = true
    elsif tag == 'homepage'
      in_description = false
    end

    if in_description && tag != 'description-en'
      deb['description-en'] << line
    else
      deb[tag] = value.strip
    end
  end
end

.info(pkg) ⇒ Object



34
35
36
# File 'lib/linux_admin/deb.rb', line 34

def self.info(pkg)
  self.from_string(run!(APT_CACHE_CMD, :params => ["show", pkg]).output)
end