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