forked from treeio/treeio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
77 lines (65 loc) · 2.39 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# encoding: utf-8
# Copyright 2011 Tree.io Limited
# This file is part of Treeio.
# License www.tree.io/license
#!/usr/bin/env python
import sys
import shutil
try:
import virtualenv
except ImportError:
print 'Error: virtualenv module not found. Please install virtualenv (e.g. pip install virtualenv)'
import subprocess
from os import path
PROJECT_ROOT = path.abspath(path.dirname(__file__))
REQUIREMENTS = path.join(PROJECT_ROOT, 'requirements.pip')
VE_ROOT = path.join(PROJECT_ROOT, '.ve')
VE_TIMESTAMP = path.join(VE_ROOT, 'timestamp')
VE_ACTIVATE = path.join(VE_ROOT, 'bin', 'activate_this.py')
envtime = path.exists(VE_ROOT) and path.getmtime(VE_ROOT) or 0
envreqs = path.exists(VE_TIMESTAMP) and path.getmtime(VE_TIMESTAMP) or 0
envspec = path.getmtime(REQUIREMENTS)
def go_to_ve():
# going into ve
if not VE_ROOT in sys.prefix:
if sys.platform == 'win32':
python = path.join(VE_ROOT, 'Scripts', 'python.exe')
else:
python = path.join(VE_ROOT, 'bin', 'python')
try:
retcode = subprocess.call([python, __file__] + sys.argv[1:])
except KeyboardInterrupt:
retcode = 1
sys.exit(retcode)
update_ve = 'update_ve' in sys.argv
if update_ve or envtime < envspec or envreqs < envspec:
if update_ve:
# install ve
if envtime < envspec:
if path.exists(VE_ROOT):
shutil.rmtree(VE_ROOT)
virtualenv.logger = virtualenv.Logger(consumers=[])
virtualenv.create_environment(VE_ROOT, site_packages=True)
go_to_ve()
# check requirements
if update_ve or envreqs < envspec:
import pip
pip.main(initial_args=['install', '-r', REQUIREMENTS, '--upgrade'])
file(VE_TIMESTAMP, 'w').close()
sys.exit(0)
else:
print "VirtualEnv need to be updated"
print "Run ./manage.py update_ve"
sys.exit(1)
go_to_ve()
from django.core.management import execute_manager
import imp
try:
imp.find_module('settings') # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
sys.exit(1)
import settings
if __name__ == "__main__":
execute_manager(settings)