P4Python Classes
The P4
module consists of several public classes:
- P4
- P4.P4Exception
- P4.DepotFile
- P4.Revision
- P4.Integration
- P4.Map
- P4.MergeData
- P4.Message
- P4.OutputHandler
- P4.Progress
- P4.PyKeepAlive
- P4.Resolver
- P4.Spec
The following tables provide more details about each public class, including methods and attributes. Attributes are readable and writable unless indicated otherwise. They can be strings, objects, or integers.
You can set attributes in the P4() constructor or by using their setters and getters. For example:
import P4
p4 = P4.P4(client="myclient", port="1666")
p4.user = 'me'
P4
Helix Core Server client class. Handles connection and interaction with the Helix Core Server. There is one instance of each connection.
The following table lists attributes of the class P4
in
P4Python.
Attribute | Description |
---|---|
API compatibility level. (Lock server output to a specified server level.) |
|
Charset for Unicode servers. |
|
|
|
Current working directory. |
|
Disable cleanup of temporary objects. |
|
Encoding to use when receiving strings from a non-Unicode
server. If unset, use UTF8. Can be set to a legal Python
encoding, or to |
|
An array containing the error messages received during execution of the last command. |
|
The exception level of the
The default value is 2. |
|
An output handler. |
|
|
|
The path of the ignore file, |
|
Input for the next command. Can be a string, a list or a dictionary. |
|
MaxLockTime used for all following commands |
|
MaxResults used for all following commands. This command must be set before the connection is made. If the command is set after the connection is made, the command is ignored. |
|
MaxScanRows used for all following commands. |
|
An array of |
|
The location of the configuration file used
( |
|
|
|
|
|
The name of the script. |
|
A progress indicator. |
|
Detect whether or not the server is case sensitive. |
|
Returns the current Helix Core Server level. |
|
Detect whether or not the server is in Unicode mode. |
|
To disable streams support, set the value to |
|
To disable tagged output for the following commands, set the value to 0 or False. By default, tagged output is enabled. |
|
To enable performance tracking for the current connection, set the value to 1 or True. By default, server tracking is disabled. |
|
If performance tracking is enabled, returns an array containing performance tracking information received during execution of the last command. |
|
|
|
|
|
The version of the script. |
|
An array containing the warning messages received during execution of the last command. |
The following table lists all public methods of the class
P4
. Many methods are wrappers around
P4.run()
, which sends a command to Helix Core Server. Such methods are provided for your convenience.
Method | Description |
---|---|
In the context of a |
|
Clones from another
Perforce
service into a local
Perforce
service, and returns a new |
|
Connects to the Helix Core Server. |
|
Returns |
|
Deletes the spec <spectype>. Equivalent to:
P4.run( "<spectype>", "-d" )
|
|
Disconnects from the Helix Core Server. |
|
Get the value of a
Helix Core Server
environment variable, taking into account |
|
Fetches the spec <spectype>. Equivalent to:
p4.run( "<spectype>", "-o" ).pop( 0 )
|
|
Converts the spec <spectype> into a string. |
|
Returns a string identifying the P4Python module. |
|
Initializes a new personal (local) Helix Core Server, and returns a new |
|
Determines whether a particular file is ignored via the
|
|
Iterate through specs of form <spectype>. |
|
Returns a new |
|
Parses a string representation of the spec <spectype> and returns a dictionary. |
|
Runs a command on the server. Needs to be connected, or an exception is raised. |
|
Runs the command cmd. Equivalent to:
P4.run( "command" )
|
|
This command returns a list of |
|
Logs in using the specified password or ticket. |
|
Convenience method: updates the password. Takes two arguments: oldpassword, newpassword |
|
Interface to |
|
Convenience method for submitting changelists. When invoked with a change spec, it submits the spec. Equivalent to:
p4.input = myspecp4.run( "submit", "-i" )
|
|
Interface to |
|
Saves the spec <spectype>. Equivalent to:
P4.run( "<spectype>", "-i" )
|
|
On Windows or macOS, set a variable in the registry or user preferences. |
|
Creates a temporary client. |
|
In the context of a |
P4.P4Exception
Exception class. Instances of this class are raised when errors and/or
(depending on the exception_level
setting) warnings are
returned by the server. The exception contains the errors in the form of
a string. P4Exception
is a subclass of the standard
Python Exception
class.
P4.DepotFile
Container class returned by P4.run_filelog()
. Contains the
name of the depot file and a list of P4.Revision
objects.
Attribute | Description |
---|---|
Name of the depot file. |
|
List of |
P4.Revision
Container class containing one revision of a
P4.DepotFile
object.
Attribute | Description |
---|---|
Action that created the revision. |
|
Changelist number |
|
Client workspace used to create this revision. |
|
Short change list description. |
|
The name of the file in the depot. |
|
MD5 digest of the revision. |
|
File size of this revision. |
|
List of |
|
Revision. |
|
Timestamp (as |
|
File type. |
|
User that created this revision. |
P4.Integration
Container class containing one integration for a
P4.Revision
object.
Attribute | Description |
---|---|
Integration method (merge/branch/copy/ignored). |
|
Integrated file. |
|
Start revision. |
|
End revision. |
P4.Map
A class that allows users to create and work with Helix Core Server mappings without requiring a connection to the Helix Core Server.
Method | Description |
---|---|
Construct a new Map object (class method). |
|
Joins two maps to create a third (class method). |
|
Empties a map. |
|
Returns the number of entries in a map. |
|
Tests whether or not a map object is empty. |
|
Inserts an entry into the map. |
|
Translate a string through a map. |
|
Tests whether a path is mapped. |
|
Returns a new mapping with the left and right sides reversed. |
|
Returns the left side as an array. |
|
Returns the right side as an array. |
|
Returns the map as an array |
P4.MergeData
Class encapsulating the context of an individual merge during execution
of a p4 resolve
command. Passed to
P4.run_resolve()
.
Attribute | Description |
---|---|
Returns the name of "your" file in the merge. (file in workspace) |
|
Returns the name of "their" file in the merge. (file in the depot) |
|
Returns the name of "base" file in the merge. (file in the depot) |
|
Returns the path of "your" file in the merge. (file in workspace) |
|
Returns the path of "their" file in the merge. (temporary file
on workstation into which |
|
Returns the path of the base file in the merge. (temporary file
on workstation into which |
|
Returns the path to the merge result. (temporary file on workstation into which the automatic merge performed by the server has been loaded) |
|
Returns hint from server as to how user might best resolve merge. |
The P4.MergeData
class also has one method:
If the environment variable |
P4.Message
Class for handling error messages in Helix Core Server.
Method | Description |
---|---|
Returns the severity of the message. |
|
Returns the generic class of the error. |
|
Returns the unique ID of the error message. |
P4.OutputHandler
Handler class that provides access to streaming output from the server;
set P4.handler
to an instance of a subclass of
P4.OutputHandler
to enable callbacks:
Method | Description |
---|---|
Process binary data. |
|
Process tabular data. |
|
Process information or errors. |
|
Process tagged output. |
|
Process text data. |
P4.Progress
Handler class that provides access to progress indicators from the
server; set P4.progress
to an instance of a subclass
of P4.Progress
to enable callbacks:
Method | Description |
---|---|
Initialize progress indicator as designated type. |
|
Total number of units (if known). |
|
Description and type of units to be used for progress reporting. |
|
If non-zero, user has requested a cancellation of the operation. |
|
If non-zero, operation has failed. |
P4.PyKeepAlive
The only method of the PyKeepAlive class, isAlive(), is used in applications to request the current command to be terminated by disconnecting.
Method | Description |
---|---|
Requests the current command to be terminated by disconnecting. By default, it returns 1. |
P4.Resolver
Class for handling resolves in Helix Core Server.
Method | Description |
---|---|
Perform a resolve and return the resolve decision as a string. |
P4.Spec
Class allowing access to the fields in a Helix Core Server specification form.
Attribute | Description |
---|---|
Value associated with the field named fieldname. |
|
Array containing comments in a spec object. |
|
Array containing the names of the fields that are valid for this spec object. |