old_p4python.html #1

  • //
  • guest/
  • robert_cowham/
  • perforce/
  • API/
  • python/
  • old_p4python.html
  • View
  • Commits
  • Open Download .zip Download (11 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="#official">New Official P4Python</a><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><b><a name="official"></a><a name="official"></a>New Official P4Python</b></h3>
<p><b>Please note that Perforce have now released 
<a href="http://www.perforce.com/perforce/loadsupp.html#api">P4Python as a 
supported product as of 2007.3</a>. </b></p>
<p><b>This has been done with my agreement and 
support.</b></p>
<p>The new version is
<a href="http://www.perforce.com/perforce/doc.073/manuals/p4script/p4script.pdf">
fully documented</a>.</p>
<p>A summary of differences between the official version 2007.3 and my version 
1.x can be found in the <a href="official/RELNOTES.txt">
release notes</a>.</p>
<p>I have made a minor mod to get the official version to compile with Python 
2.4 (<a href="http://public.perforce.com:8080/@md=d&cd=/&c=645@/6288?ac=10">see 
changelist 6288 in Public Depot</a>). </p>
<p>You can download a pre-built binary:
<a href="local/dist/P4Python-2007.3.win32-py2.4.exe">
P4Python-2007.3.win32-py2.4.exe</a>.</p>
<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">
P4Rubyy</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. The official Python 
distribution is at <a href="http://www.python.org/download/">
http://www.python.org/download/</a> and this has been built on Windows with 2.5.<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. P4Python now built 
with 2007.2 API. Please note the API changed in version 
2005.2 and affects the way various results are returned. To use old style APIs:<blockquote>
	<pre>p4client = p4.P4()
p4client.api(&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>
<p>Edit <em>setup.cfg </em>to point to the directory where p4api files reside.</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), and P4API to be in 
sub-directory as specified in <em>setup.cfg</em><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>
<H4>5. Building RPMs</H4>
<p>If you wish to build RPMs then this is kindly documented by Jason Dillon at:
<a href="http://perforce.planet57.com/wiki/P4PythonRPMS">
http://perforce.planet57.com/wiki/P4PythonRPMS</a> </p>
<P>&nbsp;<A name=downloads></A><H3>Downloads</H3>
<H4>Current Builds</H4>
<TABLE border=1>
  <TBODY>
  <TR>
    <TH>Release Type</TH>
    <TH>Version</TH>
    <TH>Current</TH>
    <TH>Notes</TH>
    </TR>
  <tr>
    <TD>Source Code</TD>
    <TD>1.2</TD>
    <TD><a href="main/p4python.zip">p4python.zip</a> 
    </TD>
    <TD>Unzip, edit<em> setup.cfg</em> if necessary<em> </em>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>P4API Version</TH>
    <TH>Installer - just download and run</TH>
    </TR>
  <tr>
    <TD>1.2</TD>
    <TD>Windows</TD>
    <TD>2.5</TD>
    <TD>2007.3</TD>
    <TD><a href="main/dist/P4Python-1.2.win32-py2.5.exe">P4Python-1.2.win32-py2.5.exe</a> 
    </TD>
    </tr>
	<tr>
    <TD>1.2</TD>
    <TD>Windows</TD>
    <TD>2.4</TD>
    <TD>2007.3</TD>
    <TD><a href="main/dist/P4Python-1.2.win32-py2.4.exe">P4Python-1.2.win32-py2.4.exe</a> 
    </TD>
    </tr>
  <tr>
    <TD>1.1</TD>
    <TD>Windows</TD>
    <TD>2.5</TD>
    <TD>2007.2</TD>
    <TD><a href="main/dist/P4Python-1.1.win32-py2.5.exe">P4Python-1.1.win32-py2.5.exe</a> 
    </TD>
    </tr>
	<tr>
    <TD>1.1</TD>
    <TD>Windows</TD>
    <TD>2.4</TD>
    <TD>2007.2</TD>
    <TD><a href="main/dist/P4Python-1.1.win32-py2.4.exe">P4Python-1.1.win32-py2.4.exe</a> 
    </TD>
    </tr>
  	</TABLE>
<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/robert_cowham/perforce/API/python/old_p4python.html#1 $</font></p>

</BODY></HTML>
# Change User Description Committed
#1 6382 Robert Cowham Split into 2 docs to clarify status.
//guest/robert_cowham/perforce/API/python/index.html
#22 6361 Robert Cowham Link to new executables.
#21 6359 Robert Cowham Added link to official version and deprecation of this one.
Also add binary.
#20 6135 Robert Cowham Check in 1.1 changes
#19 5968 Robert Cowham Latest build with Python 2.5
#18 5967 Robert Cowham - Upgrade to use Perforce API 2007.2 (new structure of api dirs and minor code change)
#17 5966 Robert Cowham - Bug fix in spec handling as suggested by Peter Fornwall
- Also changed API handling suggested by Peter to allow standard argument parsing
- Upgraded version to 1.0
#16 5823 Robert Cowham - Build for Python 2.5 - no code changes.
- Document new switch for setup.
#15 5755 Robert Cowham Added set_protocol() and api() methods.
Updated index.html and new Windows dist.
#14 5727 Robert Cowham - Reworked test harness to use new Perforce sample depot so anyone can run it.
- Fixed problem with binary output (via print) reported by Keith Perry
- Added link to RPM build by Jason Dillon in 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!