Wednesday, April 29, 2009

Google App Engine & Eclipse

I am going to show you how to run your Google App (Python) in eclipse without any special plugins!

All you need to do is ensure that you have downloaded and installed both the Google App Engine and Python.

The trick to getting Google apps to run within eclipse is to run your app as an 'External Tool'.

From the Eclipse file menu, click on
Run -> External Tools -> External Tools Configuration ...

In the resulting window, choose to create a new program:



Give it a name (I called it 'App Engine') in the Name field. In the Location field, enter the exact path to your Python executable. For the Working Directory, enter the exact path to the Google App Engine.

The Arguments field is the most interesting one! Here we enter:

dev_appserver.py -d ${resource_loc}

The dev_appserver.py is the Python script that Google tells you to run when you want to test your app.

The -d just tells the App Engine to output debug statements. Feel free to use any command line arguments that the App Engine allows!

Finally, the ${resource_loc} tells Eclipse to use the full path of any item currently selected in the Navigator.


The final thing to do is to click on the Common tab and to Select "Display in favorites menu". This will provide you with a shortcut so that running your Google App requires the least amount of clicks!


Set up is complete!

Now choose the root folder of your Google App in Eclipse and click on 'App Engine' (or the name that you named your External Tool).



As you can see, the App Engine is running!


Some Notes:
  • If the App engine looks like it has hung (froze), click in the Eclipse console and hit the return key on your keyboard. What may have happened is that the App Engine has prompted you to check for updates and Eclipse didn't show you the message.

  • If you get an Eclipse error, "Problem Occurred", make sure that the root folder for your app is selected in Eclipse (i.e. click on it!).
If you have any other things to add, please post your comments!

Monday, April 27, 2009

for loop using 'find'

I find myself constantly creating complex loops and forgetting, for a small instance of time, how to construct them again.

In this case, I wanted to list files that passed a certain criteria and loop over them so that I could call a Perl script on them.

For example:

for i in `find . -type f -name '*.pm' -print`; \
do perl some_script.pl $i; \
done
In the above case, I am searching for all files that end in pm, starting from the current directory (.) and once found, I am executing the perl script some_script.pl on them.

Of course, you don't have run a perl script ... you could just echo the output:

for i in `find . -type f -name '*.pm' -print`; \
do echo found $i; \
done
Now, next time I need to run a similar command, I wont forget how to construct the query!