Grok and XML-RPC

Posted: 2007/07/19 12:57:39

XML-RPC using Grok:

What is XML-RPC ? From the site (http://xmlrpc.com): It’s a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet.

So, What is Grok? From the site : Grok is a web application framework for Python developers. It is aimed at both beginners and very experienced web developers. Grok has an emphasis on agile development. Grok is easy and powerful. Grok accomplishes this by being based on Zope 3, an advanced object-oriented web framework. While Grok is based on Zope 3, and benefits a lot from it, you do not need to know Zope at all in order to get productive with Grok. So, it is cool, isn’t it :)

Installation:

To install the latest grok , give the following command ,

#easy_install grokproject
This will download and install grok for you. After this we are ready to rock …

Creating our first project:

Let’s create the project named “Foo”. For that give the command

$grokproject Foo
This will create a subdirectory in the current directory named “Foo”, then it will download Zope3 and install Grok with that which you can start working with. It will ask you a few questions like: “Enter module (Name of a demo Python module placed into the package) [‘app.py’]: “ Press Enter for the default value Then , “Enter user (Name of an initial administrator user): foo Enter passwd (Password for the initial administrator user): foo” We typed “foo” for both the user and password.

Starting up Zope:

Switch to the Foo directory, and give the command

$bin/zopectl fg
This will startup Zope for you , you can access it through a web browser pointing to http://localhost:8080/

Then add an application named foo. You can access it by http://localhost:8080/foo , it will show

Congratulations!

Your Grok application is up and running. Edit foo/app_templates/index.pt to change this page.

Now we are going to write our xmlrpc stuffs inside it.

XML-RPC class:

Now you can open the file src/foo/app.py in a text editor. The default is give below :

import grok

class Foo(grok.Application, grok.Container): pass

class Index(grok.View): pass # see app_templates/index.pt

We will another class which will be available through this application class, the new class should inherit grok.XMLRPC for this , and we will write a say() method. It will return “Hello World!”. So, the changed file:
import grok

class Foo(grok.Application, grok.Container): pass

class Index(grok.View): pass # see app_templates/index.pt

class FooXMLRPC(grok.XMLRPC): “”“The methods in this class will be available as XMLRPC methods on ‘Foo’ applications.“”” def say(self): return ‘Hello world!’

The name of the class doesn’t matter , so you can give any name to that. Restart the Zope in the console, and you can connect to it through any xmlrpc client. Below is an example (fooclient.py):
#!/usr/bin/env python
import xmlrpclib

s = xmlrpclib.Server(‘http://localhost:8080/foo') print s.say()

Run this and see !!

Class in a different file:

What if you want to write the class in a different file in the src/foo directory and still want to have the methods to be available under Foo application. For that you need to tell grok explicitly that the new class to associate it to the Foo model by using the grok.context class annotation.

What is a class annotation? A class annotation is a declarative way to tell grok something about a Python class. Let’s see the example, we will write a Boom.py with a Boom class.

import grok
from app import Foo

class Boom(grok.XMLRPC): grok.context(Foo)

def dance(self):
    return "Boom is dancing!!"</pre>

Look at the line where it says “grok.context(Foo)” this is doing all the magic. In the fooclient.py you just need to call s.dance instead of s.say().

So, now write your dream system …. :D

Comments

Another accident

Posted: 2007/07/16 10:03:33

Last night I put my fingers into the new fan I bought, I am currently using it to cool my desktop. I am really lucky that my fingers are still with me only :) Only few cuts with some pain :(

Comments

Alone!!

Posted: 2007/07/13 15:27:36

Currently in the new office. Suddenly , I figured out that my team is gone , everybody went out for some reason :) Now I want to play some firing music :p

Comments

Accidents and me

Posted: 2007/07/07 01:27:30

I always have a pretty good relationship with accidents. You may remember the last one.

Now the latest:

No power in the morning, went to bathroom, had a candle on top of the flush, forgot to put it off and I came out. So, after few minutes , I found a BIG HOLE on top of my flush . Isn’t it nice ? I love ACCIDENTS ……………

Comments

EPM , makes life easy

Posted: 2007/07/04 14:29:27

Was looking for a simply way to create packages in Debian or RPM based distros. Found EPM .

With EPM you have to write only one file, and you can creare packages in different formats like: aix, bsd, deb, depot, inst, native, pkg, portable rpm, setld, slackware, swinstall, tardist :)

Comments

Interview of Joomla! team

Posted: 2007/06/21 15:56:48

Joomla! is one of the most powerful Open Source Content Management Systems on the planet. It is used all over the world for everything from simple websites to complex corporate applications. Joomla! is easy to install, simple to manage, and reliable.

You can view the video here .

Comments

Interview of LinuxBIOS team

Posted: 2007/06/21 15:52:39

LinuxBIOS is a Free Software project aimed at replacing the proprietary BIOS (firmware) you can find in most of today’s computers.

You can see the video here .

Comments

Interview of Jeroen van Meeuwen (Revisor)

Posted: 2007/06/21 12:47:23

Revisor enables you to customize and compose your own Fedora based installation and live media. It does so by presenting you a GUI with all options you can click you way through, and a CLI and extended configuration files for the more advanced users.

So, you can watch the video here .

Comments

????? ?????? ???? ????? ???

Posted: 2007/06/20 16:12:27

???

Comments

The journey back to Bangalore

Posted: 2007/06/12 02:10:53

This is the story of my come back journey to India :)

The night before I spend at CCC Berlin up-to 2.00AM with Milosch. After getting back to home, Milosch went for a small nap (I saw him working 22hours a day for the last couple of days). I was checking the mails, made some call to home and friends in India. He called up a taxi, and I reached airport at around 4.35AM. The stuffs said check-in will start after 5.30 only. so, tried to figure out from where I can get the Tax back for the stuffs I bought last day.

After 5.30 the check-in started, I put a bag in. Had my laptop & other electronic stuffs in my hand baggage only . At the time of security checking , they asked me to take my laptop and the external hdd with me for a special check. The guard asked me if I know about that checking or not. I replied “No”. So, he told me that it is a special check to find bombs. He took me a small room, and asked me to open my laptop. Then they cleaned it with a vacuum cleaner, I was very happy with that as I never cleaned my keyboard in the last two months :) They also checked the external hard-disk in a strange way. At the end they gave me a clear signal . Later in Bangalore Airport I understood they also broke my lock and never sealed it anyway.

In Bangalore airport the great Custom officers asked me to hand them the OpenPCD board or pay Rs. 2500/- only. I told them to check my bank account, if they can find any money, they can take it. Then the amount came down to Rs.1000/- , I said no way. After 45 minutes of fighting, they gave up , and I successfully came back home :)

Comments

Contents © 2004-2014 Kushal Das - Powered by Shonku