|
| 1 | +# |
| 2 | +# Copyright 2015, Noah Kantrowitz |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | + |
| 17 | +require 'poise_python/resources/python_execute' |
| 18 | + |
| 19 | +require 'poise_application_python/app_mixin' |
| 20 | + |
| 21 | + |
| 22 | +module PoiseApplicationPython |
| 23 | + module Resources |
| 24 | + # (see PythonExecute::Resource) |
| 25 | + # @since 4.0.0 |
| 26 | + module PythonExecute |
| 27 | + # An `application_python_execute` resource to run Python commands inside an |
| 28 | + # Application cookbook deployment. |
| 29 | + # |
| 30 | + # @provides application_python_execute |
| 31 | + # @provides application_python_python_execute |
| 32 | + # @action run |
| 33 | + # @example |
| 34 | + # application '/srv/myapp' do |
| 35 | + # python_execute 'setup.py install' |
| 36 | + # end |
| 37 | + class Resource < PoisePython::Resources::PythonExecute::Resource |
| 38 | + include PoiseApplicationPython::AppMixin |
| 39 | + provides(:application_python_execute) |
| 40 | + provides(:application_python_python_execute) |
| 41 | + |
| 42 | + def initialize(*args) |
| 43 | + super |
| 44 | + # Clear some instance variables so my defaults work. |
| 45 | + remove_instance_variable(:@cwd) |
| 46 | + remove_instance_variable(:@group) |
| 47 | + remove_instance_variable(:@user) |
| 48 | + end |
| 49 | + |
| 50 | + # #!attribute cwd |
| 51 | + # Override the default directory to be the app path if unspecified. |
| 52 | + # @return [String] |
| 53 | + attribute(:cwd, kind_of: [String, NilClass, FalseClass], default: lazy { parent && parent.path }) |
| 54 | + |
| 55 | + # #!attribute group |
| 56 | + # Override the default group to be the app group if unspecified. |
| 57 | + # @return [String, Integer] |
| 58 | + attribute(:group, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.group }) |
| 59 | + |
| 60 | + # #!attribute user |
| 61 | + # Override the default user to be the app owner if unspecified. |
| 62 | + # @return [String, Integer] |
| 63 | + attribute(:user, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.owner }) |
| 64 | + end |
| 65 | + |
| 66 | + # The default provider for `application_python_execute`. |
| 67 | + # |
| 68 | + # @see Resource |
| 69 | + # @provides application_python_execute |
| 70 | + # @provides application_python_python_execute |
| 71 | + class Provider < PoisePython::Resources::PythonExecute::Provider |
| 72 | + provides(:application_python_execute) |
| 73 | + provides(:application_python_python_execute) |
| 74 | + |
| 75 | + private |
| 76 | + |
| 77 | + # Override environment to add the application envivonrment instead. |
| 78 | + # |
| 79 | + # @return [Hash] |
| 80 | + def environment |
| 81 | + super.tap do |environment| |
| 82 | + # Don't use the app_state_environment_python because we already have |
| 83 | + # those values in place. |
| 84 | + environment.update(new_resource.app_state_environment) |
| 85 | + # Re-apply the resource environment for correct ordering. |
| 86 | + environment.update(new_resource.environment) if new_resource.environment |
| 87 | + end |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + end |
| 92 | + end |
| 93 | +end |
0 commit comments