tpl prj
[auf_skeleton_django.git] / deploy.py
CommitLineData
e29df00c
OL
1# -*- coding: utf-8 -*-
2
3import os
4import subprocess
5from pkg_resources import parse_version
6
7PYTHON = "python2.6"
8ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
9VENV_DIR = os.path.join(ROOT_DIR, '.virtualenv')
10
11
12def shell_exec(cmd):
13 """
14 Run blocked shell command.
15 """
16 sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
17 sp.wait()
18 out = sp.stdout.read().replace('\n', '')
19 return out
20
21
22def setup_venv():
23 """
24 Virtualenv setup.
25 """
26 venv_version = shell_exec("virtualenv --version")
27 venv_options = ["virtualenv", VENV_DIR, ]
28
29 if parse_version(venv_version) >= parse_version('1.7'):
30 venv_options.append("--system-site-packages", "--python=%s" % PYTHON)
31 venv_create = " ".join(venv_options)
32
33 if not os.path.exists(VENV_DIR):
34 print u"VirtualEnv creation."
35 shell_exec(venv_create)
36 cleanup()
37 else:
38 print u"VirtualEnv already exists. Nothing to do."
39
40
41def setup_dependances():
42 print u"Deps installation"
43 shell_exec(
44 "%s/bin/pip install -r %s/requirements.txt" %
45 (VENV_DIR, ROOT_DIR)
46 )
47
48
49def cleanup():
50 """
51 Do some cleanup stuff after setup.
52 """
53 for f in os.listdir(ROOT_DIR):
54 if f.startswith('distribute'):
55 os.remove(f)
56
57
58if __name__ == "__main__":
59 setup_venv()
60 setup_dependances()
61 cleanup()