~ubuntu-branches/ubuntu/trusty/virtualenvwrapper/trusty-proposed

« back to all changes in this revision

Viewing changes to virtualenvwrapper/user_scripts.py

  • Committer: Bazaar Package Importer
  • Author(s): Jan Dittberner
  • Date: 2011-08-14 19:54:16 UTC
  • mfrom: (1.2.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20110814195416-05rds6ctun2yc69a
Tags: 2.8-1
* New upstream version.
* refresh debian/patches/debianspecific-setup.py.patch
* debian/control: get rid of Build-Depends-Indep
* switch to dh_python2 and dh_sphinxdoc
  - debian/control:
     - remove Build-Depends python-support
     - bump Build-Depends python to 2.6.6-3~
     - bump Build-Depends python-spinx to 1.0.7+dfsg-1~
     - add ${sphinxdoc:Depends} and libjs-sphinxdoc to Depends
     - remove libjs-jquery from Depends
  - debian/rules:
     - add --with python2,sphinxdoc in debian/rules
     - don't dh_link jquery.js
     - don't remove _sources, .doctrees and jquery.js manually
* add japanese sphinx documentation
  - debian/rules: add ja to lang for loop
  - add debian/virtualenvwrapper.doc-base.ja
  - add /usr/share/doc/virtualenvwrapper/ja to debian/virtualenvwrapper.dirs
* debian/rules:
  - replace copies of sphinx's _static directory in ja and es with symlinks
    to en
  - simplify sphinx build and set language
* use upstream sphinx configuration and remove bitbucket usage via
  debian/patches/remove_bitbucket_support.patch
* don't compress .txt files, to enable sphinx doc search

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
import logging
10
10
import os
 
11
import re
11
12
import stat
12
13
import subprocess
 
14
import sys
13
15
 
14
16
import pkg_resources
15
17
 
16
18
log = logging.getLogger(__name__)
17
19
 
 
20
    
 
21
# Are we running under msys
 
22
if sys.platform == 'win32' and os.environ.get('OS') == 'Windows_NT' and os.environ.get('MSYSTEM') == 'MINGW32':
 
23
    is_msys = True
 
24
    script_folder = 'Scripts'
 
25
else:
 
26
    is_msys = False
 
27
    script_folder = 'bin'
 
28
 
18
29
 
19
30
def run_script(script_path, *args):
20
31
    """Execute a script in a subshell.
21
32
    """
22
33
    if os.path.exists(script_path):
23
34
        cmd = [script_path] + list(args)
 
35
        if is_msys:
 
36
            cmd = [get_path(os.environ['MSYS_HOME'],'bin','sh.exe')] + cmd
24
37
        log.debug('running %s', str(cmd))
25
38
        try:
26
39
            return_code = subprocess.call(cmd)
33
46
def run_global(script_name, *args):
34
47
    """Run a script from $VIRTUALENVWRAPPER_HOOK_DIR.
35
48
    """
36
 
    script_path = os.path.expandvars(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', script_name))
 
49
    script_path = get_path('$VIRTUALENVWRAPPER_HOOK_DIR', script_name)
37
50
    run_script(script_path, *args)
38
51
    return
39
52
 
101
114
    :param filename: The name of the file to write.
102
115
    :param comment: The comment to insert into the file.
103
116
    """
104
 
    filename = os.path.expanduser(os.path.expandvars(filename))
 
117
    filename = get_path(filename)
105
118
    if not os.path.exists(filename):
106
119
        log.info('creating %s', filename)
107
120
        f = open(filename, 'w')
122
135
 
123
136
def initialize(args):
124
137
    for filename, comment in GLOBAL_HOOKS:
125
 
        make_hook(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment)
 
138
        make_hook(get_path('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment)
126
139
    return
127
140
 
128
141
 
138
151
    log.debug('pre_mkvirtualenv %s', str(args))
139
152
    envname=args[0]
140
153
    for filename, comment in LOCAL_HOOKS:
141
 
        make_hook(os.path.join('$WORKON_HOME', envname, 'bin', filename), comment)
 
154
        make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
142
155
    run_global('premkvirtualenv', *args)
143
156
    return
144
157
 
155
168
    log.debug('pre_cpvirtualenv %s', str(args))
156
169
    envname=args[0]
157
170
    for filename, comment in LOCAL_HOOKS:
158
 
        make_hook(os.path.join('$WORKON_HOME', envname, 'bin', filename), comment)
 
171
        make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
159
172
    run_global('precpvirtualenv', *args)
160
173
    return
161
174
 
184
197
def pre_activate(args):
185
198
    log.debug('pre_activate')
186
199
    run_global('preactivate', *args)
187
 
    script_path = os.path.expandvars(os.path.join('$WORKON_HOME', args[0], 'bin', 'preactivate'))
 
200
    script_path = get_path('$WORKON_HOME', args[0], script_folder, 'preactivate')
188
201
    run_script(script_path, *args)
189
202
    return
190
203
 
196
209
# Run user-provided scripts
197
210
#
198
211
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate"
199
 
[ -f "$VIRTUAL_ENV/bin/postactivate" ] && source "$VIRTUAL_ENV/bin/postactivate"
 
212
[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate"
200
213
"""
201
214
 
202
215
 
206
219
#
207
220
# Run user-provided scripts
208
221
#
209
 
[ -f "$VIRTUAL_ENV/bin/predeactivate" ] && source "$VIRTUAL_ENV/bin/predeactivate"
 
222
[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate"
210
223
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate"
211
224
"""
212
225
 
227
240
def get_env_details(args):
228
241
    log.debug('get_env_details')
229
242
    run_global('get_env_details', *args)
230
 
    script_path = os.path.expandvars(os.path.join('$WORKON_HOME', args[0], 'bin', 'get_env_details'))
 
243
    script_path = get_path('$WORKON_HOME', args[0], script_folder, 'get_env_details')
231
244
    run_script(script_path, *args)
232
245
    return
 
246
 
 
247
def get_path(*args):
 
248
    '''
 
249
    Get a full path from args.
 
250
    Path separator is determined according to the os and the shell and allow to use is_msys.
 
251
    Variables and user are expanded during the process.
 
252
    '''
 
253
    path = os.path.expanduser(os.path.expandvars(os.path.join(*args)))
 
254
    if is_msys:
 
255
        # MSYS accept unix or Win32 and sometimes it drives to mixed style paths
 
256
        if re.match(r'^/[a-zA-Z](/|^)', path):
 
257
            # msys path could starts with '/c/'-form drive letter
 
258
            path = ''.join((path[1],':',path[2:]))
 
259
        path = path.replace('/', os.sep)
 
260
        
 
261
    return os.path.abspath(path)