title: Checking Linux Directory Permissions with Python
body: <p>I have an interesting scenario that I would like to get some expert advice on implementing.  I have a Python application running on Linux that needs to return a single directory based upon group permissions.</p>
  
  <p>For example, the Linux filesystem looks like this:</p>
  
  <pre><code>/Directory/Apple
  /Directory/Beta
  /Directory/Carotene
  </code></pre>
  
  <p>There is a group in /etc/group for Apple, Beta, and Carotene.  Those group permissions are assigned to each directory (the Apple directory is only viewable/executable by members of the Apple group etc).  A logged in user can only be a member of one group (Apple/Beta/Carotene), and I need to be able to figure out which directory the user has access to without throwing an exception.  I can't use group membership calls inside of Python as the directory structure above is a remotely mounted filesystem.</p>
  
  <p>So to simplify this:  if the user is a member of the Beta group, I need to stat each subdir inside of /Directory and then return only a single path (in this example /Directory/Beta as the user is a member of the group directory).</p>
  
  <p>I am thinking os.stat is a good way of doing this but I would like to see some other implementations if possible.</p>
  
  <p>Thanks in advance!</p>