Class: RSCM::Perforce::P4Daemon

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/rscm/perforce/perforce.rb

Instance Method Summary collapse

Constructor Details

#initialize(depotpath) ⇒ P4Daemon

Returns a new instance of P4Daemon.



127
128
129
# File 'lib/rscm/perforce/perforce.rb', line 127

def initialize(depotpath)
  @depotpath = depotpath
end

Instance Method Details

#assert_runningObject



137
138
139
# File 'lib/rscm/perforce/perforce.rb', line 137

def assert_running
  raise "p4d did not start properly" if timeout(10) { running? }
end

#launchObject



141
142
143
144
145
146
147
148
149
# File 'lib/rscm/perforce/perforce.rb', line 141

def launch
  fork do
    mkdir_p(@depotpath)
    cd(@depotpath)
    debug "starting p4 server"
    exec("p4d")
  end
  at_exit { shutdown }
end

#running?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/rscm/perforce/perforce.rb', line 155

def running?
  !`p4 -p 1666 info`.empty?
end

#shutdownObject



151
152
153
# File 'lib/rscm/perforce/perforce.rb', line 151

def shutdown
  `p4 -p 1666 admin stop`
end

#startObject



131
132
133
134
135
# File 'lib/rscm/perforce/perforce.rb', line 131

def start
  shutdown if running?
  launch
  assert_running
end