index.html #1

  • //
  • guest/
  • shawn_hladky/
  • P4Python/
  • index.html
  • View
  • Commits
  • Open Download .zip Download (10 KB)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0072)http://public.perforce.com/guest/tony_smith/perforce/API/Ruby/index.html -->
<HTML><HEAD><TITLE>P4Python - Perforce Public Depot</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso8859-1"><LINK 
href="index_files/rubystyle.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.2523" name=GENERATOR></HEAD>
<BODY>
<TABLE width="100%" border=0>
  <TBODY>
  <TR>
    <TD>&nbsp;</TD>
    <TD>
      <H2>P4Python: Python interface to the Perforce API</H2></TD></TR></TBODY></TABLE>
<H3>Contents</H3>
<OL>
  <LI><A href="#intro">Introduction</A> 

  <LI><A 
  href="#license">License</A> 

  <LI><A 
  href="#support">Support</A> 

  <LI><A 
  href="#doc">Documentation</A> 

  <LI><A 
  href="#build">
	Building P4Python</A> 
  <LI><A 
  href="#downloads">Downloads</A> 

  <LI><A 
  href="#sample">Sample 
  Code</A> 
  <LI><A 
  href="#lib">
	P4Python 
  Script Library</A> 
  <LI><A 
  href="#porting">Porting</A> 

  <LI><A 
  href="#credits">Credits</A> 
  </LI>
	<LI><a href="#changelog">Changelog</a></LI></OL><A name=intro></A>
<H3>Introduction</H3>
<P>So, what's it all about? The observant amongst you may notice a distinct 
resemblance to
<a href="http://public.perforce.com/guest/tony_smith/perforce/API/Ruby/index.html">
P4Ruby</a> - which is intentional (thanks Tony)! P4Python allows you to write 
Python code that interacts nicely and intuitively with a Perforce server. The main features 
are: 
<UL>
  <LI>Get Perforce data and forms in dictionaries and lists 
  <LI>Edit Perforce forms by modifying dictionaries 
  <LI>Exception based error handling 
  <LI>Optionally ignore warnings (like "File(s) up-to-date." on a sync) 
  <LI>Run as many commands on a connection as you want to (dramatically 
	improving performance over the spawning of command lines and parsing of 
	results)</LI></UL>
