from bundlewrap.metadata import metadata_to_json

pkg_pip = {
    'transmission-rpc': {
        'needed_by': {
            'svc_systemd:telegraf',
        },
    },
}

files = {
    # XXX Manage settings using bundlewrap once transmission has an
    # option to disable config rewriting.
    '/etc/transmission-daemon/initial-settings.json': {
        'content': metadata_to_json(node.metadata['transmission']['config']),
        'mode': '0444',
    },
    '/etc/systemd/system/transmission-daemon.service.d/bundlewrap.conf': {
        'source': 'override.conf',
        'triggers': {
            'action:systemd-reload',
            'svc_systemd:transmission-daemon:restart',
        },
    },
    '/usr/local/bin/telegraf-transmission-plugin': {
        'content_type': 'mako',
        'context': {
            'rpc_port': node.metadata['transmission']['config']['rpc-port'],
        },
        'mode': '0755',
    },
}

actions = {
    'transmission_deploy_initial_settings': {
        'command': 'cp /etc/transmission-daemon/initial-settings.json /etc/transmission-daemon/settings.json',
        'unless': 'test -f /etc/transmission-daemon/settings.json',
        'needs': {
            'file:/etc/transmission-daemon/initial-settings.json',
        },
        'needed_by': {
            'pkg_apt:transmission-daemon',
        },
    },
}

svc_systemd = {
    'transmission-daemon': {
        'needs': {
            'pkg_apt:transmission-daemon',
        },
    },
}
