import os

import fabdeploytools.envs
from fabric.api import env, lcd, local, task
from fabdeploytools import helpers

import deploysettings as settings

env.key_filename = settings.SSH_KEY
fabdeploytools.envs.loadenv(settings.CLUSTER)

ROOT, PROJECT_NAME = helpers.get_app_dirs(__file__)


@task
def pre_update(ref):
    with lcd(PROJECT_NAME):
        local('git fetch')
        local('git fetch -t')
        local('git reset --hard %s' % ref)


@task
def update():
    with lcd(PROJECT_NAME):
        local('npm install')
        local('make install')
        local('cp src/media/js/settings_local_hosted.js src/media/js/settings_local.js')
        local('make build')
        local('node_modules/.bin/commonplace langpacks')


@task
def deploy():
    helpers.deploy(name=settings.PROJECT_NAME,
                   app_dir='marketplace-operator-dashboard',
                   env=settings.ENV,
                   cluster=settings.CLUSTER,
                   domain=settings.DOMAIN,
                   root=ROOT)

@@ -1007,8 +1007,695 @@
 t=ROOT)%0A
+%0A%0A@task%0Adef build():%0A    with lcd(PROJECT_NAME):%0A        local('npm install')%0A        local('make install')%0A        local('cp src/media/js/settings_local_hosted.js '%0A              'src/media/js/settings_local.js')%0A        local('make build')%0A        local('node_modules/.bin/commonplace langpacks')%0A%0A%0A@task%0Adef deploy_jenkins():%0A    r = helpers.build_rpm(name=settings.PROJECT_NAME,%0A                          app_dir='marketplace-operator-dashboard',%0A                          env=settings.ENV,%0A                          cluster=settings.CLUSTER,%0A                          domain=settings.DOMAIN,%0A                          root=ROOT)%0A%0A    r.local_install()%0A    r.remote_install(%5B'web'%5D)%0A

add jenkins deploy targets