Doug Hellmann avatar Doug Hellmann committed 6495c52

make log files group writable; resolves #62

Comments (0)

Files changed (3)

docs/en/history.rst

     but I no longer have a development environment set up for testing
     them, so I do not officially support them.
   - Shortcut initialization if it has run before.
+  - Set hook log file permissions to be group-writable. (:bbissue:`62`
+    reported by :bbuser:`hedgeddown`)
 
 2.10.1
 

tests/test_log_dir.sh

     assertTrue "Log file was not created" "[ -f $WORKON_HOME/logs/hook.log ]"
 }
 
+test_file_permissions() {
+    export VIRTUALENVWRAPPER_LOG_DIR="$WORKON_HOME/logs"
+    mkdir -p "$VIRTUALENVWRAPPER_LOG_DIR"
+    source "$test_dir/../virtualenvwrapper.sh"
+    perms=$(ls -l "$WORKON_HOME/logs/hook.log" | cut -f1 -d' ')
+    #echo $perms
+    assertTrue "Log file permissions are wrong: $perms" "echo $perms | grep '^-rw-rw'"
+}
+
 test_not_set_by_user() {
     unset WORKON_HOME
     unset VIRTUALENVWRAPPER_LOG_DIR

virtualenvwrapper/hook_loader.py

 
 import pkg_resources
 
+class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):
+    """Taken from http://stackoverflow.com/questions/1407474/does-python-logging-handlers-rotatingfilehandler-allow-creation-of-a-group-writa
+    """
+    def _open(self):
+        prevumask = os.umask(0o002)
+        rtv = logging.handlers.RotatingFileHandler._open(self)
+        os.umask(prevumask)
+        return rtv
+
 def main():
     parser = optparse.OptionParser(
         usage='usage: %prog [options] <hook> [<arguments>]',
 
     # Set up logging to a file
     root_logger.setLevel(logging.DEBUG)
-    file_handler = logging.handlers.RotatingFileHandler(
+    file_handler = GroupWriteRotatingFileHandler(
         os.path.expandvars(os.path.join('$VIRTUALENVWRAPPER_LOG_DIR', 'hook.log')),
         maxBytes=10240,
         backupCount=1,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.