Class: RSCM::P4Admin
- Inherits:
-
Object
- Object
- RSCM::P4Admin
- Defined in:
- lib/rscm/scm/perforce.rb
Overview
Understands p4 administrative operations (not specific to a client)
Instance Method Summary collapse
- #central_exists? ⇒ Boolean
- #client_exists?(rootdir, clientname) ⇒ Boolean
- #clientspec(name, rootdir) ⇒ Object
- #create_client(rootdir, clientname) ⇒ Object
- #delete_client(client) ⇒ Object
- #execute(cmd) ⇒ Object
- #execute_popen(cmd, mode, input) ⇒ Object
- #format_cmd(cmd) ⇒ Object
-
#initialize(port, user, pwd) ⇒ P4Admin
constructor
A new instance of P4Admin.
- #install_trigger(trigger_command) ⇒ Object
- #trigger_installed?(trigger_command) ⇒ Boolean
- #triggers ⇒ Object
- #triggerspec_append(trigger_command) ⇒ Object
- #triggerspec_remove(trigger_command) ⇒ Object
- #uninstall_trigger(trigger_command) ⇒ Object
Constructor Details
#initialize(port, user, pwd) ⇒ P4Admin
Returns a new instance of P4Admin.
156 157 158 |
# File 'lib/rscm/scm/perforce.rb', line 156 def initialize(port, user, pwd) @port, @user, @pwd = port, user, pwd end |
Instance Method Details
#central_exists? ⇒ Boolean
199 200 201 |
# File 'lib/rscm/scm/perforce.rb', line 199 def central_exists? execute("info").split.join(" ") !~ /Connect to server failed/ end |
#client_exists?(rootdir, clientname) ⇒ Boolean
168 169 170 171 172 |
# File 'lib/rscm/scm/perforce.rb', line 168 def client_exists?(rootdir, clientname) dir_regex = Regexp.new(rootdir) name_regex = Regexp.new(clientname) execute("clients").split("\n").find {|c| c =~ dir_regex && c =~ name_regex} end |
#clientspec(name, rootdir) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/rscm/scm/perforce.rb', line 203 def clientspec(name, rootdir) s = StringIO.new s.puts "Client: #{name}" s.puts "Owner: #{ENV["LOGNAME"]}" s.puts "Host: #{ENV["HOSTNAME"]}" s.puts "Description: another one" s.puts "Root: #{rootdir}" s.puts "Options: noallwrite noclobber nocompress unlocked nomodtime normdir" s.puts "LineEnd: local" s.puts "View: //depot/... //#{name}/..." s.string end |
#create_client(rootdir, clientname) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/rscm/scm/perforce.rb', line 160 def create_client(rootdir, clientname) rootdir = File.(rootdir) if rootdir =~ /\.\./ unless client_exists?(rootdir, clientname) execute_popen("client -i", "w+", clientspec(clientname, rootdir)) end P4Client.new(rootdir, clientname, @port, @user, @pwd) end |
#delete_client(client) ⇒ Object
174 175 176 |
# File 'lib/rscm/scm/perforce.rb', line 174 def delete_client(client) execute("client -d #{client.name}") end |
#execute(cmd) ⇒ Object
228 229 230 231 232 |
# File 'lib/rscm/scm/perforce.rb', line 228 def execute(cmd) cmd = format_cmd(cmd) $stderr.puts "> executing: #{cmd}" `#{cmd}` end |
#execute_popen(cmd, mode, input) ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/rscm/scm/perforce.rb', line 220 def execute_popen(cmd, mode, input) IO.popen(format_cmd(cmd), mode) do |io| io.puts(input) io.close_write io.each_line {|line| debug(line)} end end |
#format_cmd(cmd) ⇒ Object
234 235 236 |
# File 'lib/rscm/scm/perforce.rb', line 234 def format_cmd(cmd) "p4 -p #{@port} -u '#{@user}' -P '#{@pwd}' #{cmd} 2>&1" end |
#install_trigger(trigger_command) ⇒ Object
182 183 184 |
# File 'lib/rscm/scm/perforce.rb', line 182 def install_trigger(trigger_command) execute_popen("triggers -i", "a+", triggerspec_append(trigger_command)) end |
#trigger_installed?(trigger_command) ⇒ Boolean
178 179 180 |
# File 'lib/rscm/scm/perforce.rb', line 178 def trigger_installed?(trigger_command) triggers.any? {|line| line =~ /#{trigger_command}/} end |
#triggers ⇒ Object
216 217 218 |
# File 'lib/rscm/scm/perforce.rb', line 216 def triggers execute("triggers -o") end |
#triggerspec_append(trigger_command) ⇒ Object
190 191 192 193 |
# File 'lib/rscm/scm/perforce.rb', line 190 def triggerspec_append(trigger_command) new_trigger = " damagecontrol commit //depot/... \"#{trigger_command}\" " triggers + $/ + new_trigger end |
#triggerspec_remove(trigger_command) ⇒ Object
195 196 197 |
# File 'lib/rscm/scm/perforce.rb', line 195 def triggerspec_remove(trigger_command) triggers.reject {|line| line =~ /#{trigger_command}/}.join end |
#uninstall_trigger(trigger_command) ⇒ Object
186 187 188 |
# File 'lib/rscm/scm/perforce.rb', line 186 def uninstall_trigger(trigger_command) execute_popen("triggers -i", "a+", triggerspec_remove(trigger_command)) end |