Class: Chef::Provider::Subversion

Inherits:
Chef::Provider show all
Includes:
Mixin::Command
Defined in:
lib/chef/provider/subversion.rb

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #node

Instance Method Summary collapse

Methods included from Mixin::Command

handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #initialize

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #filename_to_qualified_string

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Constructor Details

This class inherits a constructor from Chef::Provider

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Method Details

#action_checkoutObject



38
39
40
41
# File 'lib/chef/provider/subversion.rb', line 38

def action_checkout
  run_command(run_options(:command => checkout_command))
  @new_resource.updated = true
end

#action_exportObject



43
44
45
46
# File 'lib/chef/provider/subversion.rb', line 43

def action_export
  run_command(run_options(:command => export_command))
  @new_resource.updated = true
end

#action_syncObject



48
49
50
51
52
53
54
55
# File 'lib/chef/provider/subversion.rb', line 48

def action_sync
  if !::File.exist?(@new_resource.destination + "/.svn") || ::Dir.entries(@new_resource.destination) == ['.','..']
    action_checkout
  else
    run_command(run_options(:command => sync_command))
  end
  @new_resource.updated = true
end

#checkout_commandObject



62
63
64
65
66
# File 'lib/chef/provider/subversion.rb', line 62

def checkout_command
  Chef::Log.info "checking out #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
  scm :checkout, @new_resource.svn_arguments, verbose, authentication, 
      "-r#{revision_int}", @new_resource.repository, @new_resource.destination
end

#export_commandObject



68
69
70
71
72
# File 'lib/chef/provider/subversion.rb', line 68

def export_command
  Chef::Log.info "exporting #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
  scm :export, @new_resource.svn_arguments, verbose, authentication,
      "-r#{revision_int}", @new_resource.repository, @new_resource.destination
end

#find_current_revisionObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/chef/provider/subversion.rb', line 92

def find_current_revision
  return nil unless ::File.exist?(@new_resource.destination)
  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
  extract_revision_info(svn_info)
end

#load_current_resourceObject



31
32
33
34
35
36
# File 'lib/chef/provider/subversion.rb', line 31

def load_current_resource
  @current_resource = Chef::Resource::Subversion.new(@new_resource.name)
  if current_revision = find_current_revision
    @current_resource.revision current_revision
  end
end

#revision_intObject 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.



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef/provider/subversion.rb', line 77

def revision_int
  @revision_int ||= begin
    if @new_resource.revision =~ /^\d+$/
      @new_resource.revision
    else
      command = scm(:info, @new_resource.repository, 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}")
      extract_revision_info(svn_info)
    end
  end
end

#run_options(run_opts = {}) ⇒ Object



103
104
105
106
# File 'lib/chef/provider/subversion.rb', line 103

def run_options(run_opts={})
  run_opts[:user] = @new_resource.user if @new_resource.user
  run_opts
end

#sync_commandObject



57
58
59
60
# File 'lib/chef/provider/subversion.rb', line 57

def sync_command
  Chef::Log.info "Updating working copy #{@new_resource.destination} to revision #{@new_resource.revision}"
  scm :update, @new_resource.svn_arguments, verbose, authentication, "-r#{revision_int}", @new_resource.destination
end