Class RSCM::P4Admin
In: lib/rscm/scm/perforce.rb
Parent: Object

Understands p4 administrative operations (not specific to a client)

Methods

Public Class methods

[Source]

     # File lib/rscm/scm/perforce.rb, line 156
156:     def initialize(port, user, pwd)
157:       @port, @user, @pwd = port, user, pwd
158:     end

Public Instance methods

[Source]

     # File lib/rscm/scm/perforce.rb, line 199
199:     def central_exists?
200:       execute("info").split.join(" ") !~ /Connect to server failed/
201:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 168
168:     def client_exists?(rootdir, clientname)
169:       dir_regex = Regexp.new(rootdir)
170:       name_regex = Regexp.new(clientname)
171:       execute("clients").split("\n").find {|c| c =~ dir_regex && c =~ name_regex}
172:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 203
203:     def clientspec(name, rootdir)
204:       s = StringIO.new
205:       s.puts "Client: #{name}"
206:       s.puts "Owner: #{ENV["LOGNAME"]}"
207:       s.puts "Host: #{ENV["HOSTNAME"]}"
208:       s.puts "Description: another one"
209:       s.puts "Root: #{rootdir}"
210:       s.puts "Options: noallwrite noclobber nocompress unlocked nomodtime normdir"
211:       s.puts "LineEnd: local"
212:       s.puts "View: //depot/... //#{name}/..."
213:       s.string
214:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 160
160:     def create_client(rootdir, clientname)
161:       rootdir = File.expand_path(rootdir) if rootdir =~ /\.\./
162:       unless client_exists?(rootdir, clientname)
163:         execute_popen("client -i", "w+", clientspec(clientname, rootdir))
164:       end
165:       P4Client.new(rootdir, clientname, @port, @user, @pwd)
166:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 174
174:     def delete_client(client)
175:       execute("client -d #{client.name}")
176:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 228
228:     def execute(cmd)
229:       cmd = format_cmd(cmd)
230:       $stderr.puts "> executing: #{cmd}"
231:       `#{cmd}`
232:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 220
220:     def execute_popen(cmd, mode, input)
221:       IO.popen(format_cmd(cmd), mode) do |io|
222:         io.puts(input)
223:         io.close_write
224:         io.each_line {|line| debug(line)}
225:       end
226:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 234
234:     def format_cmd(cmd)
235:       "p4 -p #{@port} -u '#{@user}' -P '#{@pwd}' #{cmd} 2>&1"
236:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 182
182:     def install_trigger(trigger_command)
183:       execute_popen("triggers -i", "a+", triggerspec_append(trigger_command))
184:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 178
178:     def trigger_installed?(trigger_command)
179:       triggers.any? {|line| line =~ /#{trigger_command}/}
180:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 216
216:     def triggers
217:       execute("triggers -o")
218:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 190
190:     def triggerspec_append(trigger_command)
191:       new_trigger = " damagecontrol commit //depot/... \"#{trigger_command}\" "
192:       triggers + $/ + new_trigger
193:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 195
195:     def triggerspec_remove(trigger_command)
196:       triggers.reject {|line| line =~ /#{trigger_command}/}.join
197:     end

[Source]

     # File lib/rscm/scm/perforce.rb, line 186
186:     def uninstall_trigger(trigger_command)
187:       execute_popen("triggers -i", "a+", triggerspec_remove(trigger_command))
188:     end

[Validate]