February 26, 2005

Apple == Python, Perforce, XCode - Pure Nirvana

Ok I figured out how to get XCode to build a decent coding environment for python. This includes getting the SCM (Perforce) integrated and building a (quasi) debugging environment using pdb.py. If this interests you then follow along.

In this piece I will detail how to get perforce and XCode to play nicely.

Step 1 - Getting a SCM setup that works for you.

Ok I figured out how to get perforce to work on my linux box. And now I have a place to play. How do I want the directory structure to fit is a common question. So let me outline how I think I want my development environment setup. I've bee a long time hacker, and this is the first time I want to enable perforce SCM for all of my development (perhaps others) activities. So how do I want this setup? When I am finished I want a directory structure that looks like this:
<some base directory>

scripts

perl
python
.
.

projects

proj1 (Some XCode or other project)
proj2
.
.
projN

So this seems simple enough - and it is. After a bit of trial and error playing with P4CLIENTS I have this setup. So let's assume you have a server (called server).

Ensure you have an empty base directory. For this example I created a directory on my client ( mkdir ~/depot ). Next create a client workspace. I used p4v to do this and simply did the following:

  • Open Connection (File->Open Connection)
  • Connect To: < your server and port >
  • Connect As: < your username > ( if this is the first time you must select New.. )
  • Client Workspace:
  • I named one steven and selected New..
  • Under the name I called it steven
  • Owner: Steven
  • Host: <default>
  • Description: Steven depot
  • Root: <base directory>

Now you should have a empty directory tree. Let's add our appropriate directories.

mkdir ~/depot/scripts/python
mkdir ~/depot/projects

Ok now let's put a file in the python directory and use p4v to check the thing in.

cp <my python script> ~/depot/scripts/python

Ok switch over to the p4v and refresh the Client Workspace. Seeing your new file right click and "open for add", then right click "submit"

Cool it should work. Now let's get xcode to play nicely..

Step 2 - Create a XCode project for python

This is very basic - fire up XCode ( get it from here ) and create a new empty project.

  • The type is an Empty Project
  • Give is a <project name>
  • The directory needs to be <base directory>/projects/<project name> ( ~/depot/projects/PythonTest1 )

And that's it. Now let's add SCM - version control..

Step 3 - Getting Perforce to play nicely.

One of the things I despise is when documentation points you to a particular place and no amount of searching seems to dig up the answer. So you dig and dig and finally piece together the appropriate answer. Such is the documentation for getting XCode to play with Perforce. Assuming you're an XCode junkie the docs are straightforward enough. For this part time player - I was unnerved by the following statement that was stated in the docs under the section of Perforce.

"Open the project in Xcode and set the SCM system to Perforce. See Xcode Help for details."

So what the hell does this mean? Perhaps preferences? No. Perhaps it's per project - don't know. Time for google (like life in general) - After a big of digging I find out. I need to see an inspector.. This can be found by either right clicking under the top most group and saying get info or under File->Show Inspector.

Once this is up all you need to do is under the General Tab at the bottom enable SCM. and edit the appropriate options.

  • perforce tool path (/usr/local/bin/p4)
  • P4PORT ( hostname:port )
  • P4CLIENT ( from above - I called my steven )
  • Username and Password ( from above )

At this point you should have a perforce enabled environment.

Posted by Steven at 03:21 AM | Comments (0)

February 25, 2005

Setting up SCM - Welcome Perforce...

OK I admit it - I HATE CVS. It is a kludgy mess and anyone that has used it. I like the comment from this article which states

"CVS was designed by hamsters on crystal meth."

Well if your a sole hacker and want something to use personally that's FREE - use perforce it'll save you time and energy. And you won't have UGLY CVS files all over the place - Yuck.

I will install this the sysadmin way - and allow ssh tunneling to occur so I can limit who has access to my repository

For the purposes of this I am going to make the following assumptions..

1.) You develop something that you would like to have version control over. That something is represented by 1's and 0's and can be seen on a computer screen.
2.) You have access to a Linux Machine. (Not necessary but for this install yes it is - and NO I won't help you on your windows box )
3.) You have a connection to the internet.
4.) You have some brains - they help :)

Ok, that's outa the way. Check out the following links.

So go get perforce. Pull p4 p4d (if you want p4v too)

Install it by doing the following:
# cp p4 /usr/local/bin/
# chmod 755 /usr/local/bin/p4
# cp p4d /usr/local/bin/

So that was easy - now let's get a perforce user and group defined..
# groupadd -g 500 perforce
# adduser -u 500 -g perforce -d /home/depot -s /bin/false perforce

Now let's put this in the local start up scripts as a daemon..

start-stop-daemon --start --quiet --chuid perforce:perforce \
--exec /usr/sbin/p4d \
-- -q -L /var/log/perforce \
-J /mnt/local/perforce/journal \
-p 1667 -d -r /home/depot

Ok then kick it over.. See her start up -- voila!

Now using p4v attempt to connect to localhost:1666 If you can your in business!!

Now let's get some authentication going.. First things first - p4 protect to set up basic protections

# p4 protect

Modify it so only user foo can write to my repository..

Protections:
write user foo * //...
super user root * //...

And save the file. This gives superuser access (root) and foo has (write) access. Now let's limit how we gain access from outside of our network..

Creating an ssh port forwarder.. On our client run the following:
ssh <linux-box> -L 1666:localhost:1667

This sets up a secure tunnel to the remote 1667 port using my local 1666 port. Way cool. Now I can connect to it anytime I want to from outside my network.

Now what makes it easier is to add the following to your ~/.ssh/config file

Host tunnel
User <user-name>
Hostname <linux-box>
LocalForward 1666 localhost:1667
GatewayPorts no

Now in the future all I have to do type ssh tunnel and the tunnel is created!! Once this is created now you simply connect to the localhost port 1666 and it magically and securely heads over to the the linux box! Way cool!

Or if you run a mac pull this cool little app!

OK enough for today.

Posted by Steven at 10:00 PM | Comments (0) | TrackBack

February 18, 2005

Quick hint - Enable READLINE for python on OSX

This is simple enough but damn it took me awhile to figure it out.
Get readline and install the .so into the python tree..

wget http://www.pycs.net/bbum/2004/1/21/readline.so.gz
gunzip readline.so.gz
sudo mv readline.so /Library/Python/2.3

Get readline and install the .so into the python tree..

Time to Start from the album "The Complex" by Blue Man Group

Posted by Steven at 11:39 PM | Comments (0)