<h3><A name=license></A>Licence</h3>
<P>This extension is distributed under the terms of <a href="main/LICENSE.txt">this</a> 
license. You use it at your own risk. <A 
name=support></A>
<H3>Support</H3>P4Python is supported by me personally. I aim to be helpful, but 
paying work tends to take priority! You can contact me directly at: 
robert at vaccaperna dot co dot uk.&nbsp; 
<A name=doc></A>
<H3>Documentation</H3>
If you're new to Python, then start with <a href="http://www.python.org">
www.python.org</a>&nbsp; <A name=build></A>
<p>There is also documentation for <a href="main/P4.html">P4Python</a>. </p>
<H3>Building P4Python</H3>
<H4>1. Download and install Python</H4>Linux users can probably skip this step as 
most Linux distributions these days come with Python installed (or on the CD's) 
<P>Windows users can download a Windows installer for Python from 
<a href="http://www.activestate.com/Products/ActivePython/">ActiveState</a>. 
This is currently known to work with 2.3 and 2.4.<P>Otherwise you can download the source for Python from 
<a href="http://www.python.org">www.python.org</a> which is the main 
Python home page. 
<H4>2. Download P4Python</H4>Choose the build of P4Python you want to run. For 
now there is just a current release (in the future there may be &quot;stable&quot; 
releases).<p>Pick the appropriate file from the <A 
href="#downloads">downloads</A> 
section.</p>
<P><B>If you chose to use the Windows installer then the process ends with 
running the executable. 
You're then ready to start using P4Python. </B>What follows is only applicable to those 
building P4Python from source. 
<H4>3. Get the Perforce API</H4>This step is only required if you're building 
P4Python from source. 
<P>See the <A 
href="#porting">Porting</A> 
section below to help you find the right Perforce API build for your platform 
(see note re gcc 3).<P>Then go to the <A href="http://www.perforce.com/downloads/perforce/">Perforce 
download</A> site and grab the p4api.tar file for your platform. Try to get the 
latest available release, but certainly no older than 2001.1. 
Please note the API changed in version 2005.2 - for now just tell the API to be 
2005.1 compatible (will be updated shortly):<blockquote>
	<pre>p4client = p4.P4()
p4client.p4c.SetProtocol(&quot;api&quot;, &quot;57&quot;)</pre>
</blockquote>
<p>Extract the files in the p4api.tar tarfile (WinZip can handle it for Windows 
users) into a sub directory called p4api of where the source files are (or edit 
setup.py below).</p>
<H4>4. Build and install P4Python</H4>
<P>P4Python uses Distutils (Python 2.2 and later).<Pre>  python setup.py install</pre>

should do the trick (requires C++ compiler to be installed).<p>Note that there is 
a supplied test harness (though it requires a working Perforce server with a 
copy of the training repository to run since it relies on certain history). It 
is valid example for how to use functions.</p>
<P>&nbsp;<A name=downloads></A><H3>Downloads</H3>
<H4>Current Builds</H4>
<TABLE border=1>
  <TBODY>
  <TR>
    <TH>Release Type</TH>
    <TH>Current</TH>
    <TH>Notes</TH>
    </TR>
  <TR>
    <TD>Source Code</TD>
    <TD><a href="main/p4python.zip">p4python.zip</a> 
    </TD>
    <TD>Unzip and run &quot;python setup.py install&quot; to build and install</TD>
    </TR>
  </TBODY></TABLE>
<p>Windows Installers</p>
<TABLE border=1 id="table2">
  <TR>
    <TH>Release </TH>
    <TH>Platform</TH>
    <TH>Python Version</TH>
    <TH>Installer - just download and run</TH>
    </TR>
  <tr>
    <TD>0.6</TD>
    <TD>Windows</TD>
    <TD>2.3</TD>
    <TD><a href="main/dist/P4Python-0.6.win32-py2.3.exe">
	P4Python-0.6.win32-py2.3.exe</a> 
    </TD>
    </tr>
	<tr>
    <TD>0.6</TD>
    <TD>Windows</TD>
    <TD>2.4</TD>
    <TD><a href="main/dist/P4Python-0.6.win32-py2.4.exe">P4Python-0.6.win32-py2.4.exe</a></TD>
    </tr>
	<tr>
    <TD>0.6</TD>
    <TD>Linux</TD>
    <TD>2.4</TD>
    <TD><a href="main/dist/P4Python-0.6.linux-i386.tar.gz">P4Python-0.6.linux-i386.tar.gz</a></TD>
    </tr>
</TABLE>
<H4>Older Releases</H4>
<p>Windows Installers</p>
<TABLE border=1 id="table4">
  <TR>
    <TH>Release</TH>
    <TH>Platform</TH>
    <TH>Python Version</TH>
    <TH>Installer - just download and run</TH>
    </TR>
  <tr>
    <TD>0.5</TD>
    <TD>Windows</TD>
    <TD>2.3</TD>
    <TD><a href="main/dist/P4Python-0.5.win32-py2.3.exe">
	P4Python-0.5.win32-py2.3.exe</a> 
    </TD>
    </tr>
	<tr>
    <TD>0.5</TD>
    <TD>Windows</TD>
    <TD>2.4</TD>
    <TD><a href="main/dist/P4Python-0.5.win32-py2.4.exe">
	P4Python-0.5.win32-py2.4.exe</a></TD>
    </tr>
	</TABLE>
<P>Other platforms (binaries kindly sent in):<br>
&nbsp;<TABLE border=1 id="table3">
  <TBODY>
  <TR>
    <TH>Release</TH>
    <TH>Platform</TH>
    <TH>Python Version</TH>
    <TH>Built Binary (unpack and copy to appropriate place)</TH>
    <TH>Thanks To</TH>
    </TR>
  <TR>
    <TD>0.5</TD>
    <TD>Cygwin</TD>
    <TD>2.4</TD>
    <TD><a href="main/dist/P4Python-0.5.cygwin-1.5.12-i686.tar.gz">
	P4Python-0.5.cygwin-1.5.12-i686.tar.gz</a> 
    </TD>
    <TD>Adam Heinz</TD>
    </TR>
  <TR>
    <TD>0.5</TD>
    <TD>Linux</TD>
    <TD>2.4</TD>
    <TD><a href="main/dist/P4Python-0.5.linux-i686.tar.gz">
	P4Python-0.5.linux-i686.tar.gz</a></TD>
    <TD>Tony Smith</TD>
    </TR>
  </TBODY></TABLE>
<p>To install from *.tar.gz, unzip the 2 files (p4.py and P4Client.so). Find out where your Python 
libraries are located (by running &quot;python -v&quot; usually, or the 
following command: </p>
<blockquote>
	<p>python -c &quot;import sys, string; print string.join(sys.path, '\n')&quot;</p>
</blockquote>
<p>and copy the 2 files 
into:</p>
<blockquote>
	<p>&lt;python root&gt;/lib/site-packages</p>
</blockquote>
<P>To find out what's changed, read the <a href="main/CHANGELOG.txt">change 
log</a>. <A name=sample></A>
<H3>Sample code</H3>
<p>Please note that all functions are documented in the
<a href="main/test/test_p4python.py">test harness</a>. See comments for details.</p>Just a small example to whet your appetite. This small 
sample shows how to create a new client workspace based on an existing template. 
You can of course construct the view manually but most people who are scripting 
client creation will use a template so that seemed like a good example. <PRE>  import p4

  template = "my-client-template"
  client_root = r"c:\work\my-root"

  p4c = p4.P4()
  p4c.parse_forms()	# Important for easy processing of forms like client specs!
  p4c.connect()

  try:
      # Run a "p4 client -t template -o" and convert it into a Python dictionary
      client = p4c.fetch_client("-t", template)

      # Now edit the fields in the form
      client["Root"] = client_root

      # Now save the udpated spec and sync it
      p4c.save_client(client)
      p4c.run_sync()

  except:
    # If any errors occur, we'll jump in here. Just log them
    # and raise the exception up to the higher level
    for e in p4c.errors:
        print e
        raise e</PRE><A name=porting></A>
<H3>Porting</H3>P4Python is as portable as Python and Perforce so porting it is 
relatively easy. Most of the porting problems revolve around people not knowing 
which build of the Perforce API to use. The key is to match up the compiler used 
to build Python with the compiler used to build Perforce and use that compiler to 
build P4Python. 
<P>P4Python has been built on at least the following platforms: </P>
<UL>
  <LI>Linux (gcc 2.9x) - use p4api.tar from <B>bin.linux24x86</B> 
  <LI>Linux (gcc 3) - use p4api.tar from
	<a href="ftp://ftp.perforce.com/perforce/r05.1/bin.linux3x86/">
	ftp://ftp.perforce.com/perforce/r05.1/bin.linux3x86/</a> (or equivalent 
	folder in a later release)<LI>Windows (Visual C++ version 6 and .NET should 
	be fine) </LI></UL>
<P>Note that P4Python is compatible with older versions of Python and the Perforce 
API, so on older platforms you should still be able to get a working build. 
However, Python did not include DistUtils package prior to 2.2 so you may need 
to download that package to build if you have an old version of Python.<P>
<P><B>If you get "unresolved symbol" errors when building or running P4Python, you 
probably used the wrong compiler or the wrong Perforce API build. Pay particular 
attention to the GCC version used to build the API and the one installed on your 
system.</B></P><A 
name=credits></A>
<H3>Credits</H3>Thanks to Mike Meyer for the original code.<p>Thanks to Tony 
Smith for producing P4Ruby after which this is modelled.</p>

<h3><a name="changelog">Changelog</a></h3>
<p>See <a href="main/CHANGELOG.txt">CHANGELOG.txt</a></p>
<p><font size="2">File: $Id: //guest/shawn_hladky/P4Python/index.html#1 $</font></p>

</BODY></HTML>
# Change User Description Committed
#1 5578 Shawn Hladky branching P4Python
//guest/robert_cowham/perforce/API/python/index.html
#13 5374 Robert Cowham Note re 2005.2 API
#12 5200 Robert Cowham Had mistakenly lost various pointers to releases.
#11 5165 Robert Cowham Point out where to get gcc 3 p4api.
#10 5101 Robert Cowham Updated docs and added new Linux binary.
#9 5060 Robert Cowham Tidied TOC
#8 5058 Robert Cowham Updated docs.
#7 4964 Robert Cowham Saved first version of docs.
#6 4911 Robert Cowham Fixed title
#5 4909 Robert Cowham Added new installer
#4 4858 Robert Cowham Added new binaries.
#3 4770 Robert Cowham Changed example to show better usage.
Raise AttributeError if appropriate.
#2 4768 Robert Cowham Fix references for TOC etc.
#1 4767 Robert Cowham Forgot the most important thing!