Wednesday, July 22, 2009

Basic Google App Engine command line

Some basic Python SDK commands in Google App Engine
  • dev_appserver.py - the development web server
  • appcfg.py - for uploading your app to App Engine
To run a local instance of a site named mysite within the Google App Engine localserver, invoke command line:

dev_appserver.py mysite (as opposed to python manage.py runserver)

When it comes to starting a project you can opt for either the built-in 0.96 of Django that is in the SDK or alternately bootstrap a 1.x version of Django. If the built-in is satisfactory, the first step in creating the new app engine site is identical to starting a self-standing Django project:

django-admin.py startproject mysite

If you choose the latter method, you will have more flexibility with the latest features of Django. This requires a different startup. You can simply checkout the latest helper app from google code. This serves as a platform for the applications you plan to create. Here's the command line:

svn checkout http://google-app-engine-django.googlecode.com/svn/trunk/ mysite

So now you're all set with a base. Don't forget that with 1.x of Django, you have to put in the Django library locally, probably best using the zipimport method, the details of which are in an earlier post on this blog. Regardless of which Django version you opt for, creating an application is done thus:
python manage.py startapp myapp
Next, begin connecting the apps as you would in Django standalone, via urls.py. There are also special requirements using the App Engine datastore instead of an relational database. More info on the differences can be found here.

Tuesday, July 21, 2009

PIL for Google App Engine's Python SDK

If you plan to use images in your Django-framwork Google App, you need to add the Python Image Library. If you are using os x 10.5, this bullet list can help set it up. This assumes you are working with the native Python 2.5 installation rather than a new install. Why install it again? You don't need to.
That should be all that is required.

Google App Engine with Django 1.0

Google App Engine has offered Django 0.96 out of the box since it launched in mid 2008. That has changed as of this month.

Applications can now choose either Django 0.96 or what is currently the latest stable release, 1.0.2. This means there is no need to post a zipfile to your appspot in order to utilize the latest Django. But is it that simple? Not quite.

While the cloud has the latest version, your local server environ does not. In other words, the SDK and appspot server are a bit different. This means you still need the Django Helper to run 1.0.2 locally, where you will probably be developing your site.

I went through this process and found many resources to shed light on the procedure. Some are more suited than others, due to good but out-of-date info on the woodpile. Here's what did work:
  • Google Code documentation on the Python SDK - what I like to think of as the GAE personal web server, though it's actually that and a bit more.
  • Google documentation on the Django Helper - required reading but terse. Provides and describes a turnkey local project running Django 1.0.2.
  • Finally, from Bubble Foundry in Nederland, the paydirt, aka how to get it done, aka as direct as a battleaxe to the head. Thanks, I needed that!
Good luck setting up your dev environment. Google labs makes it not so bad after all.

Monday, July 20, 2009

Up and running with Eclipse 3.5

In a previous post, I mentioned the recent release of version 3.5 aka Galileo of the Eclipse Builder. Since that time, I have found several Galileo-compatible plug-ins that make it worthwhile to make the leap to 3.5 now rather than later.

I installed Eclipse 3.5 with the latest Graphical Editing Framework tools, 3.5.0, and the latest Aptana Studio, 1.5.1. All together this makes for an invaluable core development platform. Installing it took some trial and error, so I will share with you the successful install process I used. It took several error-prone attempts to get a clean build. Now it works just super. Here's how:
  • Download Galileo 3.5 to your downloads folder and extract the zip
  • Download GEF 3.5.0 from the downloads page.
  • Extract the GEF 3.5.0 zip locally and add the folder resources from your unzipped GEF 3.5.0 into the corresponding Galileo 3.5 folders. Do not overwrite the folders, as sometimes happens when you unpack an archive into the destination folder. In other words, mixing these together is best done by hand.
  • Run Galileo, which should fire up error free. So far so what. Now plug in some Aptana goodness. This is best done using Help>Install New Software... In the field marked Work with:, don't bother with 'Add...', just plug http://update.aptana.com/install/studio directly into the field and look for the Aptana Studio checkbox to appear below.
If this all works, you are good to go. The time saver of this how-to may not be apparent, so let me add for those who try different methods that automating the installation of GEF in one of the many apparently valid ways of doing this...will not succeed. Or at minimum, they will not succeed under OS X and Galileo Classic in Cocoa 32 bit, which is the version I opted for.

Hang loose, amigos.

