]> git.pld-linux.org Git - packages/chef.git/blame - poldek.patch
Fix --no-ri patch
[packages/chef.git] / poldek.patch
CommitLineData
0e535bd2
ER
1poldek package manager support
2
3e14fa30 3https://github.com/chef/chef/pull/7482
0e535bd2 4
3e14fa30
ER
5diff --git a/lib/chef/provider/package/poldek.rb b/lib/chef/provider/package/poldek.rb
6new file mode 100644
bcb6b0f6 7index 000000000..a4d17ba67
3e14fa30
ER
8--- /dev/null
9+++ b/lib/chef/provider/package/poldek.rb
bcb6b0f6 10@@ -0,0 +1,137 @@
0e535bd2
ER
11+#
12+# Author:: Elan Ruusamäe (glen@pld-linux.org)
3e14fa30 13+# Copyright:: Copyright (c) 2013,2018 Elan Ruusamäe
0e535bd2
ER
14+# License:: Apache License, Version 2.0
15+#
16+# Licensed under the Apache License, Version 2.0 (the "License");
17+# you may not use this file except in compliance with the License.
18+# You may obtain a copy of the License at
19+#
20+# http://www.apache.org/licenses/LICENSE-2.0
21+#
22+# Unless required by applicable law or agreed to in writing, software
23+# distributed under the License is distributed on an "AS IS" BASIS,
24+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+# See the License for the specific language governing permissions and
26+# limitations under the License.
27+#
28+
29+require 'digest/md5'
30+require 'chef/provider/package'
31+require 'chef/mixin/shell_out'
32+require 'chef/resource/package'
0e535bd2
ER
33+
34+class Chef
35+ class Provider
36+ class Package
37+ class Poldek < Chef::Provider::Package
38+ include Chef::Mixin::ShellOut
bcb6b0f6
ER
39+
40+ allow_nils
41+ use_multipackage_api
0e535bd2 42+
3e14fa30
ER
43+ provides :package, platform_family: "pld"
44+
0e535bd2 45+ def load_current_resource
bcb6b0f6
ER
46+ logger.debug("#{new_resource} loading current resource")
47+ @current_resource = Chef::Resource::Package.new(new_resource.name)
48+ current_resource.package_name(new_resource.package_name)
49+ current_resource.version(get_current_versions)
50+ current_resource
0e535bd2
ER
51+ end
52+
bcb6b0f6
ER
53+ def candidate_version
54+ @candidate_version ||= get_candidate_versions
55+ end
0e535bd2 56+
bcb6b0f6
ER
57+ def get_current_versions
58+ names = package_name_array
59+ logger.debug("#{new_resource} checking current version: #{names}")
0e535bd2 60+
bcb6b0f6
ER
61+ # rpm works as expected: output is returned in order as input given, even duplicates
62+ cmd = rpm("-q", "--qf", "%{NAME} %{VERSION}\n", names)
63+ versions_from_name_list(cmd.stdout, names)
0e535bd2
ER
64+ end
65+
bcb6b0f6
ER
66+ def get_candidate_versions
67+ names = package_name_array
68+ logger.debug("#{new_resource} check candidate version");
69+
70+ update_indexes
0e535bd2 71+
bcb6b0f6
ER
72+ # poldek works unexpectedly: packages that don't exist are printed as errors first, and names are de-duplicated
73+ cmd = poldek(%w{--uniq --skip-installed} + options.to_a + ["--cmd", "ls --qf '%{NAME} %{VERSION}\n'", names])
74+ versions_from_name_list(cmd.stdout, names)
0e535bd2
ER
75+ end
76+
bcb6b0f6
ER
77+ def install_package(names, versions)
78+ logger.trace("#{new_resource} installing package #{names} version #{versions}")
79+ update_indexes
80+ poldek(options, "-u", names)
0e535bd2
ER
81+ end
82+
bcb6b0f6
ER
83+ def upgrade_package(names, versions)
84+ logger.trace("#{new_resource} upgrading package #{names} version #{versions}")
85+ install_package(names, versions)
0e535bd2
ER
86+ end
87+
bcb6b0f6
ER
88+ def remove_package(names, versions)
89+ logger.trace("#{new_resource} removing package #{names} version #{versions}")
90+ poldek(options, "-e", names)
0e535bd2
ER
91+ end
92+
93+ private
94+ @@updated = Hash.new
95+
0e535bd2 96+ def update_indexes()
bcb6b0f6 97+ checksum = Digest::MD5.hexdigest(opts).to_s
0e535bd2
ER
98+
99+ if @@updated[checksum]
100+ return
101+ end
bcb6b0f6
ER
102+
103+ logger.debug("#{@new_resource} updating package indexe")
104+ poldek("--up", options, :env => nil)
0e535bd2
ER
105+ @@updated[checksum] = true
106+ end
bcb6b0f6
ER
107+
108+ def opts
109+ expand_options(options)
110+ end
111+
112+ def versions_from_name_list(input, names)
113+ packages = extract_packages(input)
114+ versions = match_versions(names, packages)
115+ versions
116+ end
117+
118+ def extract_packages(output)
119+ packages = {}
120+ output.each_line do |line|
121+ case line.rstrip
122+ when /^package (.+) is not installed$/
123+ when /(.+): no such package or directory$/
124+ when /^(.+?) (.+)$/
125+ packages[$1] = $2
126+ end
127+ end
128+ packages
129+ end
130+
131+ def match_versions(names, packages)
132+ names.map do |name|
133+ packages[name]
134+ end
135+ end
136+
137+ def rpm(*args)
138+ shell_out_compact_timeout!("rpm", *args, env: nil, returns: [0, 1])
139+ end
140+
141+ def poldek(*args)
142+ shell_out_compact_timeout!(%w{poldek -q --noask}, *args, env: nil, returns: [0, 1, 255])
143+ end
0e535bd2
ER
144+ end
145+ end
146+ end
147+end
3e14fa30
ER
148diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb
149index cd265b061..075ffd7e8 100644
150--- a/lib/chef/providers.rb
151+++ b/lib/chef/providers.rb
152@@ -74,6 +74,7 @@ require "chef/provider/package/macports"
c8ed2d9c
ER
153 require "chef/provider/package/openbsd"
154 require "chef/provider/package/pacman"
c8ed2d9c 155 require "chef/provider/package/portage"
3e14fa30 156+require 'chef/provider/package/poldek'
c8ed2d9c
ER
157 require "chef/provider/package/paludis"
158 require "chef/provider/package/rpm"
3e14fa30
ER
159 require "chef/provider/package/rubygems"
160diff --git a/lib/chef/resource/poldek_package.rb b/lib/chef/resource/poldek_package.rb
161new file mode 100644
bcb6b0f6 162index 000000000..4db9aa824
3e14fa30
ER
163--- /dev/null
164+++ b/lib/chef/resource/poldek_package.rb
bcb6b0f6 165@@ -0,0 +1,41 @@
0e535bd2
ER
166+#
167+# Author:: Elan Ruusamäe (glen@pld-linux.org)
bcb6b0f6 168+# Copyright:: Copyright (c) 2013,2018 Elan Ruusamäe
0e535bd2
ER
169+# License:: Apache License, Version 2.0
170+#
171+# Licensed under the Apache License, Version 2.0 (the "License");
172+# you may not use this file except in compliance with the License.
173+# You may obtain a copy of the License at
174+#
175+# http://www.apache.org/licenses/LICENSE-2.0
176+#
177+# Unless required by applicable law or agreed to in writing, software
178+# distributed under the License is distributed on an "AS IS" BASIS,
179+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180+# See the License for the specific language governing permissions and
181+# limitations under the License.
182+#
183+
184+require 'chef/resource/package'
185+require 'chef/provider/package/poldek'
186+
187+class Chef
188+ class Resource
189+ class PoldekPackage < Chef::Resource::Package
bcb6b0f6 190+ extend Chef::Mixin::Which
0e535bd2 191+
bcb6b0f6
ER
192+ resource_name :poldek_package
193+
194+ provides :package do
195+ which("poldek")
0e535bd2
ER
196+ end
197+
bcb6b0f6
ER
198+ provides :poldek_package
199+
200+ description "Use the poldek_package resource to install, upgrade, and remove packages with poldek."
201+ introduced "14.3"
202+
203+ allowed_actions :install, :upgrade, :remove
0e535bd2
ER
204+ end
205+ end
206+end
This page took 0.050906 seconds and 4 git commands to generate.