Class: R10K::Source::SVN

Inherits:
Base
  • Object
show all
Includes:
Util::Setopts
Defined in:
lib/r10k/source/svn.rb

Overview

This class implements a source for SVN environments.

An SVN source generates environments by enumerating the branches and trunk for a given SVN remote. SVN repositories must conform to the conventional SVN repository structure with the directories trunk/, branches/, and optionally tags/ in the root of the repository. The trunk/ directory is specifically mapped to the production environment, branches are created as environments with the name of the given branch.

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Base

#basedir, #name, #prefix, #puppetfile_name

Instance Method Summary collapse

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Methods inherited from Base

#accept, #preload!

Constructor Details

#initialize(name, basedir, options = {}) ⇒ SVN

Initialize the given source.

Parameters:

  • name (String)

    The identifier for this source.

  • basedir (String)

    The base directory where the generated environments will be created.

  • options (Hash) (defaults to: {})

    An additional set of options for this source.

Options Hash (options):

  • :prefix (Boolean)

    Whether to prefix the source name to the environment directory names. Defaults to false.

  • :remote (String)

    The URL to the base directory of the SVN repository

  • :username (String)

    The SVN username

  • :password (String)

    The SVN password

  • :puppetfile_name (String)

    The puppetfile name

Since:

  • 1.3.0



59
60
61
62
63
64
65
66
# File 'lib/r10k/source/svn.rb', line 59

def initialize(name, basedir, options = {})
  super

  setopts(options, {:remote => :self, :username => :self, :password => :self, :puppetfile_name => :self })
  @environments = []
  @svn_remote = R10K::SVN::Remote.new(@remote, :username => @username, :password => @password)
  @ignore_branch_prefixes = options[:ignore_branch_prefixes]
end

Instance Attribute Details

#ignore_branch_prefixesObject (readonly)

Since:

  • 1.3.0



43
44
45
# File 'lib/r10k/source/svn.rb', line 43

def ignore_branch_prefixes
  @ignore_branch_prefixes
end

#passwordObject (readonly)

Since:

  • 1.3.0



38
39
40
# File 'lib/r10k/source/svn.rb', line 38

def password
  @password
end

#remoteObject (readonly)

Since:

  • 1.3.0



23
24
25
# File 'lib/r10k/source/svn.rb', line 23

def remote
  @remote
end

#svn_remoteObject (readonly)

Since:

  • 1.3.0



28
29
30
# File 'lib/r10k/source/svn.rb', line 28

def svn_remote
  @svn_remote
end

#usernameObject (readonly)

Since:

  • 1.3.0



33
34
35
# File 'lib/r10k/source/svn.rb', line 33

def username
  @username
end

Instance Method Details

#desired_contentsArray<String>

Note:

This is required by Util::Basedir

List all environments that should exist in the basedir for this source

Returns:

  • (Array<String>)

Since:

  • 1.3.0



106
107
108
# File 'lib/r10k/source/svn.rb', line 106

def desired_contents
  @environments.map {|env| env.dirname }
end

#environmentsArray<R10K::Environment::SVN>

Enumerate the environments associated with this SVN source.

Returns:

Since:

  • 1.3.0



76
77
78
79
80
81
82
# File 'lib/r10k/source/svn.rb', line 76

def environments
  if @environments.empty?
    @environments = generate_environments()
  end

  @environments
end

#filter_branches(branches, ignore_prefixes) ⇒ Object

Since:

  • 1.3.0



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/r10k/source/svn.rb', line 110

def filter_branches(branches, ignore_prefixes)
  filter = Regexp.new("^(#{ignore_prefixes.join('|')})")
  branches = branches.reject do |branch|
    result = filter.match(branch)
    if result
      logger.warn _("Branch %{branch} filtered out by ignore_branch_prefixes %{ibp}") % {branch: branch, ibp: @ignore_branch_prefixes}
    end
    result
  end
  branches
end

#generate_environmentsArray<R10K::Environment::SVN>

TODO:

respect environment name corrections

Generate a list of currently available SVN environments

Returns:

Since:

  • 1.3.0



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/r10k/source/svn.rb', line 91

def generate_environments
  names_and_paths.map do |(branch, path)|
    options = {
      :remote   => path,
      :username => @username,
      :password => @password,
      :puppetfile_name => puppetfile_name
    }
    R10K::Environment::SVN.new(branch.name, @basedir, branch.dirname, options)
  end
end

#reload!Object

Since:

  • 1.3.0



68
69
70
# File 'lib/r10k/source/svn.rb', line 68

def reload!
  @environments = generate_environments()
end