chef 0.7.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +209 -0
- data/lib/chef/application/indexer.rb +141 -0
- data/lib/chef/application/server.rb +18 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/client.rb +396 -0
- data/lib/chef/compile.rb +138 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +144 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +168 -0
- data/lib/chef/couchdb.rb +172 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/exceptions.rb +36 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +37 -0
- data/lib/chef/mixin/command.rb +351 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +36 -0
- data/lib/chef/mixin/find_preferred_file.rb +99 -0
- data/lib/chef/mixin/from_file.rb +36 -0
- data/lib/chef/mixin/generate_url.rb +48 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/template.rb +84 -0
- data/lib/chef/node.rb +406 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +253 -0
- data/lib/chef/provider.rb +40 -0
- data/lib/chef/provider/cron.rb +137 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +191 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/groupadd.rb +92 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/http_request.rb +102 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mount.rb +121 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +113 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +130 -0
- data/lib/chef/provider/package/yum-dump.py +104 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +134 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +15 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +129 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +157 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +126 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/template.rb +141 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +107 -0
- data/lib/chef/queue.rb +145 -0
- data/lib/chef/recipe.rb +210 -0
- data/lib/chef/resource.rb +256 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +143 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/group.rb +68 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +20 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +176 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +238 -0
- data/lib/chef/role.rb +231 -0
- data/lib/chef/run_list.rb +156 -0
- data/lib/chef/runner.rb +123 -0
- data/lib/chef/search.rb +88 -0
- data/lib/chef/search/result.rb +64 -0
- data/lib/chef/search_index.rb +77 -0
- data/lib/chef/tasks/chef_repo.rake +345 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +262 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Ezra Zygmuntowicz (<ezra@engineyard.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider/package'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
require 'chef/resource/package'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Package
|
26
|
+
class Portage < Chef::Provider::Package
|
27
|
+
|
28
|
+
def load_current_resource
|
29
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
30
|
+
@current_resource.package_name(@new_resource.package_name)
|
31
|
+
|
32
|
+
category = @new_resource.package_name.split('/').first
|
33
|
+
pkg = @new_resource.package_name.split('/').last
|
34
|
+
|
35
|
+
@current_resource.version(nil)
|
36
|
+
|
37
|
+
catdir = "/var/db/pkg/#{category}"
|
38
|
+
|
39
|
+
if( ::File.exists?(catdir) )
|
40
|
+
Dir.entries(catdir).each do |entry|
|
41
|
+
if(entry =~ /^#{Regexp.escape(pkg)}\-(.+)/)
|
42
|
+
@current_resource.version($1)
|
43
|
+
Chef::Log.debug("Got current version #{$1}")
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@current_resource
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def parse_emerge(package, txt)
|
54
|
+
available, installed, pkg = nil
|
55
|
+
txt.each do |line|
|
56
|
+
if line =~ /\*(.*)/
|
57
|
+
pkg = $1.strip
|
58
|
+
end
|
59
|
+
if (pkg == package) || (pkg.split('/').last == package rescue false)
|
60
|
+
if line =~ /Latest version available: (.*)/
|
61
|
+
available = $1
|
62
|
+
elsif line =~ /Latest version installed: (.*)/
|
63
|
+
installed = $1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
available = installed unless available
|
68
|
+
[available, installed]
|
69
|
+
end
|
70
|
+
|
71
|
+
def candidate_version
|
72
|
+
return @candidate_version if @candidate_version
|
73
|
+
|
74
|
+
status = popen4("emerge --color n --nospinner --search #{@new_resource.package_name.split('/').last}") do |pid, stdin, stdout, stderr|
|
75
|
+
available, installed = parse_emerge(@new_resource.package_name, stdout.read)
|
76
|
+
@candidate_version = available
|
77
|
+
end
|
78
|
+
|
79
|
+
unless status.exitstatus == 0
|
80
|
+
raise Chef::Exceptions::Package, "emerge --search failed - #{status.inspect}!"
|
81
|
+
end
|
82
|
+
|
83
|
+
@candidate_version
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def install_package(name, version)
|
89
|
+
pkg = "=#{name}-#{version}"
|
90
|
+
|
91
|
+
if(version =~ /^\~(.+)/)
|
92
|
+
# If we start with a tilde
|
93
|
+
pkg = "~#{name}-#{$1}"
|
94
|
+
end
|
95
|
+
|
96
|
+
run_command(
|
97
|
+
:command => "emerge -g --color n --nospinner --quiet#{expand_options(@new_resource.options)} #{pkg}"
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
def upgrade_package(name, version)
|
102
|
+
install_package(name, version)
|
103
|
+
end
|
104
|
+
|
105
|
+
def remove_package(name, version)
|
106
|
+
if(version)
|
107
|
+
pkg = "=#{@new_resource.package_name}-#{version}"
|
108
|
+
else
|
109
|
+
pkg = "#{@new_resource.package_name}"
|
110
|
+
end
|
111
|
+
|
112
|
+
run_command(
|
113
|
+
:command => "emerge --unmerge --color n --nospinner --quiet#{expand_options(@new_resource.options)} #{pkg}"
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def purge_package(name, version)
|
118
|
+
remove_package(name, version)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Joshua Timberman (<joshua@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
require 'chef/provider/package'
|
19
|
+
require 'chef/mixin/command'
|
20
|
+
require 'chef/resource/package'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Package
|
25
|
+
class Rpm < Chef::Provider::Package
|
26
|
+
|
27
|
+
def load_current_resource
|
28
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
29
|
+
@current_resource.package_name(@new_resource.package_name)
|
30
|
+
@new_resource.version(nil)
|
31
|
+
|
32
|
+
if @new_resource.source
|
33
|
+
unless ::File.exists?(@new_resource.source)
|
34
|
+
raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
|
35
|
+
end
|
36
|
+
|
37
|
+
Chef::Log.debug("Checking rpm status for #{@new_resource.package_name}")
|
38
|
+
status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr|
|
39
|
+
stdout.each do |line|
|
40
|
+
case line
|
41
|
+
when /([\w\d_.-]+)\s([\w\d_.-]+)/
|
42
|
+
@current_resource.package_name($1)
|
43
|
+
@new_resource.version($2)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
if @new_resource.action.include?(:install)
|
49
|
+
raise Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Chef::Log.debug("Checking install state for #{@current_resource.package_name}")
|
54
|
+
status = popen4("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
|
55
|
+
stdout.each do |line|
|
56
|
+
case line
|
57
|
+
when /([\w\d_.-]+)\s([\w\d_.-]+)/
|
58
|
+
Chef::Log.debug("Current version is #{$2}")
|
59
|
+
@current_resource.version($2)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
unless status.exitstatus == 0 || status.exitstatus == 1
|
65
|
+
raise Chef::Exceptions::Package, "rpm failed - #{status.inspect}!"
|
66
|
+
end
|
67
|
+
|
68
|
+
@current_resource
|
69
|
+
end
|
70
|
+
|
71
|
+
def install_package(name, version)
|
72
|
+
run_command(
|
73
|
+
:command => "rpm -i #{@new_resource.source}"
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def upgrade_package(name, version)
|
78
|
+
run_command(
|
79
|
+
:command => "rpm -U #{@new_resource.source}"
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
def remove_package(name, version)
|
84
|
+
if version
|
85
|
+
run_command(
|
86
|
+
:command => "rpm -e #{name}-#{version}"
|
87
|
+
)
|
88
|
+
else
|
89
|
+
run_command(
|
90
|
+
:command => "rpm -e #{name}"
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider/package'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
require 'chef/resource/package'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Package
|
26
|
+
class Rubygems < Chef::Provider::Package
|
27
|
+
|
28
|
+
def gem_list_parse(line)
|
29
|
+
installed_versions = Array.new
|
30
|
+
if line.match("^#{@new_resource.package_name} \\((.+?)\\)$")
|
31
|
+
installed_versions = $1.split(/, /)
|
32
|
+
installed_versions
|
33
|
+
else
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def gem_binary_path
|
39
|
+
path = @new_resource.gem_binary
|
40
|
+
path ? path : 'gem'
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_current_resource
|
44
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
45
|
+
@current_resource.package_name(@new_resource.package_name)
|
46
|
+
@current_resource.version(nil)
|
47
|
+
|
48
|
+
# First, we need to look up whether we have the local gem installed or not
|
49
|
+
status = popen4("#{gem_binary_path} list --local #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
|
50
|
+
stdout.each do |line|
|
51
|
+
installed_versions = gem_list_parse(line)
|
52
|
+
next unless installed_versions
|
53
|
+
# If the version we are asking for is installed, make that our current
|
54
|
+
# version. Otherwise, go ahead and use the highest one, which
|
55
|
+
# happens to come first in the array.
|
56
|
+
if installed_versions.detect { |v| v == @new_resource.version }
|
57
|
+
Chef::Log.debug("#{@new_resource.package_name} at version #{@new_resource.version}")
|
58
|
+
@current_resource.version(@new_resource.version)
|
59
|
+
else
|
60
|
+
iv = installed_versions.first
|
61
|
+
Chef::Log.debug("#{@new_resource.package_name} at version #{iv}")
|
62
|
+
@current_resource.version(iv)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
unless status.exitstatus == 0
|
68
|
+
raise Chef::Exceptions::Package, "#{gem_binary_path} list --local failed - #{status.inspect}!"
|
69
|
+
end
|
70
|
+
|
71
|
+
@current_resource
|
72
|
+
end
|
73
|
+
|
74
|
+
def candidate_version
|
75
|
+
return @candidate_version if @candidate_version
|
76
|
+
|
77
|
+
status = popen4("#{gem_binary_path} list --remote #{@new_resource.package_name}#{' --source=' + @new_resource.source if @new_resource.source}") do |pid, stdin, stdout, stderr|
|
78
|
+
stdout.each do |line|
|
79
|
+
installed_versions = gem_list_parse(line)
|
80
|
+
next unless installed_versions
|
81
|
+
Chef::Log.debug("candidate_version: remote rubygem(s) available: #{installed_versions.inspect}")
|
82
|
+
|
83
|
+
unless installed_versions.empty?
|
84
|
+
Chef::Log.debug("candidate_version: setting install candidate version to #{installed_versions.first}")
|
85
|
+
@candidate_version = installed_versions.first
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
unless status.exitstatus == 0
|
92
|
+
raise Chef::Exceptions::Package, "#{gem_binary_path} list --remote failed - #{status.inspect}!"
|
93
|
+
end
|
94
|
+
@candidate_version
|
95
|
+
end
|
96
|
+
|
97
|
+
def install_package(name, version)
|
98
|
+
src = nil
|
99
|
+
if @new_resource.source
|
100
|
+
src = " --source=#{@new_resource.source} --source=http://gems.rubyforge.org"
|
101
|
+
end
|
102
|
+
run_command(
|
103
|
+
:command => "#{gem_binary_path} install #{name} -q --no-rdoc --no-ri -v \"#{version}\"#{src}"
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
def upgrade_package(name, version)
|
108
|
+
install_package(name, version)
|
109
|
+
end
|
110
|
+
|
111
|
+
def remove_package(name, version)
|
112
|
+
if version
|
113
|
+
run_command(
|
114
|
+
:command => "#{gem_binary_path} uninstall #{name} -q -v \"#{version}\""
|
115
|
+
)
|
116
|
+
else
|
117
|
+
run_command(
|
118
|
+
:command => "#{gem_binary_path} uninstall #{name} -q -a"
|
119
|
+
)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def purge_package(name, version)
|
124
|
+
remove_package(name, version)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matthew Kent (<mkent@magoazul.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 Matthew Kent
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
# yum-dump.py
|
20
|
+
# Inspired by yumhelper.py by David Lutterkort
|
21
|
+
#
|
22
|
+
# Produce a list of installed and available packages using yum and dump the
|
23
|
+
# result to stdout.
|
24
|
+
#
|
25
|
+
# This invokes yum just as the command line would which makes it subject to
|
26
|
+
# all the caching related configuration paramaters in yum.conf.
|
27
|
+
#
|
28
|
+
# Can be run as non root, but that won't update the cache.
|
29
|
+
|
30
|
+
import os
|
31
|
+
import sys
|
32
|
+
import time
|
33
|
+
import yum
|
34
|
+
|
35
|
+
from yum import Errors
|
36
|
+
|
37
|
+
# Seconds to wait for exclusive access to yum
|
38
|
+
lock_timeout = 10
|
39
|
+
|
40
|
+
failure = False
|
41
|
+
|
42
|
+
# Can't do try: except: finally: in python 2.4 it seems, hence this fun.
|
43
|
+
try:
|
44
|
+
try:
|
45
|
+
y = yum.YumBase()
|
46
|
+
# Only want our output
|
47
|
+
y.doConfigSetup(debuglevel=0, errorlevel=0)
|
48
|
+
|
49
|
+
# Yum assumes it can update the cache directory. Disable this for non root
|
50
|
+
# users.
|
51
|
+
y.conf.cache = os.geteuid() != 0
|
52
|
+
|
53
|
+
# Spin up to lock_timeout.
|
54
|
+
countdown = lock_timeout
|
55
|
+
while True:
|
56
|
+
try:
|
57
|
+
y.doLock()
|
58
|
+
except Errors.LockError, e:
|
59
|
+
time.sleep(1)
|
60
|
+
countdown -= 1
|
61
|
+
if countdown == 0:
|
62
|
+
print >> sys.stderr, "Error! Couldn't obtain an exclusive yum lock in %d seconds. Giving up." % lock_timeout
|
63
|
+
failure = True
|
64
|
+
sys.exit(1)
|
65
|
+
else:
|
66
|
+
break
|
67
|
+
|
68
|
+
y.doTsSetup()
|
69
|
+
y.doRpmDBSetup()
|
70
|
+
|
71
|
+
db = y.doPackageLists('all')
|
72
|
+
|
73
|
+
y.closeRpmDB()
|
74
|
+
|
75
|
+
except Errors.YumBaseError, e:
|
76
|
+
print >> sys.stderr, "Error! %s" % e
|
77
|
+
failure = True
|
78
|
+
sys.exit(1)
|
79
|
+
|
80
|
+
# Ensure we clear the lock.
|
81
|
+
finally:
|
82
|
+
try:
|
83
|
+
y.doUnlock()
|
84
|
+
# Keep Unlock from raising a second exception as it does with a yum.conf
|
85
|
+
# config error.
|
86
|
+
except Errors.YumBaseError:
|
87
|
+
if failure == False:
|
88
|
+
print >> sys.stderr, "Error! %s" % e
|
89
|
+
sys.exit(1)
|
90
|
+
|
91
|
+
for pkg in db.installed:
|
92
|
+
print '%s,installed,%s,%s,%s,%s' % ( pkg.name,
|
93
|
+
pkg.epoch,
|
94
|
+
pkg.version,
|
95
|
+
pkg.release,
|
96
|
+
pkg.arch )
|
97
|
+
for pkg in db.available:
|
98
|
+
print '%s,available,%s,%s,%s,%s' % ( pkg.name,
|
99
|
+
pkg.epoch,
|
100
|
+
pkg.version,
|
101
|
+
pkg.release,
|
102
|
+
pkg.arch )
|
103
|
+
|
104
|
+
sys.exit(0)
|