refactor text save form
[redakcja.git] / deployment / base.py
1 # -*- coding: utf-8 -*-
2 import os
3
4 from fabric.api import env, require
5 from fabric.tasks import Task
6 from fnpdjango.deploy import Command
7
8
9 class Environment(Task):
10     def __init__(self, *args, **kwargs):
11         super(Environment, self).__init__(*args, **kwargs)
12         self.npm_bin = kwargs.pop('npm_bin', 'npm')
13         self.host = kwargs.pop('host')
14         self.env_vars = kwargs
15         self.env_vars['skip_collect_static'] = True
16
17     def run(self, *args, **kwargs):
18         env.project_name = 'redakcja'
19         env.hosts = [self.host]
20         for k, v in self.env_vars.items():
21             env[k] = v
22
23         require('app_path')
24
25         build_cmd = '../../ve/bin/python manage.py build --npm-bin=%s --editor-npm-env=%s' \
26             % (self.npm_bin, os.path.join(env['app_path'], 'npm_env'))
27         if 'node_bin_path' in self.env_vars:
28             build_cmd += ' --node-bin-path=%s' % self.env_vars['node_bin_path']
29         if 'editor_optimize' in self.env_vars:
30             build_cmd += ' --editor-optimize=%s' % self.env_vars['editor_optimize']
31
32         env.pre_collectstatic = [
33             Command([build_cmd], '')
34         ]