"""
wkhtmltopdf Blueprint

blueprints:
  - blues.wkhtmltopdf

"""
from fabric.decorators import task

from refabric.context_managers import sudo
from refabric.contrib import blueprints

from . import debian

__all__ = ['setup', 'configure']


blueprint = blueprints.get(__name__)


@task
def setup():
    """
    Install and configure wkhtmltopdf
    """
    install()
    configure()


def install():
    with sudo():
        packages = ['wkhtmltopdf', 'xvfb', 'xfonts-100dpi', 'xfonts-75dpi', 'xfonts-cyrillic']
        debian.apt_get('install', *packages)


@task
def configure():
    """
    Configure wkhtmltopdf
    """
    destination = '/usr/local/bin/wkhtmltopdf.sh'
    blueprint.upload('wkhtmltopdf.sh', destination)
    with sudo():
        debian.chmod(destination, '+x')

@@ -20,16 +20,42 @@
 eprint%0A%0A
+.. code-block:: yaml%0A%0A    
 blueprin
@@ -58,16 +58,22 @@
 prints:%0A
+      
   - blue
@@ -87,16 +87,96 @@
 ltopdf%0A%0A
+    settings:%0A        wkhtmltopdf:%0A            # wkhtmltopdf_version: 0.12.2.1%0A%0A
 %22%22%22%0Afrom
@@ -249,16 +249,26 @@
 ort sudo
+, settings
 %0Afrom re
@@ -299,16 +299,52 @@
 ueprints
+%0Afrom refabric.operations import run
 %0A%0Afrom .
@@ -524,25 +524,8 @@
 l()%0A
-    configure()%0A%0A
 %0Adef
@@ -544,383 +544,900 @@
     
-with sudo():%0A        packages = %5B'wkhtmltopdf', 'xvfb', 'xfonts-100dpi', 'xfonts-75dpi', 'xfonts-cyrillic'%5D%0A        debian.apt_get('install', *packages)%0A%0A%0A@task%0Adef configure():%0A    %22%22%22%0A    Configure wkhtmltopdf%0A    %22%22%22%0A    destination = '/usr/local/bin/wkhtmltopdf.sh'%0A    blueprint.upload('wkhtmltopdf.sh', destination)%0A    with sudo():%0A        debian.chmod(destination, '+x')
+%22%22%22%0A    Install wkhtmltox from the pkgs on sourceforge that are compiled with%0A    patched QT. This version doesn't need X/Xvfb to run.%0A    %22%22%22%0A    # Can't be named version since it'll conflict with fabrics own version variable%0A    wkhtmltox_ver = blueprint.get('wkhtmltopdf_version', '0.12.2.1')%0A    wkhtmltox_pkg = 'wkhtmltox-%7B%7D_linux-%7B%7D-amd64.deb'.format(%0A        wkhtmltox_ver, debian.lbs_codename())%0A    wkhtmltox_url = 'http://downloads.sourceforge.net/project/wkhtmltopdf/%7B%7D/%7B%7D'.format(%0A        wkhtmltox_ver, wkhtmltox_pkg)%0A    run('curl --silent --location --show-error --remote-name %22%7B%7D%22'.format(%0A        wkhtmltox_url))%0A    with sudo():%0A        with settings(warn_only=True):%0A            run('dpkg -i %7B%7D'.format(wkhtmltox_pkg))%0A        debian.apt_get('--fix-broken', 'install')%0A        debian.rm(wkhtmltox_pkg)%0A%0A@task%0Adef configure():%0A    %22%22%22%0A    Configure wkhtmltopdf%0A    %22%22%22%0A    pass
 %0A

Install wkhtmltox from the pkgs on sourceforge