Statistics
| Branch: | Tag: | Revision:

root / conf / ci / manage.py @ b216cb77

History | View | Annotate | Download (1.9 kB)

1
#!/usr/bin/env python2.6
2
# -*- coding: utf-8 -*-
3
from os import path
4
import shutil, sys, virtualenv, subprocess
5

    
6
PROJECT_ROOT = path.abspath(path.dirname(__file__))
7
REQUIREMENTS = path.join(PROJECT_ROOT, 'requirements.pip')
8

    
9
VE_ROOT = path.join(PROJECT_ROOT, '.ve')
10
VE_TIMESTAMP = path.join(VE_ROOT, 'timestamp')
11

    
12
envtime = path.exists(VE_ROOT) and path.getmtime(VE_ROOT) or 0
13
envreqs = path.exists(VE_TIMESTAMP) and path.getmtime(VE_TIMESTAMP) or 0
14
envspec = path.getmtime(REQUIREMENTS)
15

    
16
def go_to_ve():
17
    # going into ve
18
    if not sys.prefix == VE_ROOT:
19
        if sys.platform == 'win32':
20
            python = path.join(VE_ROOT, 'Scripts', 'python.exe')
21
        else:
22
            python = path.join(VE_ROOT, 'bin', 'python')
23
            
24
        retcode = subprocess.call([python, __file__] + sys.argv[1:])
25
        sys.exit(retcode)
26

    
27
update_ve = 'update_ve' in sys.argv
28
if update_ve or envtime < envspec or envreqs < envspec:
29
    if update_ve:
30
        # install ve
31
        if envtime < envspec:
32
            if path.exists(VE_ROOT):
33
                shutil.rmtree(VE_ROOT)
34
            virtualenv.logger = virtualenv.Logger(consumers=[])
35
            virtualenv.create_environment(VE_ROOT, site_packages=True)
36

    
37
        go_to_ve()    
38

    
39
        # check requirements
40
        if update_ve or envreqs < envspec:
41
            import pip
42
            pip.main(initial_args=['install', '-r', REQUIREMENTS])
43
            file(VE_TIMESTAMP, 'w').close()
44
        sys.exit(0)
45
    else:
46
        print "VirtualEnv need to be updated"
47
        print "Run ./manage.py update_ve"
48
        sys.exit(1)
49

    
50
go_to_ve()
51

    
52
# run django
53
from django.core.management import execute_manager
54
try:
55
    import settings # Assumed to be in the same directory.
56
except ImportError:
57
    import sys
58
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory")
59
    sys.exit(1)
60

    
61
if __name__ == "__main__":
62
    execute_manager(settings)