#!/usr/bin/env python
import os
from dm.cli.makeconfig import DomainConfigMaker

class ConfigMaker(DomainConfigMaker):

    template = """[DEFAULT]
# Base path (required, but only within some of the values below).
master_dir = /path/to/kforge

# Path to folder for KForge project service files (required).
project_data_dir = %(master_dir)s/var/project

# Name of KForge service (default: KForge).
service_name = KForge

# Server name of KForge service (defaults to platform hostname).
#domain_name = kforge.my.domain

# Mode of operation (default: production).
#system_mode = development

[virtualenv]
# Path to bin folder of virtual environment (required within virtualenv).
#bin_dir = %(master_dir)s/bin

[environment]
# Timezone, see platform's zoneinfo database (defaults to environment).
timezone = Europe/London

[logging]
# Path to KForge log file (required).
log_file = %(master_dir)s/var/log/kforge.log
# Log level ERROR, WARNING, or INFO (default: ERROR).
#level = INFO

[db]
# When type is sqlite, set name to be a file path. Otherwise
# for postgres (and mysql) set a normal database name and
# set the user, password and host if necessary. (Required.)
type = sqlite
name = %(master_dir)s/var/sqlite.db
#user = kforge
#pass = 
#host = localhost

[memos]
# Enable memoization of access controller results (not enabled by default).
#enabled = on
# Maximum number of memos to store (default: 3000).
#limit = 3000
# Maximum time (seconds) validity of memos (default: 30).
#expire = 30

[django]
# Path to folder of template files (required).
templates_dir = %(master_dir)s/templates
# Secret to seed session key generation (default: not-a-secret).
#secret_key = make-yourself-a-new-secret-key 

[www]
# Path to folder with css, images, and scripts (required).
media_dir = %(master_dir)s/media
# Path to auto-generated Apache configuration file (required).
apache_config_file = %(master_dir)s/var/httpd-autogenerated.conf
# Shell command to reload Apache when config changes (default: blank).
#reload_apache = sudo /etc/init.d/apache2 restart

[email]
# Send notifications of changes to administrators (not enabled by default).
#notify_changes = on
# Email address for send of service emails (defaults to good guess).
#service_address = kforge-noreply@your.domain.com
# Socket for connections with SMTP server (default: localhost).
#smtp_host = localhost

[feed]
# Maximum number of items in feed (default: 100).
#length = 100
# Maximum number of items in feed summary (default: 25).
#length_summary = 25

## ********************************************************************
## Plugins
## ********************************************************************
[moin]
# Path to MoinMoin folder containing the htdocs folder (required).
system_path = /usr/share/moin

[trac]
# Trac admin script (default: trac-admin).
#admin_script = trac-admin
# Path to Trac templates folder (required < v0.11).
#templates_path = /usr/share/trac/templates
# Path to Trac htdocs folder (optional).
#htdocs_path = /usr/share/trac/htdocs

[wordpress]
# Path to master Wordpress installation to be used as a template (required).
master_path = /usr/share/wordpress

[joomla]
# Path to master Joomla installation to be used as a template (required).
master_path = /usr/share/joomla_1.5
# Shell command to backup the Joomla database (required).
backup_command = mysqldump --user=yourusername --password=yourpassword yourdbname
"""

    def addOptions(self, parser):
        super(ConfigMaker, self).addOptions(parser)
        parser.add_option(
            '--trac-admin',
            dest='tracAdmin',
            help="""The path to your trac-admin script.""")

        parser.add_option(
            '--project-data-dir',
            dest='projectDataDir',
            help="""The folder to be used for project service data.
Please note that it can be worth setting this path outside of
any master folder (--master-dir). New versions of KForge can be installed
separately to previous installations but will need to use the same
project service data folder, which must not be moved once created.
    """)

        parser.add_option(
            '--kforge-apache-config',
            dest='apacheConfigFile',
            help="""The filesystem path to the auto-generated KForge Apache
configuration file.""")

    def addOptionLines(self, options, optionLines):
        super(ConfigMaker, self).addOptionLines(options, optionLines)
        if options.projectDataDir:
            optionLines.append('[DEFAULT]')
            optionLines.append('project_data_dir = %s' % os.path.abspath(options.projectDataDir))
        if options.apacheConfigFile:
            optionLines.append('[www]')
            optionLines.append('apache_config_file = %s' % options.apacheConfigFile)
        if options.tracAdmin:
            optionLines.append('[trac]')
            optionLines.append('admin_script = %s' % options.tracAdmin)

if __name__ == '__main__':
    ConfigMaker()

