Class: Chef::Provider::Subversion
Instance Attribute Summary
#current_resource, #new_resource, #run_context
Instance Method Summary
collapse
#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale
#popen4
#popen4
#action_nothing, build_from_file, #cookbook_name, #initialize, #node, #resource_collection
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
#method_missing
#data_bag, #data_bag_item, #platform?, #search, #value_for_platform
Constructor Details
This class inherits a constructor from Chef::Provider
Instance Method Details
#action_checkout ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/chef/provider/subversion.rb', line 41
def action_checkout
assert_target_directory_valid!
if target_dir_non_existant_or_empty?
run_command(run_options(:command => checkout_command))
@new_resource.updated_by_last_action(true)
else
Chef::Log.debug "#{@new_resource} checkout destination #{@new_resource.destination} already exists or is a non-empty directory - nothing to do"
end
end
|
#action_export ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/chef/provider/subversion.rb', line 51
def action_export
assert_target_directory_valid!
if target_dir_non_existant_or_empty?
run_command(run_options(:command => export_command))
@new_resource.updated_by_last_action(true)
else
Chef::Log.debug "#{@new_resource} export destination #{@new_resource.destination} already exists or is a non-empty directory - nothing to do"
end
end
|
#action_force_export ⇒ Object
61
62
63
64
65
|
# File 'lib/chef/provider/subversion.rb', line 61
def action_force_export
assert_target_directory_valid!
run_command(run_options(:command => export_command))
@new_resource.updated_by_last_action(true)
end
|
#action_sync ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/chef/provider/subversion.rb', line 67
def action_sync
assert_target_directory_valid!
if ::File.exist?(::File.join(@new_resource.destination, ".svn"))
current_rev = find_current_revision
Chef::Log.debug "#{@new_resource} current revision: #{current_rev} target revision: #{revision_int}"
unless current_revision_matches_target_revision?
run_command(run_options(:command => sync_command))
Chef::Log.info "#{@new_resource} updated to revision: #{revision_int}"
@new_resource.updated_by_last_action(true)
end
else
action_checkout
@new_resource.updated_by_last_action(true)
end
end
|
#checkout_command ⇒ Object
89
90
91
92
93
94
|
# File 'lib/chef/provider/subversion.rb', line 89
def checkout_command
c = scm :checkout, @new_resource.svn_arguments, verbose, authentication,
"-r#{revision_int}", @new_resource.repository, @new_resource.destination
Chef::Log.info "#{@new_resource} checked out #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
c
end
|
#current_revision_matches_target_revision? ⇒ Boolean
134
135
136
|
# File 'lib/chef/provider/subversion.rb', line 134
def current_revision_matches_target_revision?
(!@current_resource.revision.nil?) && (revision_int.strip.to_i == @current_resource.revision.strip.to_i)
end
|
#export_command ⇒ Object
96
97
98
99
100
101
102
103
|
# File 'lib/chef/provider/subversion.rb', line 96
def export_command
args = ["--force"]
args << @new_resource.svn_arguments << verbose << authentication <<
"-r#{revision_int}" << @new_resource.repository << @new_resource.destination
c = scm :export, *args
Chef::Log.info "#{@new_resource} exported #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
c
end
|
#find_current_revision ⇒ Object
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/chef/provider/subversion.rb', line 123
def find_current_revision
return nil unless ::File.exist?(::File.join(@new_resource.destination, ".svn"))
command = scm(:info)
status, svn_info, error_message = output_of_command(command, run_options(:cwd => cwd))
unless [0,1].include?(status.exitstatus)
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
end
(svn_info)
end
|
#load_current_resource ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/chef/provider/subversion.rb', line 31
def load_current_resource
@current_resource = Chef::Resource::Subversion.new(@new_resource.name)
unless [:export, :force_export].include?(Array(@new_resource.action).first)
if current_revision = find_current_revision
@current_resource.revision current_revision
end
end
end
|
#revision_int ⇒ Object
Also known as:
revision_slug
If the specified revision isn’t an integer (“HEAD” for example), look up the revision id by asking the server If the specified revision is an integer, trust it.
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/chef/provider/subversion.rb', line 108
def revision_int
@revision_int ||= begin
if @new_resource.revision =~ /^\d+$/
@new_resource.revision
else
command = scm(:info, @new_resource.repository, @new_resource.svn_info_args, authentication, "-r#{@new_resource.revision}")
status, svn_info, error_message = output_of_command(command, run_options)
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
(svn_info)
end
end
end
|
#run_options(run_opts = {}) ⇒ Object
138
139
140
141
142
|
# File 'lib/chef/provider/subversion.rb', line 138
def run_options(run_opts={})
run_opts[:user] = @new_resource.user if @new_resource.user
run_opts[:group] = @new_resource.group if @new_resource.group
run_opts
end
|
#sync_command ⇒ Object
83
84
85
86
87
|
# File 'lib/chef/provider/subversion.rb', line 83
def sync_command
c = scm :update, @new_resource.svn_arguments, verbose, authentication, "-r#{revision_int}", @new_resource.destination
Chef::Log.debug "#{@new_resource} updated working copy #{@new_resource.destination} to revision #{@new_resource.revision}"
c
end
|