#!/usr/bin/python
from paella.installer.toolkit import InstallerTools
from paella.installer.network import METHODS

print "config script for debrepos"
it = InstallerTools()
env = it.env()

# some helpers to keep from passing the trait
# name around too much

def has_key(name):
    key = 'debrepos:%s' % name
    return env.has_key(key)

def get(name):
    key = 'debrepos:%s' % name
    return env.dereference(key)



apache_reprepro_conf = it.target / 'etc/apache2/conf.d/reprepro.conf'

conf_template = """Alias %(httproot)s %(basedir)s
<Directory %(basedir)s>
\tOptions +Indexes +FollowSymLinks
\tAllowOverride None
\torder allow,deny
\tallow from all
</Directory>
"""

basedir = it.get('debrepos:debian_basedir')
httproot = it.get('debrepos:debian_httproot')

print "creating %s" % basedir
cmd = ['mkdir', '-p', basedir]
retval = it.chroot(cmd)
print "%s returned %d" % (' '.join(cmd), retval)


template_contents = dict(basedir=basedir, httproot=httproot)

contents = conf_template % template_contents
apache_reprepro_conf.write_bytes(contents)
print "%s created" % apache_reprepro_conf
