Syndgen developer documentation

Adding new features to Syndgen is quite easy. You do not have to to figure out how syndgen works internally. However, it is good to talk about its architecture so you will have a good overview on what you can do around.

Architecture design

It is pretty simple and based on only 2 classes: Application and Task. These are meant to be abstract. Application is the one which owns all the tasks. Every real features in Syndgen are in fact so-called "tasks", so they inherit from Task class. Some task may be passive inside syndgen, they are used to make a group of subtask, like Deploy for instance. Therefore, the sub-task of Deploy (rsync and exclude) are dependent over Deploy. One task may provide a bunch of feature (for instance: ssh task provides 4 features). These features are, inside the task, a callback on which a defined option points on.

Creating a new task

Let's consider the simplest example ever: we want to add a feature which prints only "I am a new task". Only. First, inside root directory of syndgen source code (taken from bzr), just go in syndgen/tasks. There you create a file named "newtask" (taken for the example). Edit it and add:

# Newtask class

from syndgen.base.task import Task
from syndgen.base.error import TaskException
from optparse import make_option, OptionParser

class Newtask( Task ):
    def __init__(self, app):
        configs = {
            "newtask_sentence" : "I am a new task",
            }

        opts = [
            make_option("-n", "--newtask", action="callback", 
                        callback=self.cb_print,
                        help="print the nowtask sentence"),
            ]

        Task.__init__(self, app, "NewTask", 
                      options=opts, 
                      default_configs=configs, 
                      config=app.config)

    def cb_print(self, option, opt, value, parser):
        print self.newtask_sentence

That's it! Now, what the heck is configs and opts? These 2 variables are respectively here for:

  • configuration entry with a default value. That means, here "newtask_sentence" has a default value which set to "I am a new task" and it can be changed in the configuration file of syndgen (in config or, when installed: in /etc/syndgen) like adding that:
[Newtask]
newtask_sentence = the sentence you want
  • option entry in the software so you will see the option "-n" and "--newtask" appearing if you run syndgen -h, the callback of that option is cb_print.

If you wish Newtask class being dependent over Deploy for instance, you can add parent_task="Deploy" as a parameter inside the Task.init() call.

Now, let's add this task into syndgen (syndgen is not plugin-ready, there were no need for that so it has been avoided, though it would be trivial to add). Edit scripts/syndgen file and add in the imports:

from syndgen.tasks.newtask import Newtask

and then inside the try/except:

self.addTask(Newtask(self))

Now you can run syndgen with your new task. That is all. You may have a look at the other tasks if you want to know more.