File tree Expand file tree Collapse file tree 7 files changed +27
-41
lines changed Expand file tree Collapse file tree 7 files changed +27
-41
lines changed Original file line number Diff line number Diff line change 8
8
mode. (:bbuser: `upsuper `)
9
9
- Add ``--help `` option to ``mkproject ``.
10
10
- Add ``--help `` option to ``workon ``.
11
+ - Turn off logging from the hook loader by default, and replace
12
+ ``VIRTUALENVWRAPPER_LOG_DIR `` environment variable with
13
+ ``VIRTUALENVWRAPPER_LOG_FILE ``. The rotating log behavior remains
14
+ the same. The motivation for this change is the race condition
15
+ caused by that rotating behavior, especially when the wrappers are
16
+ being used by users with different permissions and
17
+ umasks. (:bbissue: `152 `)
11
18
12
19
3.6.1
13
20
Original file line number Diff line number Diff line change @@ -220,14 +220,14 @@ default is ``$WORKON_HOME``.
220
220
221
221
* :ref: `scripts `
222
222
223
- .. _variable-VIRTUALENVWRAPPER_LOG_DIR :
223
+ .. _variable-VIRTUALENVWRAPPER_LOG_FILE :
224
224
225
225
Location of Hook Logs
226
226
---------------------
227
227
228
- The variable ``VIRTUALENVWRAPPER_LOG_DIR `` tells virtualenvwrapper
228
+ The variable ``VIRTUALENVWRAPPER_LOG_FILE `` tells virtualenvwrapper
229
229
where the logs for the hook loader should be written. The default is
230
- `` $WORKON_HOME `` .
230
+ to not log from the hooks .
231
231
232
232
.. _variable-VIRTUALENVWRAPPER_VIRTUALENV :
233
233
Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ test_virtualenvwrapper_initialize() {
26
26
assertTrue " Global $WORKON_HOME /$hook was not created" " [ -f $WORKON_HOME /$hook ]"
27
27
assertTrue " Global $WORKON_HOME /$hook is not executable" " [ -x $WORKON_HOME /$hook ]"
28
28
done
29
- assertTrue " Log file was not created" " [ -f $WORKON_HOME /hook.log ]"
30
29
export pre_test_dir=$( cd " $test_dir " ; pwd)
31
30
echo " echo GLOBAL initialize >> \" $pre_test_dir /catch_output\" " >> " $WORKON_HOME /initialize"
32
31
virtualenvwrapper_initialize
Original file line number Diff line number Diff line change @@ -8,27 +8,25 @@ setUp () {
8
8
}
9
9
10
10
test_set_by_user () {
11
- export VIRTUALENVWRAPPER_LOG_DIR=" $WORKON_HOME /logs"
12
- mkdir -p " $VIRTUALENVWRAPPER_LOG_DIR "
11
+ export VIRTUALENVWRAPPER_LOG_FILE=" $WORKON_HOME /hooks.log"
13
12
source " $test_dir /../virtualenvwrapper.sh"
14
- assertTrue " Log file was not created" " [ -f $WORKON_HOME /logs/hook.log ]"
13
+ assertTrue " Log file was not created" " [ -f $VIRTUALENVWRAPPER_LOG_FILE ]"
15
14
}
16
15
17
16
test_file_permissions () {
18
- export VIRTUALENVWRAPPER_LOG_DIR=" $WORKON_HOME /logs"
19
- mkdir -p " $VIRTUALENVWRAPPER_LOG_DIR "
17
+ export VIRTUALENVWRAPPER_LOG_FILE=" $WORKON_HOME /hooks.log"
20
18
source " $test_dir /../virtualenvwrapper.sh"
21
- perms=$( ls -l " $WORKON_HOME /logs/hook.log " | cut -f1 -d' ' )
19
+ perms=$( ls -l " $VIRTUALENVWRAPPER_LOG_FILE " | cut -f1 -d' ' )
22
20
# echo $perms
23
21
assertTrue " Log file permissions are wrong: $perms " " echo $perms | grep '^-rw-rw'"
24
22
}
25
23
26
24
test_not_set_by_user () {
27
25
unset WORKON_HOME
28
- unset VIRTUALENVWRAPPER_LOG_DIR
26
+ unset VIRTUALENVWRAPPER_LOG_FILE
29
27
unset VIRTUALENVWRAPPER_HOOK_DIR
30
28
source " $test_dir /../virtualenvwrapper.sh"
31
- assertSame " $WORKON_HOME " " $VIRTUALENVWRAPPER_LOG_DIR "
29
+ assertSame " " " $VIRTUALENVWRAPPER_LOG_FILE "
32
30
}
33
31
34
32
. " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -64,11 +64,4 @@ test_virtualenvwrapper_run_hook_permissions() {
64
64
assertSame " Errno 13] Permission denied" " $error "
65
65
}
66
66
67
- test_virtualenvwrapper_run_hook_without_log_dir () {
68
- old_log_dir=" $VIRTUALENVWRAPPER_LOG_DIR "
69
- unset VIRTUALENVWRAPPER_LOG_DIR
70
- assertFalse " virtualenvwrapper_run_hook initialize"
71
- export VIRTUALENVWRAPPER_LOG_DIR=" $old_log_dir "
72
- }
73
-
74
67
. " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -202,12 +202,6 @@ function virtualenvwrapper_run_hook {
202
202
203
203
hook_script=" $( virtualenvwrapper_tempfile ${1} -hook) " || return 1
204
204
205
- if [ -z " $VIRTUALENVWRAPPER_LOG_DIR " ]
206
- then
207
- echo " ERROR: VIRTUALENVWRAPPER_LOG_DIR is not set." 1>&2
208
- command \r m -f " $hook_script "
209
- return 1
210
- fi
211
205
" $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script " $hook_script " " $@ "
212
206
result=$?
213
207
@@ -286,12 +280,6 @@ function virtualenvwrapper_initialize {
286
280
export VIRTUALENVWRAPPER_HOOK_DIR=" $WORKON_HOME "
287
281
fi
288
282
289
- # Set the location of the hook script logs
290
- if [ " $VIRTUALENVWRAPPER_LOG_DIR " = " " ]
291
- then
292
- export VIRTUALENVWRAPPER_LOG_DIR=" $WORKON_HOME "
293
- fi
294
-
295
283
virtualenvwrapper_run_hook " initialize"
296
284
297
285
virtualenvwrapper_setup_tab_completion
Original file line number Diff line number Diff line change @@ -85,16 +85,17 @@ def main():
85
85
root_logger = logging .getLogger ('' )
86
86
87
87
# Set up logging to a file
88
- root_logger .setLevel (logging .DEBUG )
89
- file_handler = GroupWriteRotatingFileHandler (
90
- os .path .expandvars (os .path .join ('$VIRTUALENVWRAPPER_LOG_DIR' ,
91
- 'hook.log' )),
92
- maxBytes = 10240 ,
93
- backupCount = 1 ,
94
- )
95
- formatter = logging .Formatter (LOG_FORMAT )
96
- file_handler .setFormatter (formatter )
97
- root_logger .addHandler (file_handler )
88
+ logfile = os .environ .get ('VIRTUALENVWRAPPER_LOG_FILE' )
89
+ if logfile :
90
+ root_logger .setLevel (logging .DEBUG )
91
+ file_handler = GroupWriteRotatingFileHandler (
92
+ logfile ,
93
+ maxBytes = 10240 ,
94
+ backupCount = 1 ,
95
+ )
96
+ formatter = logging .Formatter (LOG_FORMAT )
97
+ file_handler .setFormatter (formatter )
98
+ root_logger .addHandler (file_handler )
98
99
99
100
# Send higher-level messages to the console, too
100
101
console = logging .StreamHandler ()
You can’t perform that action at this time.
0 commit comments