Dynamic import module in python

Let’s say you want to create a dynamic application extensible feature with module, all module file will be located on some directory so when the application was loaded it will scan all module file  and inject it dynamically with magic function __import__ to core application.

Here some example with module directory modules 

import os

import sys

# module path that will be included

mdlpath = "modules"


# a variable that will contain all modules

modules = {}

for x in os.listdir(mdlpath):

    # get filename only

    x = os.path.basename(x)

    # split out name file and it's format

    module, ext = os.path.splitext(x)

    # we only accept python file

    if ext is not '.py': continue

    modules[module] = __import__(module)

# try to run a function within module

for name,module in modules.iteritems():

    print "Running %s" % name

    module.run("Run in core application")


Here some an example of module file that has function run 

# filename  modules/ hello.py

def run(msg):

    print msg


You can structure another design of your module like extended class based for instance.


Happy hacking

Propagate cluster.conf to all nodes

It would be easier when we want to change some cluster configuration (/etc/cluster/cluster.conf) using Luci, more over for propagate cluster.conf to all nodes, but sometime i’am often in condition cannot install the package or has a limited access to active it due corporate policy.

So the alternative solution beside send configuration through scp is by using cman_tool, first of all change cluster configuration by increase it by 1, Example:


<?xml version="1.0"?>
<cluster config_version="9" name="DB_CLUST">



<?xml version="1.0"?>
<cluster config_version="10" name="DB_CLUST">

then run cman_tool for propagating to all nodes

cman_tool version -r

Zimlet, add attachment option

This is an example adding attachment option with name Sisipan

 SomeOtherZimlet.prototype.init = function(){



SomeOtherZimlet.prototype.addAttachmentOption = function(){

     this._msgController = AjxDispatcher.run("GetMsgController");
     var viewType = appCtxt.getViewTypeFromId(ZmId.VIEW_MSG);

     // apply this option to all attachment type 
     for ( var mimeType in ZmMimeTable._table) {
           this._msgController._listView[viewType].addAttachmentLinkHandler(mimeType, "simpanan", this.generateAttOption);


// Callback function for generating attachment link button 
SomeOtherZimlet.prototype.generateAttOption = function(attachment){

  var html= "<a href='#' onClick='alert(\""+attachment.label+", This Attachment Located At: "+attachment.url+" \")'>Simpanan</a>";

  return html;

Here the result when an email has attachment and Simpanan link button is clicked


Zimlet base class

Base of zimlet plugin must extend from class ZmZimletBase, and the initialization method  that will be executed every Zimbra Webmail Loaded is init. here some example

function SomeOtherZimlet () {}

SomeOtherZimlet.prototype = new ZmZimletBase();

SomeOtherZimlet.prototype.constructor = SomeOtherZimlet;

SomeOtherZimlet.prototype.init = function(){

     console.log("[SomeOtherZimlet] LOADED");


If you open web development console then you will have an output message [SomeOtherZimlet] LOADED.


These are the best practice to learn creating zimlet:

  • See the unsorted tutorial at Zimbra Wiki Page
  • Reading deployed zimlet that exist at /opt/zimbra/zimlets-deployed
  • If you don’t have zimbra at your environment test, you can see it online at mirror of zimbra repository at github
  • Learning how other or customized zimlet at Zimlet Gallery but the challenge is some or much of zimlet for zimbra 6/7 doesn’t work in zimbra latest version so you must hold tightly at Zimlet Api Documentation

Decode Url Parameter

When i tracing some ajax activity from an apps that connected to Alfresco API like this

Event though it still readable but sometime the url are more longer with ticket ID, i can encode the url with online tools such as this one but my friend told me it can be done with python.

from urllib import unqoute

target = &amp;quot;;quot;
print unqoute(target)