Class: Informo::Dpkg
- Inherits:
-
Object
- Object
- Informo::Dpkg
- 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
-
#get_all(name) ⇒ Object
returns the following information for a given package name as a hash.
-
#get_architecture(name) ⇒ Object
returns the architecture of the package specified as a string.
-
#get_description(name) ⇒ Object
returns the full, possibly lengthy, description for the specified package as a string.
-
#get_installdate(name) ⇒ Object
returns the installation date of the given package.
-
#get_maintainer(name) ⇒ Object
returns the package maintainer for the given package as a string.
-
#get_packages ⇒ Object
returns an array of package names that are/were installed as show via
dpkg-querycommand. -
#get_short_description(name) ⇒ Object
returns a brief description of a given package as a string.
-
#get_status(name) ⇒ Object
returns the status for the package specified as a string.
-
#get_version(name) ⇒ Object
returns the version of the package specified as a string.
-
#initialize ⇒ Dpkg
constructor
A new instance of Dpkg.
Constructor Details
#initialize ⇒ Dpkg
Returns a new instance of Dpkg.
8 9 10 11 |
# File 'lib/informo/dpkg.rb', line 8 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
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/informo/dpkg.rb', line 70 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
28 29 30 31 |
# File 'lib/informo/dpkg.rb', line 28 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
46 47 48 49 |
# File 'lib/informo/dpkg.rb', line 46 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
58 59 60 61 |
# File 'lib/informo/dpkg.rb', line 58 def get_installdate(name) create_time = Time.at(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
34 35 36 37 |
# File 'lib/informo/dpkg.rb', line 34 def get_maintainer(name) package_maintainer = `#{@@dpkgquery} -W -f='${Maintainer}' #{name}` return package_maintainer end |
#get_packages ⇒ Object
returns an array of package names that are/were installed as show via dpkg-query command
15 16 17 18 19 |
# File 'lib/informo/dpkg.rb', line 15 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
40 41 42 43 |
# File 'lib/informo/dpkg.rb', line 40 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
52 53 54 55 |
# File 'lib/informo/dpkg.rb', line 52 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
22 23 24 25 |
# File 'lib/informo/dpkg.rb', line 22 def get_version(name) package_version = `#{@@dpkgquery} -W -f='${Version}' #{name}` return package_version end |