Class: Informo::Dpkg

Inherits:
Object
  • Object
show all
Defined in:
lib/informo/dpkg.rb

Overview

This class is used to return information about installed packages for systems utilizing debian/ubuntu package formats

Instance Method Summary collapse

Constructor Details

#initializeDpkg

Returns a new instance of Dpkg.



6
7
8
9
# File 'lib/informo/dpkg.rb', line 6

def initialize()
  @@dpkgquery = "dpkg-query"
  @@pkginfo = "/var/lib/dpkg/info"
end

Instance Method Details

#get_all(name) ⇒ Object

returns the following information for a given package name as a hash

  • version

  • architecture

  • maintainer

  • description

  • status



68
69
70
71
72
73
74
75
76
77
# File 'lib/informo/dpkg.rb', line 68

def get_all(name)
  results = `#{@@dpkgquery} -W -f='${Version}|||${Architecture}|||${Maintainer}|||${Description}|||${Status}' #{name}`.split('|||')
  
  # return results as an array and map
  hresults = {'name' => name, 'version' => results[0],
              'architecture' => results[1], 'maintainer' => results[2],
              'description' => results[3], 'status' => results[4]}
  
  return hresults
end

#get_architecture(name) ⇒ Object

returns the architecture of the package specified as a string



26
27
28
29
# File 'lib/informo/dpkg.rb', line 26

def get_architecture(name)
  package_architecture = `#{@@dpkgquery} -W -f='${Architecture}' #{name}`
  return package_architecture
end

#get_description(name) ⇒ Object

returns the full, possibly lengthy, description for the specified package as a string



44
45
46
47
# File 'lib/informo/dpkg.rb', line 44

def get_description(name)
  package_description = `#{@@dpkgquery} -W -f='${Description}' #{name}`
  return package_description
end

#get_installdate(name) ⇒ Object

returns the installation date of the given package



56
57
58
59
# File 'lib/informo/dpkg.rb', line 56

def get_installdate(name)
  create_time = File.stat(@@pkginfo + "/#{name}.list").ctime.utc
  return create_time
end

#get_maintainer(name) ⇒ Object

returns the package maintainer for the given package as a string



32
33
34
35
# File 'lib/informo/dpkg.rb', line 32

def get_maintainer(name)
  package_maintainer = `#{@@dpkgquery} -W -f='${Maintainer}' #{name}`
  return package_maintainer
end

#get_packagesObject

returns an array of package names that are/were installed as show via dpkg-query command



13
14
15
16
17
# File 'lib/informo/dpkg.rb', line 13

def get_packages
  packages = Array.new
  packages = `#{@@dpkgquery} -W -f='${Package}\n'`.split("\n")
  return packages
end

#get_short_description(name) ⇒ Object

returns a brief description of a given package as a string



38
39
40
41
# File 'lib/informo/dpkg.rb', line 38

def get_short_description(name)
  package_description = `#{@@dpkgquery} -W -f='${Description}' #{name}`.split("\n")
  return package_description[0]
end

#get_status(name) ⇒ Object

returns the status for the package specified as a string



50
51
52
53
# File 'lib/informo/dpkg.rb', line 50

def get_status(name)
  package_status = `#{@@dpkgquery} -W -f='${Status}' #{name}`
  return package_status
end

#get_version(name) ⇒ Object

returns the version of the package specified as a string



20
21
22
23
# File 'lib/informo/dpkg.rb', line 20

def get_version(name)
  package_version = `#{@@dpkgquery} -W -f='${Version}' #{name}`
  return package_version
end