MCPcopy Create free account
hub / github.com/git/git / p4_check_access

Function p4_check_access

git-p4.py:472–515  ·  view source on GitHub ↗

Check if we can access Perforce - account still logged in.

(min_expiration=1)

Source from the content-addressed store, hash-verified

470
471
472def p4_check_access(min_expiration=1):
473 """Check if we can access Perforce - account still logged in."""
474
475 results = p4CmdList(["login", "-s"])
476
477 if len(results) == 0:
478 # should never get here: always get either some results, or a p4ExitCode
479 assert("could not parse response from perforce")
480
481 result = results[0]
482
483 if 'p4ExitCode' in result:
484 # p4 returned non-zero status, e.g. P4PORT invalid, or p4 not in path
485 die_bad_access("could not run p4")
486
487 code = result.get("code")
488 if not code:
489 # we get here if we couldn't connect and there was nothing to unmarshal
490 die_bad_access("could not connect")
491
492 elif code == "stat":
493 expiry = result.get("TicketExpiration")
494 if expiry:
495 expiry = int(expiry)
496 if expiry > min_expiration:
497 # ok to carry on
498 return
499 else:
500 die_bad_access("perforce ticket expires in {0} seconds".format(expiry))
501
502 else:
503 # account without a timeout - all ok
504 return
505
506 elif code == "error":
507 data = result.get("data")
508 if data:
509 die_bad_access("p4 error: {0}".format(data))
510 else:
511 die_bad_access("unknown error")
512 elif code == "info":
513 return
514 else:
515 die_bad_access("unknown error code {0}".format(code))
516
517
518_p4_version_string = None

Callers 2

p4_build_cmdFunction · 0.85
runMethod · 0.85

Calls 2

p4CmdListFunction · 0.85
die_bad_accessFunction · 0.85

Tested by

no test coverage detected