summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/provider/vcsrepo/dummy.rb2
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb11
-rw-r--r--lib/puppet/provider/vcsrepo/p4.rb86
3 files changed, 54 insertions, 45 deletions
diff --git a/lib/puppet/provider/vcsrepo/dummy.rb b/lib/puppet/provider/vcsrepo/dummy.rb
index f7b4e54..27bfbbe 100644
--- a/lib/puppet/provider/vcsrepo/dummy.rb
+++ b/lib/puppet/provider/vcsrepo/dummy.rb
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:dummy, :parent => Puppet::Provider::Vcsrepo) do
desc "Dummy default provider"
- defaultfor :vcsrepo => :dummy
+ defaultfor :feature => :posix
def working_copy_exists?
providers = @resource.class.providers.map{|x| x.to_s}.sort.reject{|x| x == "dummy"}.join(", ") rescue "none"
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index 9e0306b..1c6588c 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -279,7 +279,16 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
# @!visibility private
def set_excludes
- at_path { open('.git/info/exclude', 'w') { |f| @resource.value(:excludes).each { |ex| f.write(ex + "\n") }}}
+ # Excludes may be an Array or a String.
+ at_path do
+ open('.git/info/exclude', 'w') do |f|
+ if @resource.value(:excludes).respond_to?(:each)
+ @resource.value(:excludes).each { |ex| f.puts ex }
+ else
+ f.puts @resource.value(:excludes)
+ end
+ end
+ end
end
# Finds the latest revision or sha of the current branch if on a branch, or
diff --git a/lib/puppet/provider/vcsrepo/p4.rb b/lib/puppet/provider/vcsrepo/p4.rb
index 63d3df2..b429bcb 100644
--- a/lib/puppet/provider/vcsrepo/p4.rb
+++ b/lib/puppet/provider/vcsrepo/p4.rb
@@ -4,11 +4,11 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
desc "Supports Perforce depots"
has_features :filesystem_types, :reference_tracking, :p4config
-
+
def create
- # create or update client
+ # create or update client
create_client(client_name)
-
+
# if source provided, sync client
source = @resource.value(:source)
if source
@@ -22,12 +22,12 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
def working_copy_exists?
# Check if the server is there, or raise error
p4(['info'], {:marshal => false})
-
+
# Check if workspace is setup
args = ['where']
args.push(@resource.value(:path) + "...")
hash = p4(args, {:raise => false})
-
+
return (hash['code'] != "error")
end
@@ -49,14 +49,14 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
(rev >= self.latest)
else
true
- end
+ end
end
def latest
args = ['changes']
args.push('-m1', @resource.value(:source))
hash = p4(args)
-
+
return hash['change'].to_i
end
@@ -65,7 +65,7 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
args.push(@resource.value(:source))
hash = p4(args, {:marshal => false})
hash = marshal_cstat(hash)
-
+
revision = 0
if hash && hash['code'] != 'error'
hash['data'].each do |c|
@@ -90,7 +90,7 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
set_ownership
end
end
-
+
# Sync the client workspace files to head or specified revision.
# Params:
# +source+:: Depot path to sync
@@ -105,16 +105,16 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
end
p4(args)
end
-
- # Returns the name of the Perforce client workspace
+
+ # Returns the name of the Perforce client workspace
def client_name
p4config = @resource.value(:p4config)
-
+
# default (generated) client name
path = @resource.value(:path)
host = Facter.value('hostname')
default = "puppet-" + Digest::MD5.hexdigest(path + host)
-
+
# check config for client name
set_client = nil
if p4config && File.file?(p4config)
@@ -124,10 +124,10 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
set_client = p.match(m)[1] if m
end
end
-
+
return set_client || ENV['P4CLIENT'] || default
end
-
+
# Create (or update) a client workspace spec.
# If a client name is not provided then a hash based on the path is used.
# Params:
@@ -135,13 +135,13 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
# +path+:: The Root location of the Perforce client workspace
def create_client(client)
Puppet.debug "Creating client: #{client}"
-
+
# fetch client spec
hash = parse_client(client)
hash['Root'] = @resource.value(:path)
hash['Description'] = "Generated by Puppet VCSrepo"
-
- # check is source is a Stream
+
+ # check is source is a Stream
source = @resource.value(:source)
if source
parts = source.split(/\//)
@@ -154,7 +154,7 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
end
end
end
-
+
# save client spec
save_client(hash)
end
@@ -170,15 +170,15 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
return hash
end
-
-
- # Saves the client workspace spec from the given hash
+
+
+ # Saves the client workspace spec from the given hash
# Params:
# +hash+:: hash map of client spec
def save_client(hash)
spec = String.new
view = "\nView:\n"
-
+
hash.keys.sort.each do |k|
v = hash[k]
next if( k == "code" )
@@ -187,40 +187,40 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
else
spec += "#{k.to_s}: #{v.to_s}\n"
end
- end
+ end
spec += view
-
+
args = ['client']
args.push('-i')
p4(args, {:input => spec, :marshal => false})
- end
-
+ end
+
# Sets Perforce Configuration environment.
# P4CLIENT generated, but overwitten if defined in config.
def config
p4config = @resource.value(:p4config)
-
+
cfg = Hash.new
cfg.store 'P4CONFIG', p4config if p4config
cfg.store 'P4CLIENT', client_name
- return cfg
+ return cfg
end
-
+
def p4(args, options = {})
# Merge custom options with defaults
- opts = {
+ opts = {
:raise => true, # Raise errors
:marshal => true, # Marshal output
}.merge(options)
-
+
cmd = ['p4']
cmd.push '-R' if opts[:marshal]
cmd.push args
cmd_str = cmd.respond_to?(:join) ? cmd.join(' ') : cmd
-
+
Puppet.debug "environment: #{config}"
Puppet.debug "command: #{cmd_str}"
-
+
hash = Hash.new
Open3.popen3(config, cmd_str) do |i, o, e, t|
# Send input stream if provided
@@ -229,13 +229,13 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
i.write opts[:input]
i.close
end
-
+
if(opts[:marshal])
hash = Marshal.load(o)
else
- hash['data'] = o.read
+ hash['data'] = o.read
end
-
+
# Raise errors, Perforce or Exec
if(opts[:raise] && !e.eof && t.value != 0)
raise Puppet::Error, "\nP4: #{e.read}"
@@ -244,22 +244,22 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
raise Puppet::Error, "\nP4: #{hash['data']}"
end
end
-
+
Puppet.debug "hash: #{hash}\n"
return hash
end
-
+
# helper method as cstat does not Marshal
def marshal_cstat(hash)
data = hash['data']
code = 'error'
-
+
list = Array.new
change = Hash.new
data.each_line do |l|
p = /^\.\.\. (.*) (.*)$/
m = p.match(l)
- if m
+ if m
change[m[1]] = m[2]
if m[1] == 'status'
code = 'stat'
@@ -268,11 +268,11 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
end
end
end
-
+
hash = Hash.new
hash.store 'code', code
hash.store 'data', list
return hash
end
-
+
end