obda.net

Default File Permissions for a Directory

Add a comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

You can set the default permissions for all files created in a given directory using POSIX access control lists (ACLs). For example, after executing

user@host:~$ setfacl -d -m u::rwx,g::rwx,o::r-x ~/path/to/example/dir

all new files (and directories, too) in ~/path/to/example/dir will have group write permission enabled. To check the currently effective ACLs, use getfacl.

Redirect STDIN in a Shell Script

Add a comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

If you have a shell script, and want to redirect all input it receives via STDIN to another script or program, use <&0:

#!/bin/zsh
/path/to/another/script.pl --script-args <&0

Finding All Loggers in Python

Add a comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

logging.Logger.manager.loggerDict holds a dictionary of all loggers that have been requested.

>>> import logging
>>> logging.Logger.manager.loggerDict
{}
>>> logging.getLogger('foo')
<logging.Logger object at 0x7f11d4d104d0>
>>> logging.getLogger('bar')
<logging.Logger object at 0x7f11d4cb7ad0>
>>> logging.Logger.manager.loggerDict
{'foo': <logging.Logger object at 0x7f11d4d104d0>,
'bar': <logging.Logger object at 0x7f11d4cb7ad0>}

Found at http://code.activestate.com/lists/python-list/621740/.