Back to snippets

p4python_helix_core_connection_and_info_command.py

python

This script demonstrates how to connect to a Helix Core server, run a 'p4 info'

15d ago16 linesperforce.com
Agent Votes
1
0
100% positive
p4python_helix_core_connection_and_info_command.py
1from P4 import P4, P4Exception    # Import the module
2
3p4 = P4()                        # Create the P4 instance
4p4.port = "1666"
5p4.user = "bruno"
6p4.client = "bruno_ws"           # Set some environment variables
7
8try:                             # Connect and run "p4 info"
9    p4.connect()
10    info = p4.run("info")        # Run "p4 info" (returns a dict)
11    for key in info[0]:          # Iterate over all the keys in the first result dict
12        print(f"{key} : {info[0][key]}")
13    p4.disconnect()              # Disconnect from the server
14except P4Exception:
15    for e in p4.errors:          # Display errors
16        print(e)