Class: Cfruby::Packages::AptPackageManager

Inherits:
PackageManager show all
Defined in:
lib/libcfruby/osmodules/linux-debian.rb

Overview

PackageManager implementation for apt

Instance Method Summary collapse

Methods inherited from PackageManager

#[], #installed?, #installed_version, #method_missing, #version

Constructor Details

#initializeAptPackageManager

Returns a new instance of AptPackageManager.



11
12
13
14
15
# File 'lib/libcfruby/osmodules/linux-debian.rb', line 11

def initialize()
	# FIXME - search for apt utils
	@aptgetbin = 'apt-get'
	@dpkgbin = 'dpkg'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Cfruby::Packages::PackageManager

Instance Method Details

#install(packagename) ⇒ Object

Installs the latest version of the named package



19
20
21
22
23
24
25
# File 'lib/libcfruby/osmodules/linux-debian.rb', line 19

def install(packagename)
	packagename.strip!()

	Cfruby.controller.attempt("Installing \"#{packagename}\"", 'destructive', 'unknown') {
		`#{@aptgetbin} install '#{packagename.gsub(/(\')/, "\\\1")}'`
	}
end

#installed_packagesObject

Returns a PackageList object that contains key value pairs for every installed package where the key is the package name and the value is the currently installed version. See PackageList for more information



62
63
# File 'lib/libcfruby/osmodules/linux-debian.rb', line 62

def installed_packages()
end

#packagesObject

Returns the latest stable version of the named package that is available (installed or not)



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/libcfruby/osmodules/linux-debian.rb', line 40

def packages()
	packages = PackageList.new()

	list = `#{@dpkgbin} -l`
	regex = /^ii\s+(\S+)\s+(\S+)/
	list.each { | s |
		match = regex.match(s)
		if(match != nil)
			packages[match[1]]= PackageInfo.new()
			packages[match[1]].name = match[1]
			packages[match[1]].version = match[2]
		end
	}

	return(packages)
end

#uninstall(packagename) ⇒ Object

Uninstalls the named package



29
30
31
32
33
34
35
# File 'lib/libcfruby/osmodules/linux-debian.rb', line 29

def uninstall(packagename)
	packagename.strip!()

	Cfruby.controller.attempt("Uninstalling \"#{packagename}\"", 'destructive', 'unknown') {
		raise(Exception, 'uninstall unimplemented for AptPackageManager')
	}
end