Thursday, July 16, 2009

Flash Actionscript vs Open Source Javascript Animation

The eye does not deceive: javascripted animation still has significant limitations. While it's perfectly suitable for image fades and graduated motion via jQuery or similar packages, more liberal applications tend to cause the jitters.

At the heart of this is a lack of graphics operation handlers - helper functions to assist processor-intensive math and graphics-array operations before they reach a bottleneck. Such co-processing operations are a cornerstone of rich media plug-in technologies like Flash and Silverlight.

In spite of this, it's interesting what can be accomplished with development kits like Processing. An open source animation suite and "electronic sketchbook for developing ideas," Processing has gained many followers in the realm of academia, while the down and dirty commercial market continues to patronize plug-in solutions.

With browser capabilities on the rise, there is a huge upside for better native animation in future browser versions. Consequently, the open source community is poised to gain more animation and graphics programming devotees.

Update: Google's Chrome is on the move with native graphics processing in javaScript. Have a look at this example via drawlogic that uses the HaXe (pron: 'hex') version of the Sandy library. You will need to launch Chrome to see it. These are some bold smoke signals for Adobe to heed.

Version Control with Subversion

Setting up version control for, among other things, Flex code repositories, is not too hard to set up with Mediatemple (dv) accounts. SVN is already ready to run from SSH.

I followed these steps to get it up and going. What's more, it works.
  • Svn on mediatemple knowledgebase article is here
  • Great overview on bit-101.com
Good luck with your own implementations.

Update: I set up a SVN repository server on my account and it is simple to use in Eclipse projects. Once your repository is configured, whenever you start a new project, simply right click it in Eclipse, then choose Team > Share Project... All you have to do is enter your username and password, and the IDE will take care of starting a new svn repos. The dark master will be pleased...

Thursday, July 9, 2009

Django AMF Service

Now that the basic Django framework is in place (admin, views, urls), the focus shifts to data and services. In the past, WebORB has been adept at providing RPC between ASP and RIA, so it's tempting to use it again in a Linux environment.

Since the current project is Apache, one option is to utilize Apache Tomcat. Tomcat is readily available in MediaTemple's (dv) configuration to provide a pure Java HTTP server environment. This would pair well with WebORB for Java, a robust middleware solution for RIA data synchronization.

Good enough but the tiers don't fully align with the planets yet. My goal is to utilize remote procedure calls to mySQL and take advantage of the schema I've built in Python-based Django. That will not be possible until my Python objects can be called from Java. So, is it possible to port Python code to WebORB via a Python -> Java compiler?

In a word, Jython.

Jython runs in Tomcat as an implementation of the Python programming language. By compiling the Django code, Jython could route between Flex on the front end and the mySQL admin system within the framework of Django.

Incidentally, I'm not going to implement this cookbook recipe just yet. I've worked with WebORB and am sold on it's strengths, but in this instance I'm looking for a lighter and more agnostic solution for the frontend than a uniform rich presentation server.

Namely, I'm going to move forward with Django AMF PyAMF. This allows some of Django's front-end capabilities to shine, and also enables javascript and ajax elements to be plugged into the site design.

More posts to come on this direction.

Out of curiosity, has anyone else tried the setup I outlined above, i.e. Django <-> Java <-> RPC tier <-> RIA? Furthermore, would you go a completely different route or change any of the tiers from the architecture I outlined? It is one of countless possibilities, and on that note, in my experience, one of the most direct and stable available.

Monday, July 6, 2009

Django MVC Basics Pt 1: URLconf

The URLconf - mapping between URLs and view functions that should be called for those URLs.

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),

# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
# (r'^admin/', include(admin.site.urls)),
)
Important to note are:
r - Python indication that the string is a "raw string", i.e. do not interpret characters.
' ' - string enclosed in single quotes
^ - caret, a regular expression meaning "require that the pattern matches the start of the string"
$ - dollar sign, regex meaning "require the pattern match the end of the string".

e.g. ensures this works: www.url.com/hello/
and this does not: www.url.com/hello/there (thanks to $)
and this does not:www.url.com/there/hello (thanks to ^)

See table of basic Regular Expressions - from the Django Book.

The second parameter in the 2-tuple sometimes begins with include(... and sometimes does not. It is the function to be associated with the specified URL. The function's first parameter is always the HttpRequest object. Always. Here's documentation on the HttpRequest object's API.