]> git.pld-linux.org Git - packages/chef.git/blob - poldek.patch
Fix --no-ri patch
[packages/chef.git] / poldek.patch
1 poldek package manager support
2
3 https://tickets.opscode.com/browse/CHEF-4476
4 https://github.com/opscode/chef/pull/1225
5
6 --- chef-11.12.8/lib/chef/provider/package/poldek.rb    1970-01-01 02:00:00.000000000 +0200
7 +++ chef-11.12.8.poldek/lib/chef/provider/package/poldek.rb     2014-12-04 18:27:24.468416380 +0200
8 @@ -0,0 +1,123 @@
9 +#
10 +# Author:: Elan Ruusamäe (glen@pld-linux.org)
11 +# Copyright:: Copyright (c) 2013 Elan Ruusamäe
12 +# License:: Apache License, Version 2.0
13 +#
14 +# Licensed under the Apache License, Version 2.0 (the "License");
15 +# you may not use this file except in compliance with the License.
16 +# You may obtain a copy of the License at
17 +#
18 +#     http://www.apache.org/licenses/LICENSE-2.0
19 +#
20 +# Unless required by applicable law or agreed to in writing, software
21 +# distributed under the License is distributed on an "AS IS" BASIS,
22 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 +# See the License for the specific language governing permissions and
24 +# limitations under the License.
25 +#
26 +
27 +require 'digest/md5'
28 +require 'chef/provider/package'
29 +require 'chef/mixin/shell_out'
30 +require 'chef/resource/package'
31 +require 'chef/mixin/get_source_from_package'
32 +
33 +class Chef
34 +  class Provider
35 +    class Package
36 +      class Poldek < Chef::Provider::Package
37 +        include Chef::Mixin::ShellOut
38 +        attr_accessor :is_virtual_package
39 +
40 +        def load_current_resource
41 +            Chef::Log.debug("#{@new_resource} loading current resource")
42 +            @current_resource = Chef::Resource::Package.new(@new_resource.name)
43 +            @current_resource.package_name(@new_resource.package_name)
44 +            @current_resource.version(nil)
45 +            check_package_state
46 +            @current_resource # modified by check_package_state
47 +        end
48 +
49 +        def check_package_state()
50 +            Chef::Log.debug("#{@new_resource} checking package #{@new_resource.package_name}")
51 +
52 +            installed = false
53 +            @current_resource.version(nil)
54 +
55 +            out = shell_out!("rpm -q #{@new_resource.package_name}", :env => nil, :returns => [0,1])
56 +            if out.stdout
57 +                Chef::Log.debug("rpm STDOUT: #{out.stdout}");
58 +                version = version_from_nvra(out.stdout)
59 +                if version
60 +                    @current_resource.version(version)
61 +                    installed = true
62 +                end
63 +            end
64 +
65 +            return installed
66 +        end
67 +
68 +        def candidate_version
69 +            Chef::Log.debug("poldek check candidate version for #{@new_resource.package_name}");
70 +            return @candidate_version if @candidate_version
71 +
72 +            update_indexes
73 +            cmd = "poldek -q --uniq --skip-installed #{expand_options(@new_resource.options)} --cmd 'ls #{@new_resource.package_name}'"
74 +            out = shell_out!(cmd, :env => nil, :returns => [0,1,255])
75 +            if out.stdout
76 +                Chef::Log.debug("poldek STDOUT: #{out.stdout}");
77 +                version = version_from_nvra(out.stdout)
78 +                if version
79 +                    @candidate_version = version
80 +                end
81 +            end
82 +            unless @candidate_version
83 +                raise Chef::Exceptions::Package, "poldek does not have a version of package #{@new_resource.package_name}"
84 +            end
85 +            @candidate_version
86 +        end
87 +
88 +        def install_package(name, version)
89 +            Chef::Log.debug("#{@new_resource} installing package #{name}-#{version}")
90 +            package = "#{name}-#{version}"
91 +            update_indexes
92 +            out = shell_out!("poldek --noask #{expand_options(@new_resource.options)} -u #{package}", :env => nil)
93 +        end
94 +
95 +        def upgrade_package(name, version)
96 +            Chef::Log.debug("#{@new_resource} upgrading package #{name}-#{version}")
97 +            install_package(name, version)
98 +        end
99 +
100 +        def remove_package(name, version)
101 +            Chef::Log.debug("#{@new_resource} removing package #{name}-#{version}")
102 +            package = "#{name}-#{version}"
103 +            out = shell_out!("poldek --noask #{expand_options(@new_resource.options)} -e #{package}", :env => nil)
104 +        end
105 +
106 +        def purge_package(name, version)
107 +            remove_package(name, version)
108 +        end
109 +
110 +        private
111 +        @@updated = Hash.new
112 +
113 +        def version_from_nvra(stdout)
114 +            stdout[/^#{Regexp.escape(@new_resource.package_name)}-(.+)/, 1]
115 +        end
116 +
117 +        def update_indexes()
118 +            Chef::Log.debug("#{@new_resource} call update indexes #{expand_options(@new_resource.options)}")
119 +            checksum = Digest::MD5.hexdigest(@new_resource.options || '').to_s
120 +
121 +            if @@updated[checksum]
122 +                return
123 +            end
124 +            Chef::Log.debug("#{@new_resource} updating package indexes: #{expand_options(@new_resource.options)}")
125 +            shell_out!("poldek --up #{expand_options(@new_resource.options)}", :env => nil)
126 +            @@updated[checksum] = true
127 +        end
128 +      end
129 +    end
130 +  end
131 +end
132 --- chef-11.14.2/lib/chef/providers.rb~ 2014-12-04 18:38:06.000000000 +0200
133 +++ chef-11.14.2/lib/chef/providers.rb  2014-12-04 18:38:39.567794339 +0200
134 @@ -62,6 +62,7 @@
135  require "chef/provider/package/macports"
136  require "chef/provider/package/pacman"
137  require "chef/provider/package/portage"
138 +require "chef/provider/package/poldek"
139  require "chef/provider/package/paludis"
140  require "chef/provider/package/rpm"
141  require "chef/provider/package/rubygems"
142 --- chef-11.12.8/lib/chef/resource/poldek_package.rb    1970-01-01 02:00:00.000000000 +0200
143 +++ chef-11.12.8.poldek/lib/chef/resource/poldek_package.rb     2014-12-04 18:27:24.438414927 +0200
144 @@ -0,0 +1,34 @@
145 +#
146 +# Author:: Elan Ruusamäe (glen@pld-linux.org)
147 +# Copyright:: Copyright (c) 2013 Elan Ruusamäe
148 +# License:: Apache License, Version 2.0
149 +#
150 +# Licensed under the Apache License, Version 2.0 (the "License");
151 +# you may not use this file except in compliance with the License.
152 +# You may obtain a copy of the License at
153 +#
154 +#     http://www.apache.org/licenses/LICENSE-2.0
155 +#
156 +# Unless required by applicable law or agreed to in writing, software
157 +# distributed under the License is distributed on an "AS IS" BASIS,
158 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159 +# See the License for the specific language governing permissions and
160 +# limitations under the License.
161 +#
162 +
163 +require 'chef/resource/package'
164 +require 'chef/provider/package/poldek'
165 +
166 +class Chef
167 +  class Resource
168 +    class PoldekPackage < Chef::Resource::Package
169 +
170 +      def initialize(name, run_context=nil)
171 +        super
172 +        @resource_name = :poldek_package
173 +        @provider = Chef::Provider::Package::Poldek
174 +      end
175 +
176 +    end
177 +  end
178 +end
This page took 0.063834 seconds and 3 git commands to generate.