Grok
Getting started with Grok¶
This chapter will help you get up and running with Grok, using the grokproject tool. We create a new project with grokproject and tell you how to get that project running so you can access it with a web browser.
Setting up grokproject¶
Setting up grok on a Unix-like (Linux, Mac OS X) environment is easy. Most of these instructions should also work in a Windows environment as well.
Let’s go through the prerequisites first. You need a computer connected to the internet, as Grok installs itself over the network. You also need Python 2.5 (or Python 2.4) installed.
Because Grok uses a source distribution of the Zope Toolkit libraries, you may need to install your operating system’s Python “dev” package. You also need a working C compiler (typically gcc) installed, as we compile bits of the Zope Toolkit during setup. On Windows such a build environment is not necessary, as grokproject will download and automatically install precompiled libraries for Windows. Finally, you also need easy_install installed so it becomes easy to install Python packages.
Once you are done with the prerequisites, you can install grokproject itself:
$ easy_install grokproject
If you are on a Unixy environment and you are not working from the recommended virtualenv, you will need to request admin rights using sudo, as this will install new libraries into your system Python.
We’re ready to create our first grok project now!
Creating a grok project¶
Let’s create a first Grok project. A Grok project is a working environment for a developer using Grok. In essence, a directory with a lot of files and subdirectories in it. Let’s create a Grok project called Sample:
$ grokproject Sample
This tells grokproject to create a new subdirectory called Sample and set up the project in there. grokproject will automatically download and install the Zope Toolkit libraries as well as Grok into the project area.
Grok asks you for an initial username and password for the server. We’ll use grok for both:
Enter user (Name of an initial administrator user): grok
Enter passwd (Password for the initial administrator user): grok
Now you have to wait while grokproject downloads and installs the various tools and libraries that are needed in a Grok project. The second time you create a Grok project it will be faster as it can reuse the previously installed libraries. After all that your Grok project is ready to go.
Starting up the web server¶
You can go into the Sample project directory now and start up the web server for our project:
$ cd Sample
$ bin/paster serve parts/etc/deploy.ini
This will make Grok available on port 8080. You can log in with username grok and password grok. Assuming you’ve started up the web server on your development computer, you can go to it here:
http://localhost:8080
This first pops up a login dialog (username: grok and password: grok). It will then show a simple Grok admin interface. This user interface allows you to install new Grok applications.
Our sample application (sample.app.Sample) will be available for adding. Let’s try this out. Go to the Grok admin page:
http://localhost:8080
and add a Sample application. Give it the name test.
You can now go to the installed application if you click on its link. This will bring you to the following URL:
http://localhost:8080/test
You should see a simple web page with the following text on it:
Congratulations!
Your Grok application is up and running. Edit
sample/app_templates/index.pt to change this page.
You can shut down the server at any time by hitting CTRL-c. Shut it down now. We will be shutting down and starting up the server often in this tutorial.
Practice restarting the server now, as you’ll end up doing it a lot during this tutorial. It’s just stopping and starting it again: CTRL-c and then bin/paster serve parts/etc/deploy.ini from your Sample project directory.
Alternatively, you can use the –reload flag to start up paster with a monitor that scans your code base (python files only) for changes and automatically restarts the server every time you make a change:
$ bin/paster serve --reload parts/etc/deploy.ini


