Package perforce :: Package async :: Module connection :: Class Connection
[frames] | no frames]

Class Connection



object --+
         |
        Connection

A Perforce connection that allows asynchronous running of commands.

Use instances of this class to run commands on the Perforce server asynchronously, returning twisted Deferred objects.

Only one command executes using this connection at any one time, however, many connections may be simultaneously executing on separate threads in the Twisted thread pool.


See Also: connectPerforce

Instance Methods
 
__init__(self, client)
Construct a Connection object from an already connected ClientApi.
 
__del__(self)
 
disconnect(self)
Disconnect from the server once all pending commands have finished.
 
run(self, command, *args, **kwargs)
Run a Perforce command asynchronously.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties
str server
The Perforce server protocol version used by the connection.
boolean nocase
Flag indicating whether the server is case insensitive.
str (may be set with unicode) charset
The default charset used for Perforce unicode files.
str or unicode client
The default Perforce client to use when running client commands.
str or unicode cwd
The default working directory for running client commands.
str (may be set with unicode) host
The hostname of the local machine as identified by Perforce.
str or unicode language
The language to use for Perforce messages.
str os
The operating system as identified by Perforce.
str or unicode password
The default password to use to authenticate the Perforce user.
str (may be set with unicode) port
The address and port of the connected Perforce server.
str or unicode user
The default Perforce user name to use for running commands.

Inherited from object: __class__

Method Details

__init__(self, client)
(Constructor)

 
Construct a Connection object from an already connected ClientApi.
Parameters:
Overrides: object.__init__

Note: Instances of this class should be created by calling the connectPerforce function.

See Also: connectPerforce

disconnect(self)

 
Disconnect from the server once all pending commands have finished.

Note: Subsequent calls to run will fail with ConnectionDropped.

run(self, command, *args, **kwargs)

 

Run a Perforce command asynchronously.

Connection parameters may be overridden on a per-command basis by specifying them as named parameters: ie. charset, client, cwd, language, user and password.
Parameters:
  • command (str or unicode) - The Perforce command to execute.
  • args (tuple of str or unicode) - Arguments to provide to the Perforce command.
  • kwargs - Additional parameters to provide to the command.
  • input (convertible to str, unicode or list of same) - Input to provide to the command (such as form contents or passwords). Multiple inputs may be specified by passing a list of values (useful for handling 'p4 passwd' prompts).
  • output (adaptable to perforce.results.IOutputConsumer) - An object that will receive the output of the command. If not provided then a perforce.results.Results object will be used. Callbacks will be made on this object in the main thread.
  • charset (perforce.api.CharSet, str, unicode or None) - Optional override value for the charset environment variable for this command only.
  • client (str or unicode) - Optional override value for the client environment variable for this command only.
  • cwd (str or unicode) - Optional override value for the cwd environment variable for this command only.
  • user (str or unicode) - Optional override value for the user environment variable for this command only.
  • password (str or unicode) - Optional override value for th password environment variable for this command only.
Returns:
A deferred that fires with the output object when the command finishes executing.

Warning: This method should only ever be called from the Twisted main thread.


Property Details

server

The Perforce server protocol version used by the connection.
Get Method:
unreachable.fget(self)
Type:
str

Note: Can only be queried after running a command on this connection.

See Also: perforce.connection.Connection.server for a list of the values and their corresponding Perforce server versions.

nocase

Flag indicating whether the server is case insensitive.
Get Method:
unreachable.fget(self)
Type:
boolean

Note: Can only be queried after running a command on this connection.

See Also: server

charset

The default charset used for Perforce unicode files.

This value may be overridden on a per-command basis by passing a value to the named 'charset' argument of run().

For example:
 | c.run('sync', charset='utf8')
Get Method:
unreachable.fget(self)
Type:
str (may be set with unicode)

client

The default Perforce client to use when running client commands.

This value may be overridden on a per-command basis by passing the new client value to the named 'client' argument of run().

For example:
 | c.run('sync', client='my-client')
Get Method:
unreachable.fget(self)
Type:
str or unicode

cwd

The default working directory for running client commands.

This value may be overridden on a per-command basis by passing the new working directory to the the named 'cwd' argument of run().

For example:
 | c.run('sync', 'foo.h',
 |       cwd='/path/to/include')
Get Method:
unreachable.fget(self)
Type:
str or unicode

host

The hostname of the local machine as identified by Perforce.
Get Method:
unreachable.fget(self)
Type:
str (may be set with unicode)

language

The language to use for Perforce messages.
Get Method:
unreachable.fget(self)
Type:
str or unicode

os

The operating system as identified by Perforce.
Get Method:
unreachable.fget(self)
Type:
str

password

The default password to use to authenticate the Perforce user.

This value may be overridden on a per-command basis by passing the new password to the named 'password' parameter of run(). The ticket identifier (obtained from 'p4 login') may also be passed as the password for servers that require ticket-based authentication.

For example:
 | c.run('user', '-d', 'joe',
 |        user='p4admin',
 |        password='thePassword')
Get Method:
unreachable.fget(self)
Type:
str or unicode

port

The address and port of the connected Perforce server.
Get Method:
unreachable.fget(self)
Type:
str (may be set with unicode)

user

The default Perforce user name to use for running commands.

This value may be overridden on a per-command basis by passing the new user name to the named 'user' argument of run().

For example:
 | c.run('login', user='joe',
 |       input='thePassword')
Get Method:
unreachable.fget(self)
Type:
str or unicode