API Reference#
Commands#
- pyforce.p4(
- connection: Connection,
- command: list[str],
- stdin: Dict[str, str] | None = None,
- max_severity: MessageSeverity = MessageSeverity.EMPTY,
Run a
p4
command and return its output.This function uses
marshal
(usingp4 -G
) to load stdout and dump stdin.- Parameters:
connection – The connection to execute the command with.
command – A
p4
command to execute, with arguments.stdin – Write a dict to the standard input file using
marshal.dump
.max_severity – Raises an exception if the output error severity is above that threshold.
- Returns:
The command output.
- Raises:
CommandExecutionError – An error occured during command execution.
ConnectionExpiredError – Connection to server expired, password is required. You can use the
login
function.
- pyforce.login(connection: Connection, password: str) None #
Login to Perforce Server.
- Raises:
AuthenticationError – Failed to login.
- pyforce.get_user(
- connection: Connection,
- user: str,
Get user specification.
- Command:
- Parameters:
connection – Perforce connection.
user – Perforce username.
- pyforce.get_client(
- connection: Connection,
- client: str,
Get client workspace specification.
- Command:
- Parameters:
connection – Perforce connection.
client – Perforce client name.
- pyforce.get_change(
- connection: Connection,
- change: int,
Get changelist specification.
- Command:
- Parameters:
connection – Perforce connection.
change – The changelist number.
- Raises:
ChangeUnknownError –
change
not found.
- pyforce.get_revisions(
- connection: Connection,
- filespecs: list[str],
- *,
- long_output: bool = False,
List all revisions of files matching
filespecs
.- Command:
- Parameters:
connection – Perforce Connection.
filespecs – A list of File specifications.
long_output – List long output, with full text of each changelist description.
Warning
The lists are not intentionally sorted despite being naturally sorted by descending revision (highest to lowset) due to how p4 filelog data are processed. This behavior could change in the future, the order is not guaranteed.
- pyforce.create_changelist(
- connection: Connection,
- description: str,
Create and return a new changelist.
- Command:
- Parameters:
connection – Perforce connection.
description – Changelist description.
- pyforce.add(
- connection: Connection,
- filespecs: list[str],
- *,
- changelist: int | None = None,
- preview: bool = False,
Open
filespecs
in client workspace for addition to the depot.- Command:
- Parameters:
connection – Perforce connection.
filespecs – A list of File specifications.
changelist – Open the files within the specified changelist. If not set, the files are linked to the default changelist.
preview – Preview which files would be opened for add, without actually changing any files or metadata.
- Returns:
ActionInfo
andActionMessage
objects.ActionInfo
are only included if something unexpected happened during the operation.
- pyforce.edit(
- connection: Connection,
- filespecs: list[str],
- *,
- changelist: int | None = None,
- preview: bool = False,
Open
filespecs
in client workspace for edit.- Command:
- Parameters:
connection – Perforce connection.
filespecs – A list of File specifications.
changelist – Open the files within the specified changelist. If not set, the files are linked to the default changelist.
preview – Preview the result of the operation, without actually changing any files or metadata.
- Returns:
ActionInfo
andActionMessage
objects.ActionInfo
are only included if something unexpected happened during the operation.
- pyforce.delete(
- connection: Connection,
- filespecs: list[str],
- *,
- changelist: int | None = None,
- preview: bool = False,
Open
filespecs
in client workspace for deletion from the depo.- Command:
- Parameters:
connection – Perforce connection.
filespecs – A list of File specifications.
changelist – Open the files within the specified changelist. If not set, the files are linked to the default changelist.
preview – Preview the result of the operation, without actually changing any files or metadata.
- Returns:
ActionInfo
andActionMessage
objects.ActionInfo
are only included if something unexpected happened during the operation.
- pyforce.sync(
- connection: Connection,
- filespecs: list[str],
Update
filespecs
to the client workspace.- Parameters:
connection – Perforce Connection.
filespecs – A list of File specifications.
- pyforce.fstat(
- connection: Connection,
- filespecs: list[str],
- *,
- include_deleted: bool = False,
List files information.
Local files (not in depot and not opened for
add
) are not included.- Command:
- Parameters:
connection – Perforce connection.
filespecs – A list of File specifications.
include_deleted – Include files with a head action of
delete
ormove/delete
.
User#
- pydantic model pyforce.User#
A Perforce user specification.
- field access: PerforceDateTime (alias 'Access')#
The date and time this user last ran a Helix Server command.
- field auth_method: AuthMethod (alias 'AuthMethod')#
- field update: PerforceDateTime (alias 'Update')#
The date and time this user was last updated.
Client#
- pydantic model pyforce.Client#
A Perforce client workspace specification.
- field access: PerforceDateTime (alias 'Access')#
The date and time that the workspace was last used in any way.
- field options: ClientOptions (alias 'Options')#
- field root: pathlib.Path (alias 'Root')#
Workspace root directory on the local host
All the file in
views
are relative to this directory.
- field submit_options: SubmitOptions (alias 'SubmitOptions')#
- field type: ClientType (alias 'Type')#
- field update: PerforceDateTime (alias 'Update')#
The date the workspace specification was last modified.
- class pyforce.View#
A perforce View specification.
- class pyforce.ClientOptions#
A set of switches that control particular Client options.
- classmethod from_string(string: str) ClientOptions #
Instanciate class from an option line returned by p4.
- enum pyforce.ClientType(value)#
Types of client workspace.
- Member Type:
Valid values are as follows:
- STANDARD = <ClientType.STANDARD: 'writeable'>#
- OPERATOR = <ClientType.OPERATOR: 'readonly'>#
- SERVICE = <ClientType.SERVICE: 'partitioned'>#
- enum pyforce.SubmitOptions(value)#
Options to govern the default behavior of
p4 submit
.- Member Type:
Valid values are as follows:
- SUBMIT_UNCHANGED = <SubmitOptions.SUBMIT_UNCHANGED: 'submitunchanged'>#
- SUBMIT_UNCHANGED_AND_REOPEN = <SubmitOptions.SUBMIT_UNCHANGED_AND_REOPEN: 'submitunchanged+reopen'>#
- REVERT_UNCHANGED = <SubmitOptions.REVERT_UNCHANGED: 'revertunchanged'>#
- REVERT_UNCHANGED_AND_REOPEN = <SubmitOptions.REVERT_UNCHANGED_AND_REOPEN: 'revertunchanged+reopen'>#
- LEAVE_UNCHANGED = <SubmitOptions.LEAVE_UNCHANGED: 'leaveunchanged'>#
- LEAVE_UNCHANGED_AND_REOPEN = <SubmitOptions.LEAVE_UNCHANGED_AND_REOPEN: 'leaveunchanged+reopen'>#
Change#
- pydantic model pyforce.Change#
A Perforce changelist specification.
- Command:
- field date: PerforceDateTime (alias 'Date')#
Date the changelist was last modified.
- field shelve_access: PerforceDateTime | None (alias 'shelveAccess')#
- field shelve_update: PerforceDateTime | None (alias 'shelveUpdate')#
- field status: ChangeStatus (alias 'Status')#
- field type: ChangeType (alias 'Type')#
- pydantic model pyforce.ChangeInfo#
A Perforce changelist.
Compared to a
Change
, this model does not contain the files in the changelist.- Command:
- field date: PerforceTimestamp (alias 'time')#
Date the changelist was last modified.
- field status: ChangeStatus#
- field type: ChangeType (alias 'changeType')#
Action#
- pydantic model pyforce.ActionInfo#
The result of an action operation.
Actions can be, for example,
add
,edit
orremove
.
- enum pyforce.Action(value)#
A file action.
- Member Type:
Valid values are as follows:
- ADD = <Action.ADD: 'add'>#
- EDIT = <Action.EDIT: 'edit'>#
- DELETE = <Action.DELETE: 'delete'>#
- BRANCH = <Action.BRANCH: 'branch'>#
- MOVE_ADD = <Action.MOVE_ADD: 'move/add'>#
- MOVE_DELETE = <Action.MOVE_DELETE: 'move/delete'>#
- INTEGRATE = <Action.INTEGRATE: 'integrate'>#
- IMPORT = <Action.IMPORT: 'import'>#
- PURGE = <Action.PURGE: 'purge'>#
- ARCHIVE = <Action.ARCHIVE: 'archive'>#
- class pyforce.ActionMessage#
Information on a file during an action operation.
Actions can be, for example,
add
,edit
orremove
.- Notable messages:
“can’t add (already opened for edit)”
“can’t add existing file”
“empty, assuming text.”
“also opened by user@client”
- __init__(
- path: str,
- message: str,
- level: MessageLevel,
- classmethod from_info_data( ) ActionMessage #
Create instance from an ‘info’ dict of an action command.
Revision#
- pydantic model pyforce.Revision#
A file revision information.
- field digest: str | None#
MD5 digest of the file.
None
ifaction
isAction.DELETE
.
- field file_size: int | None#
File length in bytes.
None
ifaction
isAction.DELETE
.
- field time: PerforceTimestamp#
Sync#
FStat#
- pydantic model pyforce.FStat#
A file information.
- pydantic model pyforce.HeadInfo#
Head revision information.
- field mod_time: PerforceTimestamp (alias 'headModTime')#
Revision modification time.
The time that the file was last modified on the client before submit.
- field revision: int (alias 'headRev')#
Revision number.
If you used a Revision specifier in your query, this field is set to the specified value. Otherwise, it’s the head revision.
- field time: PerforceTimestamp (alias 'headTime')#
Revision changelist time.
Exceptions#
- exception pyforce.AuthenticationError#
Raised when login to the Helix Core Server failed.
- __init__(*args, **kwargs)#
- exception pyforce.ConnectionExpiredError#
Raised when the connection to the Helix Core Server has expired.
You need to log back in.
- __init__(*args, **kwargs)#
Other#
- class pyforce.Connection#
Perforce connection informations.
- enum pyforce.MessageSeverity(value)#
Perforce message severity levels.
- Member Type:
Valid values are as follows:
- EMPTY = <MessageSeverity.EMPTY: 0>#
- INFO = <MessageSeverity.INFO: 1>#
- WARNING = <MessageSeverity.WARNING: 2>#
- FAILED = <MessageSeverity.FAILED: 3>#
- FATAL = <MessageSeverity.FATAL: 4>#
- enum pyforce.MarshalCode(value)#
Values of the
code
field from a marshaled P4 response.The output dictionary from
p4 -G
must have acode
field.- Member Type:
Valid values are as follows:
- STAT = <MarshalCode.STAT: 'stat'>#
- ERROR = <MarshalCode.ERROR: 'error'>#
- INFO = <MarshalCode.INFO: 'info'>#
- enum pyforce.MessageLevel(value)#
Perforce generic ‘level’ codes, as described in P4.Message.
- Member Type:
Valid values are as follows:
- NONE = <MessageLevel.NONE: 0>#
- USAGE = <MessageLevel.USAGE: 1>#
- UNKNOWN = <MessageLevel.UNKNOWN: 2>#
- CONTEXT = <MessageLevel.CONTEXT: 3>#
- ILLEGAL = <MessageLevel.ILLEGAL: 4>#
- NOTYET = <MessageLevel.NOTYET: 5>#
- PROTECT = <MessageLevel.PROTECT: 6>#
- EMPTY = <MessageLevel.EMPTY: 17>#
- FAULT = <MessageLevel.FAULT: 33>#
- CLIENT = <MessageLevel.CLIENT: 34>#
- ADMIN = <MessageLevel.ADMIN: 35>#
- CONFIG = <MessageLevel.CONFIG: 36>#
- UPGRADE = <MessageLevel.UPGRADE: 37>#
- COMM = <MessageLevel.COMM: 38>#
- TOOBIG = <MessageLevel.TOOBIG: 39>#
- class pyforce.utils.PerforceDateTime#
Alias of
datetime.datetime
- class pyforce.utils.PerforceTimestamp#
Alias of
datetime.datetime