<!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> </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></OL><A name=intro></A> <H3>Introduction</H3> <P>So, what's it all about? The observant amongst 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>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. You can contact me directly at: robert at vaccaperna dot co dot uk. <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> <A name=build></A> <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.<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 "stable" 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 exectuable. 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. <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. <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).<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++ compile 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> <A name=downloads></A><H3>Downloads</H3> <H4>Current Builds</H4> <TABLE border=1> <TBODY> <TR> <TH>Release Type</TH> <TH>Source Code</TH> <TH>Installer (Python 2.3)</TH> </TR> <TR> <TD>Current</TD> <TD><a href="main/p4python.zip">p4python.zip</a> </TD> <TD><a href="main/dist/P4Python-0.5.win32-py2.3.exe"> P4Python-0.5.win32-py2.3.exe</a> </TD> </TR> </TBODY></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> from p4 import P4 template = "my-client-template" client_root = r"c:\work\my-root" p4 = P4() p4.parse_forms() p4.connect() try: # Run a "p4 client -t template -o" and convert it into a Python dictionary spec = p4.fetch_client("-t", template) # Now edit the fields in the form spec["Root"] = client_root # Now save the udpated spec and sync it p4.save_client(spec) p4.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 p4.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>Windows (Visual C++) </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. <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. </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> </BODY></HTML>
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#28 | 8056 | Robert Cowham | Updated doc linka | ||
#27 | 8055 | Robert Cowham | Better link | ||
#26 | 8054 | Robert Cowham | Tweak references | ||
#25 | 7544 | Robert Cowham | Update links | ||
#24 | 6517 | Robert Cowham | Clarified and updated links | ||
#23 | 6382 | Robert Cowham | Split into 2 docs to clarify status. | ||
#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! |