summaryrefslogtreecommitdiff
path: root/lib/puppet/provider/vcsrepo
diff options
context:
space:
mode:
authorAaron Stone <aaron@serendipity.cx>2014-09-13 22:48:18 -0700
committerAaron Stone <aaron@serendipity.cx>2014-09-17 15:05:47 -0700
commit96d1cc90cf3caa72f6b9d69f85389b2960c27792 (patch)
treeeb9e0bb953ef79c9f92594c18e49ea780e7790b2 /lib/puppet/provider/vcsrepo
parentdaff68c3a040abd5c8b4e3119bf2f56c23b4ca5b (diff)
downloadpuppet-vcsrepo-96d1cc90cf3caa72f6b9d69f85389b2960c27792.tar.gz
puppet-vcsrepo-96d1cc90cf3caa72f6b9d69f85389b2960c27792.tar.bz2
Remove excess whitespace
Diffstat (limited to 'lib/puppet/provider/vcsrepo')
-rw-r--r--lib/puppet/provider/vcsrepo/p4.rb86
1 files changed, 43 insertions, 43 deletions
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