Just got my visa. See you all there!
Thursday, October 27, 2011
Clearing Evolution IMAP local mail cache
Quite straightforward:
rm -rf ~/.local/share/evolution/mail/{imapx,imap}/*
Friday, October 14, 2011
Friday, October 07, 2011
Opps ..
Opps , to Fedora Planet, sorry that some old posts appeared in frontpage .. I changed my feed to aggregate the PlanetFedora tag instead of Fedora, and tagged a number of old contents ..
but seems like PlanetPlanet sorted items by updated date rather than published date ..
but seems like PlanetPlanet sorted items by updated date rather than published date ..
Tuesday, October 04, 2011
A simple demo application using collective.trajectory
Last week I wrote about a Plone library called collective.trajectory which allows you to do url routing on Plone content type. Back then it was only able to route the context, but I have yet to try develop something on it yet.
A few days ago on geekcamp.my, I gave a talk on it, so naturally, I'll need to test to develop something on it first before doing the talk. Using trajectory, I hacked together a simple app, which fetch a profile page from Facebook, to demonstrate the library capabilities. Here's the howto.
Goals
Create a content type which can be added on any part of site, where if user load a subpath of the content, it will load a profile info from graph.facebook.com, and serve it as a context in Plone.
Creating an archetype project
First you'll need ZopeSkel in your buildout. Add this section into buildout.cfg:
Execute
Create an archetype product using ZopeSkel.
That should create a directory called example.trajectory in the current directory. Now, lets create a simple archetype content.
Notice that Folderish is False. We doesn't need the content to be folderish here.
Hooking the archetype product to Plone
After creating the archetype product above, we'll need to hook it in Plone.
In your buildout.cfg, add these:
Run ./bin/buildout and at this point, you should have the base we need for this demo app. If you start the Plone server you should see the product installable, and you can add the content after installing the product. Now for the fun stuff.
Registering trajectory traverser to contenttype
Edit example.trajectory/example/trajectory/configure.zcml , and add this:
Registering routes and factories
Edit example.trajectory/example/trajectory/content/facebookprofiles.py, and you can register the routes directly there.
Done, now when you access http://site/path/to/facebookprofilesapp/profile/somefacebookid, you should get a Profile object.
Now we need to register a simple view for the profile
Registering a default view
Create example.trajectory/example/trajectory/browser/facebookprofiles.py and fill it with this:
Edit example.trajectory/example/trajectory/browser/configure.zcml and add this:
Create example.trajectory/example/trajectory/browser/profileview.pt and fill it with this:
Thats it, if you add the FacebookProfiles content into your plone site, take for example http://site/myfolder/fbprofiles , when you load http://site/myfolder/fbprofiles/profile/yourfacebookid you should get a page with user 'yourfacebookid' details
I've uploaded the example.trajectory demo into https://svn.plone.org/svn/collective/example.trajectory/trunk/ so that you can try it and refer to it.
Happy hacking!
A few days ago on geekcamp.my, I gave a talk on it, so naturally, I'll need to test to develop something on it first before doing the talk. Using trajectory, I hacked together a simple app, which fetch a profile page from Facebook, to demonstrate the library capabilities. Here's the howto.
Goals
Create a content type which can be added on any part of site, where if user load a subpath of the content, it will load a profile info from graph.facebook.com, and serve it as a context in Plone.
Creating an archetype project
First you'll need ZopeSkel in your buildout. Add this section into buildout.cfg:
[paster] recipe = zc.recipe.egg eggs = ZopeSkel PasteScript
Execute
./bin/buildout install paster afterwards. Once thats done, you should have paster command in your bin directory.Create an archetype product using ZopeSkel.
./bin/paster create -t archetype Selected and implied templates: ZopeSkel#basic_namespace A basic Python project with a namespace package ZopeSkel#plone A project for Plone products ZopeSkel#archetype A Plone project that uses Archetypes content types Enter project name: example.trajectory .....
That should create a directory called example.trajectory in the current directory. Now, lets create a simple archetype content.
cd example.trajectory ../bin/paster addcontent contenttype Enter contenttype_name (Content type name ) ['Example Type']: FacebookProfiles Enter contenttype_description (Content type description ) ['Description of the Example Type']: An application which fetch facebook profile from graph.facebook.com Enter folderish (True/False: Content type is Folderish ) [False]:
Notice that Folderish is False. We doesn't need the content to be folderish here.
Hooking the archetype product to Plone
After creating the archetype product above, we'll need to hook it in Plone.
In your buildout.cfg, add these:
[buildout]
eggs =
...
collective.trajectory
example.trajectory
...
zcml =
...
collective.trajectory
example.trajectory
...
develop =
...
./example.trajectory
...
Run ./bin/buildout and at this point, you should have the base we need for this demo app. If you start the Plone server you should see the product installable, and you can add the content after installing the product. Now for the fun stuff.
Registering trajectory traverser to contenttype
Edit example.trajectory/example/trajectory/configure.zcml , and add this:
<adapter factory="collective.trajectory.components.Traverser"
for="example.trajectory.content.facebookprofiles.FacebookProfiles
zope.publisher.interfaces.IRequest"/>
Registering routes and factories
Edit example.trajectory/example/trajectory/content/facebookprofiles.py, and you can register the routes directly there.
...
import traject
from collective.trajectory import getApp, Model
from zope.globalrequest import getRequest
import json, urllib
...
class FacebookProfiles(base.ATCTContent):
...
class Profile(Model):
def __init__(self, id, data):
self.id = id
self.data = data
def factory(profile_id):
data = urllib.urlopen('http://graph.facebook.com/%s' % profile_id).read()
data = json.loads(data)
return Profile(profile_id, data)
def arguments(obj):
return {
'profile_id': obj.id
}
traject.register(FacebookProfiles, 'profile/:profile_id', factory)
traject.register_inverse(FacebookProfiles, Profile,
'profile/:profile_id', arguments)
Done, now when you access http://site/path/to/facebookprofilesapp/profile/somefacebookid, you should get a Profile object.
Now we need to register a simple view for the profile
Registering a default view
Create example.trajectory/example/trajectory/browser/facebookprofiles.py and fill it with this:
from Products.Five import BrowserView
class ProfileView(BrowserView):
pass
Edit example.trajectory/example/trajectory/browser/configure.zcml and add this:
<browser:page
name="index"
for="example.trajectory.content.facebookprofiles.Profile"
template="profileview.pt"
permission="zope2.View"
class=".facebookprofiles.ProfileView"/>
Create example.trajectory/example/trajectory/browser/profileview.pt and fill it with this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="context/main_template/macros/master">
<head>
</head>
<body>
<div metal:fill-slot="content">
<h1 tal:content="context/data/username"/>
<dl>
<dt>Fullname</dt>
<dd tal:content="context/data/name"></dd>
<dt>Facebook Page</dt>
<dd><a href="#" tal:attributes="href context/data/link" tal:content="here/data/link"></a></dd>
</dl>
</div>
</body>
</html>
Thats it, if you add the FacebookProfiles content into your plone site, take for example http://site/myfolder/fbprofiles , when you load http://site/myfolder/fbprofiles/profile/yourfacebookid you should get a page with user 'yourfacebookid' details
I've uploaded the example.trajectory demo into https://svn.plone.org/svn/collective/example.trajectory/trunk/ so that you can try it and refer to it.
Happy hacking!
Monday, October 03, 2011
Email server with Postfix, Dovecot, and LDAP
I think I'll skip the introduction as this is mainly a note for myself
The LDAP Setup
I'm not going to cover how to setup LDAP. The setup that I'm using for this system is organized where all users are under an Organizational Unit called 'people' (ou=people,dc=organization,dc=org) with this schema:
Configuring Dovecot
Add these into dovecot.conf
dovecot-ldap.pass
dovecot-ldap.user
Configuring Postfix
Add these into your main.cf
Make sure domains under virtual_mailbox_domains is not listed under mydestinations.
Thats it I think, not sure if I missed anyting.
The LDAP Setup
I'm not going to cover how to setup LDAP. The setup that I'm using for this system is organized where all users are under an Organizational Unit called 'people' (ou=people,dc=organization,dc=org) with this schema:
dn: uid=user,ou=people,dc=organization,dc=org objectClass: posixAccount objectClass: inetOrgPerson uid: user homeDirectory: /home/user userPassword: <passwordhash>
Configuring Dovecot
Add these into dovecot.conf
mail_uid = 5000
mail_gid = 5000
auth default {
mechanisms = plain
passdb ldap {
args = /etc/dovecot-ldap.pass
}
userdb ldap {
args = /etc/dovecot-ldap.user
}
# for postfix to authenticate against
socket listen {
client {
# Assuming the default Postfix $queue_directory setting
path = /var/spool/postfix/private/auth
mode = 0660
# Assuming the default Postfix user and group
user = postfix
group = postfix
}
}dovecot-ldap.pass
hosts = host.of.ldap.server:389 sasl_bind = no auth_bind = yes ldap_version = 3 deref = never base = uid=%n,ou=people,dc=organization,dc=org scope = base dn = uid=manager,dc=organization,dc=org dnpass = password
dovecot-ldap.user
hosts = host.of.ldap.server:389 sasl_bind = no auth_bind = yes ldap_version = 3 deref = never base = uid=%n,ou=people,dc=organization,dc=org scope = base user_attrs = homeDirectory=home dn = uid=manager,dc=organization,dc=org dnpass = password
Configuring Postfix
Add these into your main.cf
accounts_server_host = host.of.ldap.server accounts_search_base = ou=people,dc=organization,dc=org accounts_query_filter = (&(objectClass=inetOrgPerson)(mail=%s)) accounts_result_attribute = homeDirectory accounts_result_format = %s/Mailbox accounts_scope = sub accounts_cache = yes accounts_bind = yes accounts_bind_dn = uid=manager,dc=organization,dc=org accounts_bind_pw = password accounts_version = 3 virtual_transport = virtual virtual_uid_maps = static:5000 virtual_gid_maps = static:5000 virtual_mailbox_base = / virtual_mailbox_maps = ldap:accounts virtual_mailbox_domains = organization.org smtpd_sasl_type = dovecot smtpd_sasl_auth_enable = yes smtpd_sasl_authenticated_header = no smtpd_sasl_local_domain = smtpd_sasl_security_options = noanonymous broken_sasl_auth_clients = yes smtpd_sasl_path = private/auth
Make sure domains under virtual_mailbox_domains is not listed under mydestinations.
Thats it I think, not sure if I missed anyting.
Radiate: A simple push server for SocketIO (alpha)
Based on my previous post on WebSocket server using Tornado, I've hacked the code more to be a SocketIO server instead of just WebSocket, so that it can be used on many browsers until everyone support WebSocket. The SocketIO connection is handled by TornadIO, a neat SocketIO library for Tornado.
I've uploaded the code here in github: https://github.com/kagesenshi/radiate
I've packaged Radiate together with a buildout.cfg, so you can deploy it easily by just using these few lines of commands
I've uploaded the code here in github: https://github.com/kagesenshi/radiate
I've packaged Radiate together with a buildout.cfg, so you can deploy it easily by just using these few lines of commands
git clone https://kagesenshi@github.com/kagesenshi/radiate.git radiate cd radiate python bootstrap.py ./bin/buildoutTo start the daemon, just execute:
./bin/radiate-admin fgThe readme file on how to deploy and use Radiate is here: https://github.com/kagesenshi/radiate/blob/master/README.txt.
Sunday, October 02, 2011
Simple websocket push service using Tornado
WebSocket server side documentation/guides around tend to be very node.js oriented. However, I don't fancy rewriting stuff I already have simply to be able to make use of WebSocket. After some research, I figured out a mechanism for a service which will handle push for WebSocket, in a simpler manner which are familiar to everyone - simple POST/GET!
Example server code: (on Tornado 11.0)
Example Client Javascript (jQuery)
How to try
Start the Tornado server, load http://localhost:8888/push?data=somedatahere. This will send 'somedatahere' to the websockets and notify them all with the string.
Probably this can evolve to a nicer service system. But I'll hack on it more later
Example server code: (on Tornado 11.0)
import tornado.ioloop
import tornado.web
from tornado import websocket
GLOBALS={
'sockets': []
}
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
class ClientSocket(websocket.WebSocketHandler):
def open(self):
GLOBALS['sockets'].append(self)
print "WebSocket opened"
def on_close(self):
print "WebSocket closed"
GLOBALS['sockets'].remove(self)
class Announcer(tornado.web.RequestHandler):
def get(self, *args, **kwargs):
data = self.get_argument('data')
for socket in GLOBALS['sockets']:
socket.write_message(data)
self.write('Posted')
application = tornado.web.Application([
(r"/", MainHandler),
(r"/socket", ClientSocket),
(r"/push", Announcer),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Example Client Javascript (jQuery)
$(document).ready(function () {
var ws = new WebSocket("ws://localhost:8888/socket");
ws.onmessage = function(event) {
$('body').append('<div>' + event.data + '</div>');
}
$('body').append('<div> Start! </div>');
});
How to try
Start the Tornado server, load http://localhost:8888/push?data=somedatahere. This will send 'somedatahere' to the websockets and notify them all with the string.
Probably this can evolve to a nicer service system. But I'll hack on it more later
Subscribe to:
Posts (Atom)
