perforce.models

This module implements the main data models used by perforce

copyright:
  1. 2015 by Brett Dixon
license:

MIT, see LICENSE for more details

class perforce.models.Changelist(changelist=None, connection=None)[source]

A Changelist is a collection of files that will be submitted as a single entry with a description and timestamp

append(rev)[source]

Adds a :py:class:Revision to this changelist and adds or checks it out if needed

Parameters:rev (Revision) – Revision to add
static create(description='<Created by Python>', connection=None)[source]

Creates a new changelist

Parameters:
  • connection (Connection) – Connection to use to create the changelist
  • description (str) – Description for new changelist
Returns:

Changelist

delete()[source]

Reverts all files in this changelist then deletes the changelist from perforce

query(files=True)[source]

Queries the depot to get the current status of the changelist

remove(rev, permanent=False)[source]

Removes a revision from this changelist

Parameters:
  • rev (Revision) – Revision to remove
  • permanent (bool) – Whether or not we need to set the changelist to default
revert(unchanged_only=False)[source]

Revert all files in this changelist

Parameters:unchanged_only (bool) – Only revert unchanged files
Raises:ChangelistError
save()[source]

Saves the state of the changelist

submit()[source]

Submits a chagelist to the depot

client

Perforce client this changelist is under

description

Changelist description

isDirty

Does this changelist have unsaved changes

time

Creation time of this changelist

class perforce.models.Client(client, connection=None)[source]

Represents a client(workspace) for a given connection

access

The date and time last accessed

root

Root path fo the client

stream

Which stream, if any, the client is under

update

The date and time the client was updated

view

A list of view specs

class perforce.models.Connection(port=None, client=None, user=None, executable='p4', level=3)[source]

This is the connection to perforce and does all of the communication with the perforce server

add(filename, change=None)[source]

Adds a new file to a changelist

Parameters:
  • filename (str) – File path to add
  • change (int) – Changelist to add the file to
Returns:

Revision

canAdd(filename)[source]

Determines if a filename can be added to the depot under the current client

Parameters:filename (str) – File path to add
findChangelist(description=None)[source]

Gets or creates a Changelist object with a description

Parameters:description (str) – The description to set or lookup
Returns:Changelist
ls(files, silent=True, exclude_deleted=False)[source]

List files

Parameters:
  • files (list) – Perforce file spec
  • silent (bool) – Will not raise error for invalid files or files not under the client
  • exclude_deleted (bool) – Exclude deleted files from the query
Raises:

errors.RevisionError

Returns:

list<Revision>

run(cmd, stdin=None, marshal_output=True, **kwargs)[source]

Runs a p4 command and returns a list of dictionary objects

Parameters:
  • cmd (list) – Command to run
  • stdin (str) – Standard Input to send to the process
  • marshal_output (bool) – Whether or not to marshal the output from the command
  • kwargs – Passes any other keyword arguments to subprocess
Raises:

error.CommandError

Returns:

list, records of results

client

The client used in perforce queries

level

The current exception level

status

The status of the connection to perforce

user

The user used in perforce queries

class perforce.models.FileSpec(depot, client)

File spec http://www.perforce.com/perforce/doc.current/manuals/cmdref/filespecs.html

client

Alias for field number 1

depot

Alias for field number 0

class perforce.models.FormObject(connection)[source]

Abstract class for objects with a form api (client, stream, changelist)

save()[source]

Saves the state of the changelist

class perforce.models.HeadRevision(filedict)[source]

The HeadRevision represents the latest version on the Perforce server

class perforce.models.PerforceObject(connection=None)[source]

Abstract class for dealing with the dictionaries coming back from p4 commands

This is a simple descriptor for the incoming P4Dict

class perforce.models.Revision(data, connection=None)[source]

A Revision represents a file on perforce at a given point in it’s history

delete(changelist=0)[source]

Marks the file for delete

Parameters:changelist (Changelist) – Changelist to add the move to
edit(changelist=0)[source]

Checks out the file

Parameters:changelist (Changelist) – Optional changelist to checkout the file into
lock(lock=True, changelist=0)[source]

Locks or unlocks the file

Parameters:
  • lock (bool) – Lock or unlock the file
  • changelist (Changelist) – Optional changelist to checkout the file into
move(dest, changelist=0, force=False)[source]

Renames/moves the file to dest

Parameters:
  • dest (str) – Destination to move the file to
  • changelist (Changelist) – Changelist to add the move to
  • force (bool) – Force the move to an existing file
query()[source]

Runs an fstat for this file and repopulates the data

revert(unchanged=False)[source]

Reverts any file changes

Parameters:unchanged (bool) – Only revert if the file is unchanged
shelve(changelist=None)[source]

Shelves the file if it is in a changelist

Parameters:changelist (Changelist) – Changelist to add the move to
sync(force=False, safe=True, revision=0, changelist=0)[source]

Syncs the file at the current revision

Parameters:
  • force (bool) – Force the file to sync
  • safe (bool) – Don’t sync files that were changed outside perforce
  • revision (int) – Sync to a specific revision
  • changelist (int) – Changelist to sync to
action

The current action: add, edit, etc.

changelist

Which Changelist is this revision in

clientFile

The local path to the revision

depotFile

The depot path to the revision

hash

The hash value of the current revision

head

The HeadRevision of this file

isEdit

Is the file open for edit

isLocked

Is the file locked by anyone excluding the current user

isMapped

Is the file mapped to the current workspace

isResolved

Is the revision resolved

isShelved

Is the file shelved

isSynced

Is the local file the latest revision

lockedBy

Who has this file locked

openedBy

Who has this file open for edit

resolved

The number, if any, of resolved integration records

revision

Revision number

type

Best guess at file type. text or binary

unresolved

The number, if any, of unresolved integration records

class perforce.models.Stream(stream, connection=None)[source]

An object representing a perforce stream

access

The date and time last accessed

description

Stream description tha thas been trimmed

update

The date and time the client was updated

view

A list of view specs

perforce.models.camel_case(string)[source]

Makes a string camelCase

Parameters:string – String to convert
perforce.models.split_ls(func)[source]

Decorator to split files into manageable chunks as not to exceed the windows cmd limit

Parameters:func (:py:class:Function) – Function to call for each chunk
perforce.models.ConnectionStatus = ConnectionStatus(OK=0, OFFLINE=1, NO_AUTH=2, INVALID_CLIENT=3)

Connections status enum

perforce.models.ErrorLevel = ErrorLevel(EMPTY=0, INFO=1, WARN=2, FAILED=3, FATAL=4)

Error levels enum