Pages

Thursday, October 22, 2009

Bogeymin is Almost Alpha

Almost. After my previous exercise in optimism, a number of other projects took precedence over Bogeymin. Even so, I spent last Saturday with blinders on and managed to finish all of the core commands.

I'm hoping to start testing this weekend as well as working on some of the built-in plugins. Speaking of which, the plugins system I've devised is pretty neat -- if I say so myself.

  • It allows the registration of arbitrary callbacks both before and after the command runs. So for example, when installhost is issued, various plugins can express their interest in responding to this activity and execute using the same command line switches that were given to installhost.
  • Plugins may be built in (written here) or user defined (written there). As noted, they have access to the original command line arguments. They can also use Bogeymin's built-in logging, user, and exit tools.
  • Plugins can be disabled or enabled in the main configuration file.

The __init__.py file looks something like this:

# Dependencies.
import os
from bogeymin import bogeymin

# Define the commands we want to which we wish to respond.
_implements = [ 
    'installhost',
    'movehost',
    'renamehost',
    'uninstallhost',
]

# All plugins must define an implements function.
def implements(command):
    """Determine whether the plugin implements the given command. Returns 
    True if implemented, False if not.
    """
    if command in _implements: return True
    return False

# Run after the main command has finished.
def post(Command):
    """Run the plugin *after* execution of the command.

    Command - The command object from Bogeymin.

    Returns an exit code.
    """
    domain_name = Command.getOption('d')

    ServerCfg = bogeymin.ServerConfiguration()
    if not ServerCfg.has('virtual_host','path_shared_ssl'):
        return 1
    path = '%s/%s' %(path_shared_ssl,Command.domain_name)

    if not os.path.exists(path):
        return 1

    if 'installhost' == command:
        return os.system('installsharedssl -d %s' %domain_name)
    elif 'movehost' == command:
        os.system('uninstallsharedssl -d %s' %domain_name)
        return os.system('installsharedssl -d %s' %domain_name)
    elif 'renamehost' == command:
        os.system('uninstallsharedssl -d %s' %domain_name)
        new_domain_name = options[options.index('-n') + 1]
        return os.system('installsharedssl -d %s' %new_domain_name)
    elif 'uninstallhost' == command:
        return os.system('uninstallsharedssl -d %s' %domain_name)

No comments:

Post a Comment