Class: P4
- Inherits:
-
Object
- Object
- P4
- Defined in:
- lib/P4.rb
Overview
Add the extra’s written purely in ruby.
Defined Under Namespace
Classes: DepotFile, Integration, MergeInfo, OutputHandler, ReportHandler, Revision, Spec
Constant Summary collapse
- RAISE_NONE =
Named constants for the exception levels. Note they are cumulative, so RAISE_ALL includes RAISE_ERRORS (as you’d expect).
0
- RAISE_ERRORS =
1
- RAISE_ALL =
2
- MERGE_SKIP =
Named values for merge actions. Values taken from clientmerge.h in the Perforce API
1
- MERGE_ACCEPT_MERGED =
2
- MERGE_ACCEPT_EDIT =
3
- MERGE_ACCEPT_THEIRS =
4
- MERGE_ACCEPT_YOURS =
5
- EV_NONE =
misc
0
- EV_USAGE =
The fault of the user
0x01
- EV_UNKNOWN =
request not consistent with dox
0x02
- EV_CONTEXT =
using unknown entity
0x03
- EV_ILLEGAL =
using entity in wrong context
0x04
- EV_NOTYET =
trying to do something you can’t
0x05
- EV_PROTECT =
something must be corrected first
0x06
- EV_EMPTY =
No fault at all
0x11
- EV_FAULT =
not the fault of the user
0x21
- EV_CLIENT =
inexplicable program fault
0x22
- EV_ADMIN =
client side program errors
0x23
- EV_CONFIG =
server administrative action required
0x24
- EV_UPGRADE =
client configuration inadequate
0x25
- EV_COMM =
client or server too old to interact
0x26
- EV_TOOBIG =
communications error
0x27
- E_EMPTY =
Named values for error severities returned by P4::Message#severity
0
- E_INFO =
nothing yet
1
- E_WARN =
something good happened
2
- E_FAILED =
something not good happened
3
- E_FATAL =
user did something wrong
4
- REPORT =
OutputHandler return values constants
0
- HANDLED =
1
- CANCEL =
2
Instance Method Summary collapse
-
#at_exception_level(level) ⇒ Object
Allow the user to run commands at a temporarily altered exception level.
- #delete_shelve(*args) ⇒ Object
-
#inspect ⇒ Object
Show some handy information when using irb.
- #method_missing(m, *a) ⇒ Object
-
#run_filelog(*args) ⇒ Object
run_filelog: convert “p4 filelog” responses into objects with useful methods.
-
#run_login(*args) ⇒ Object
Simple interface for using “p4 login”.
-
#run_password(oldpass, newpass) ⇒ Object
Interface for changing the user’s password.
- #run_resolve(*args) ⇒ Object
-
#run_shelve(*args) ⇒ Object
Simple interface for shelving.
-
#run_submit(*args) ⇒ Object
Simple interface for submitting.
-
#with_handler(handler) ⇒ Object
Allow users to run commands using a specified handler.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/P4.rb', line 106 def method_missing( m, *a ) # Generic run_* methods if ( m.to_s =~ /^run_(.*)/ ) return self.run( $1, a ) # Generic fetch_* methods elsif ( m.to_s =~ /^fetch_(.*)/ ) return self.run( $1, "-o", a ).shift # Generic save_* methods elsif ( m.to_s =~ /^save_(.*)/ ) if ( a.length == 0 ) raise( P4Exception, "Method P4##{m.to_s} requires an argument", caller) end self.input = a.shift return self.run( $1, "-i", a ) # Generic delete_* methods elsif ( m.to_s =~ /^delete_(.*)/ ) if ( a.length == 0 ) raise( P4Exception, "Method P4##{m.to_s} requires an argument", caller) end return self.run( $1, "-d", a ) # Generic parse_* methods elsif ( m.to_s == "parse_forms" ) raise( NoMethodError, "undefined method 'P4#parse_forms'", caller ) elsif ( m.to_s =~ /^parse_(.*)/ ) if ( a.length != 1 ) raise( P4Exception, "Method P4##{m.to_s} requires an argument", caller) end return self.parse_spec( $1, a.shift ) # Generic format_* methods elsif ( m.to_s =~ /^format_(.*)/ ) if ( a.length != 1 ) raise( P4Exception, "Method P4##{m.to_s} requires an argument", caller) end return self.format_spec( $1, a.shift ) # That's all folks! else raise NameError, "No such method #{m.to_s} in class P4", caller end end |
Instance Method Details
#at_exception_level(level) ⇒ Object
Allow the user to run commands at a temporarily altered exception level. Pass the new exception level desired, and a block to be executed at that level.
309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/P4.rb', line 309 def at_exception_level( level ) return self unless block_given? old_level = self.exception_level self.exception_level = level begin yield( self ) ensure self.exception_level = old_level end self end |
#delete_shelve(*args) ⇒ Object
199 200 201 202 203 204 |
# File 'lib/P4.rb', line 199 def delete_shelve( *args ) if( ! args.include?( "-c" ) ) args.unshift( "-c") end return self.run( "shelve", "-d", args) end |
#inspect ⇒ Object
Show some handy information when using irb
341 342 343 344 345 |
# File 'lib/P4.rb', line 341 def inspect sprintf( 'P4: [%s] %s@%s (%s)', self.port, self.user, self.client, self.connected? ? 'connected' : 'not connected' ) end |
#run_filelog(*args) ⇒ Object
run_filelog: convert “p4 filelog” responses into objects with useful
methods
Requires tagged output to be of any real use. If tagged output it not enabled then you just get the raw data back
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/P4.rb', line 253 def run_filelog( *args ) raw = self.run( 'filelog', args.flatten ) raw.collect do |h| if ( ! h.kind_of?( Hash ) ) h else df = P4::DepotFile.new( h[ "depotFile" ] ) h[ "rev" ].each_index do |n| # If rev is nil, there's nothing here for us next unless h[ "rev" ][ n ] # Create a new revision of this file ready for populating r = df.new_revision h.each do |key,value| next unless( value.kind_of?( Array ) ) next unless value[ n ] next if( value[ n ].kind_of?( Array ) ) # If the field is the revision time, convert it to a Time object value[ n ] = Time.at( value[ n ].to_i ) if key == "time" r.set_attribute( key, value[ n ] ) end # Now if there are any integration records for this revision, # add them in too next unless ( h[ "how" ] ) next unless ( h[ "how" ][ n ] ) h[ "how" ][ n ].each_index do |m| how = h[ "how" ][ n ][ m ] file = h[ "file" ][ n ][ m ] srev = h[ "srev" ][ n ][ m ] erev = h[ "erev" ][ n ][ m ] srev.gsub!( /^#/, "" ) erev.gsub!( /^#/, "" ) srev = ( srev == "none" ? 0 : srev.to_i ) erev = ( erev == "none" ? 0 : erev.to_i ) r.integration( how, file, srev, erev ) end end df end end end |
#run_login(*args) ⇒ Object
Simple interface for using “p4 login”
209 210 211 212 |
# File 'lib/P4.rb', line 209 def run_login( *args ) self.input = self.password return self.run( "login", args ) end |
#run_password(oldpass, newpass) ⇒ Object
Interface for changing the user’s password. Supply the old password and the new one.
229 230 231 232 233 234 235 236 |
# File 'lib/P4.rb', line 229 def run_password( oldpass, newpass ) if( oldpass && oldpass.length > 0 ) self.input = [ oldpass, newpass, newpass ] else self.input = [ newpass, newpass ] end self.run( "password" ) end |
#run_resolve(*args) ⇒ Object
214 215 216 217 218 219 220 221 222 223 |
# File 'lib/P4.rb', line 214 def run_resolve( *args ) if( block_given? ) self.run( "resolve", args ) do |default| yield( default ) end else self.run( "resolve", args ) end end |
#run_shelve(*args) ⇒ Object
Simple interface for shelving. Same rules as for submit apply
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/P4.rb', line 180 def run_shelve( *args ) form = nil nargs = args.flatten.collect do |a| if( a.kind_of?( Hash ) ) form = a nil else a end end.compact if( form ) self.input = form nargs.push( "-i" ) end return self.run( "shelve", nargs ) end |
#run_submit(*args) ⇒ Object
Simple interface for submitting. If any argument is a Hash, (or subclass thereof - like P4::Spec), then it will be assumed to contain the change form. All other arguments are passed on to the server unchanged.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/P4.rb', line 158 def run_submit( *args ) form = nil nargs = args.flatten.collect do |a| if( a.kind_of?( Hash ) ) form = a nil else a end end.compact if( form ) self.input = form nargs.push( "-i" ) end return self.run( "submit", nargs ) end |
#with_handler(handler) ⇒ Object
Allow users to run commands using a specified handler. Pass a handler and the block that will be executed using this handler The handler will be reset to its previous value at the end of this block
326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/P4.rb', line 326 def with_handler( handler ) return self unless block_given? old_handler = self.handler self.handler = handler begin yield( self ) ensure self.handler = old_handler end self end |