-
Notifications
You must be signed in to change notification settings - Fork 6
/
venv_manager.py
62 lines (41 loc) · 1.43 KB
/
venv_manager.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
# -*- coding: utf-8 -*-
__author__ = 'AminHP'
import os
import sys
from virtualenv import main
def create():
if not os.path.isdir(venv_dir()):
tmp = sys.argv
sys.argv = ['', venv_dir()]
main()
sys.argv = tmp
def remove():
if os.path.isdir(venv_dir()):
command = 'rm -r %s' % venv_dir()
os.system(command)
def activate():
lib_dir = os.path.join(venv_dir(), 'lib/python2.7/site-packages')
sys.path.append(lib_dir)
def deactivate():
sys.path.pop()
def update():
print 'Updating ...'
req_dir = os.path.join(framework_dir(), 'requirements')
pip(['install', '-r', req_dir, '>', '/dev/null'])
def pip(command_list):
pip_cmd = os.path.join(venv_dir(), 'bin/pip')
command = '%s %s' % (pip_cmd, ' '.join(command_list))
os.system(command)
def pyresttest(command_list):
prt_cmd = os.path.join(venv_dir(), 'bin/pyresttest')
command = '%s %s' % (prt_cmd, ' '.join(command_list))
if os.system(command) == 256:
print '** USING GLOBAL PYRESTTEST **'
prt_cmd = '/usr/bin/pyresttest'
command = '%s %s' % (prt_cmd, ' '.join(command_list))
if os.system(command) == 32512:
print '* please install pyresttest:\n> sudo apt-get install python-pycurl\n> sudo pip install pyresttest'
def framework_dir():
return os.path.abspath(os.path.dirname(__file__))
def venv_dir():
return os.path.join(framework_dir(), 'venv')