Skip to content

Commit 6495c52

Browse files
committed
make log files group writable; resolves #62
1 parent 963ea3f commit 6495c52

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

docs/en/history.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ dev
1111
but I no longer have a development environment set up for testing
1212
them, so I do not officially support them.
1313
- Shortcut initialization if it has run before.
14+
- Set hook log file permissions to be group-writable. (:bbissue:`62`
15+
reported by :bbuser:`hedgeddown`)
1416

1517
2.10.1
1618

tests/test_log_dir.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ test_set_by_user() {
1717
assertTrue "Log file was not created" "[ -f $WORKON_HOME/logs/hook.log ]"
1818
}
1919

20+
test_file_permissions() {
21+
export VIRTUALENVWRAPPER_LOG_DIR="$WORKON_HOME/logs"
22+
mkdir -p "$VIRTUALENVWRAPPER_LOG_DIR"
23+
source "$test_dir/../virtualenvwrapper.sh"
24+
perms=$(ls -l "$WORKON_HOME/logs/hook.log" | cut -f1 -d' ')
25+
#echo $perms
26+
assertTrue "Log file permissions are wrong: $perms" "echo $perms | grep '^-rw-rw'"
27+
}
28+
2029
test_not_set_by_user() {
2130
unset WORKON_HOME
2231
unset VIRTUALENVWRAPPER_LOG_DIR

virtualenvwrapper/hook_loader.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515

1616
import pkg_resources
1717

18+
class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):
19+
"""Taken from http://stackoverflow.com/questions/1407474/does-python-logging-handlers-rotatingfilehandler-allow-creation-of-a-group-writa
20+
"""
21+
def _open(self):
22+
prevumask = os.umask(0o002)
23+
rtv = logging.handlers.RotatingFileHandler._open(self)
24+
os.umask(prevumask)
25+
return rtv
26+
1827
def main():
1928
parser = optparse.OptionParser(
2029
usage='usage: %prog [options] <hook> [<arguments>]',
@@ -66,7 +75,7 @@ def main():
6675

6776
# Set up logging to a file
6877
root_logger.setLevel(logging.DEBUG)
69-
file_handler = logging.handlers.RotatingFileHandler(
78+
file_handler = GroupWriteRotatingFileHandler(
7079
os.path.expandvars(os.path.join('$VIRTUALENVWRAPPER_LOG_DIR', 'hook.log')),
7180
maxBytes=10240,
7281
backupCount=1,

0 commit comments

Comments
 (0)