Class: Cfruby::Packages::PortagePackageManager

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

Overview

PackageManager implementation for the Gentoo portage system

Instance Method Summary collapse

Methods inherited from PackageManager

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

Dynamic Method Handling

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

Instance Method Details

#install(packagename, force = false) ⇒ Object

Installs the latest version of the named package



12
13
14
15
16
17
18
19
20
# File 'lib/libcfruby/osmodules/linux-gentoo.rb', line 12

def install(packagename, force=false)
	packagename.strip!()

	# FIXME - check to see if it is already installed

	Cfruby.controller.attempt("Installing \"#{packagename}\"", 'destructive', 'unknown', 'install') {
		`emerge '#{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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/libcfruby/osmodules/linux-gentoo.rb', line 37

def installed_packages()
	packages = PackageList.new()
	packageregex = /^\s*([^\/]+)\/([^ ]+?)-([0-9][^ ]+)/

	list = `qpkg -I -v`
	list.each_line() { |line|
		match = packageregex.match(line)
		if(match != nil)
			packages[match[2]] = PackageInfo.new()
			packages[match[2]].name = match[2]
			packages[match[2]].version = match[3]
			packages[match[2]].category = match[1]
		end
	}
end

#packagesObject

Returns a PackageList object that contains key value pairs for every package (installed or not) where the key is the package name and the value is a PackageInfo object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/libcfruby/osmodules/linux-gentoo.rb', line 57

def packages()
	packages = PackageList.new()
	packageregex = /^\s*([^\/]+)\/([^ ]+?)-([0-9][^ ]+)/

	list = `qpkg -v`
	list.each_line() { |line|
		match = packageregex.match(line)
		if(match != nil)
			packages[match[2]] = PackageInfo.new()
			packages[match[2]].name = match[2]
			packages[match[2]].version = match[3]
			packages[match[2]].category = match[1]
		end
	}
end

#uninstall(packagename) ⇒ Object

Uninstalls the named package



24
25
26
27
28
29
30
# File 'lib/libcfruby/osmodules/linux-gentoo.rb', line 24

def uninstall(packagename)
	packagename.strip!()

	Cfruby.controller.attempt("Uninstalling \"#{packagename}\"", 'destructive', 'unknown') {
		`emerge unmerge '#{packagename.gsub(/(\')/, "\\\1")}'`
	}
end