Class: RightScale::SvnScraper

Inherits:
ScraperBase show all
Defined in:
lib/right_scraper/scrapers/svn_scraper.rb

Instance Attribute Summary

Attributes inherited from ScraperBase

#errors, #repo, #repo_dir, #root_dir

Instance Method Summary collapse

Methods inherited from ScraperBase

#initialize, #scrape, #succeeded?

Constructor Details

This class inherits a constructor from RightScale::ScraperBase

Instance Method Details

#incremental_update?Boolean

Check whether it is possible to perform an incremental update of the repo

Return

true

Scrape directory contains files belonging to the scraped repo and protocol supports incremental updates

false

Otherwise

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/right_scraper/scrapers/svn_scraper.rb', line 34

def incremental_update?
  return false unless File.directory?(@repo_dir)
  Dir.chdir(@repo_dir) do
    info = `svn info`
    $?.success? && info =~ (/^URL: (.*)$/) && $1 == @repo.url
  end
end

#scrape_impObject

Scrape SVN repository, see RightScale::Scraper#scrape

Return

true

Always return true



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/right_scraper/scrapers/svn_scraper.rb', line 46

def scrape_imp
  msg = @incremental ? "Updating " : "Checking out "
  msg += "SVN repository '#{@repo.display_name}'"
  @callback.call(msg, is_step=true) if @callback
  if @incremental
    svn_cmd = "svn update --non-interactive --quiet" +
    (@repo.first_credential ? " --username #{@repo.first_credential}" : '') +
    (@repo.second_credential ? " --password #{@repo.second_credential}" : '') +
    ' 2>&1'
    Dir.chdir(@repo_dir) do
      res = `#{svn_cmd}`
      if $? != 0
        @callback.call("Failed to update repo: #{res}, falling back to checkout", is_step=false) if @callback
        FileUtils.rm_rf(@repo_dir)
        @incremental = false
      end
    end
  end
  if !@incremental
    svn_cmd = "svn checkout #{@repo.url} #{@repo_dir} --non-interactive --quiet" +
    (!@repo.tag.nil? && !@repo.tag.empty? ? " --revision #{@repo.tag}" : '') +
    (@repo.first_credential ? " --username #{@repo.first_credential}" : '') +
    (@repo.second_credential ? " --password #{@repo.second_credential}" : '') +
    ' 2>&1'
    res = `#{svn_cmd}`
    @errors << res if $? != 0
  end
  true
end