tpl prj
[auf_skeleton_django.git] / deploy.py
1 # -*- coding: utf-8 -*-
2
3 import os
4 import subprocess
5 from pkg_resources import parse_version
6
7 PYTHON = "python2.6"
8 ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
9 VENV_DIR = os.path.join(ROOT_DIR, '.virtualenv')
10
11
12 def 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
22 def 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
41 def 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
49 def 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
58 if __name__ == "__main__":
59 setup_venv()
60 setup_dependances()
61 cleanup()