ó
ÞçULc           @   s¥   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d „ Z	 d d „ Z
 d „  Z d d d „ Z d „  Z d	 e f d
 „  ƒ  YZ d S(   sÅ   
Module for querying information about users.  This mostly asks plugins
for the extra information, and falls back to using a default that should
work on most systems (but by no means all systems.)
iÿÿÿÿN(   t   pluginc         C   s.   |  d k r t j ƒ  }  n  t j d |  g ƒ S(   s"  
    Returns a tuple (quota usage, quota limit).  Returns ``None`` if
    the quota usage is unknown.  If ``dir`` is omitted, the current
    working directory is assumed.  Value returned is in bytes.

    This function implements a plugin interface named
    :ref:`wizard.user.quota`.
    s   wizard.user.quotaN(   t   Nonet   ost   getcwdR    t   hook(   t   dir(    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyt   quota   s    	c         C   s±   |  d k rT t j d ƒ t j d ƒ } | d k	 rH t j d | ƒ | St ƒ  }  n  t j d |  g ƒ } | d k	 ry | Sy t d ƒ j	 ƒ  } Wn t
 j ƒ  } n X|  d | S(   sã  
    Converts a username into an email address to that user.  If you have
    a UID, you will have to convert it into a username first.  If no
    canonical source of information is found, an heuristic approach
    will be used.  If ``name`` is ``None``, the current user will be
    used unless it is root, in which case :func:`operator` is tried
    first to determine the real current user.

    This function implements a plugin interface named
    :ref:`wizard.user.email`.
    s5   wizard.user.email: Determining email for current usert   EMAILs,   wizard.user.email: Used environment email %ss   wizard.user.emails   /etc/mailnamet   @N(   R   t   loggingt   infoR   t   getenvt   operatorR    R   t   opent   readt   sockett   getfqdn(   t   namet	   env_emailt   rt   mailname(    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyt   email   s    c          C   sy   t  j ƒ  }  |  r( t j |  ƒ } | j St j d g  ƒ } | d k	 rJ | St  j d ƒ } | sc d St j	 | ƒ } | j S(   sE  
    Determines the username of the true person who is running this
    program.  If the process's real uid is nonzero, just do a passwd
    lookup; otherwise attempt to figure out the user behind the root
    prompt some other way.

    This function implements a plugin interface named
    :ref:`wizard.user.operator`.
    s   wizard.user.operatort	   SUDO_USERN(
   R   t   getuidt   pwdt   getpwuidt   pw_nameR    R   R   R   t   getpwnam(   t   uidt   pwdentryR   t	   sudo_user(    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyR   :   s    
c         C   s£   |  d k r t j ƒ  }  n  t j j |  ƒ }  | sH t j |  ƒ j } n  t j d |  | g ƒ } | d k	 rp | Sy t	 j
 t j | ƒ ƒ SWn t k
 rž d SXd S(   sí  
    Returns a passwd-like entry (a :class:`Info` object) corresponding
    to the owner of ``path``.  If ``uid`` is specified, ``path`` is used
    solely to determine the filesystem ``uid`` was determined from.  It
    will fall back to the local passwd database, and return ``None``
    if no information is available.  If ``path`` is omitted, it will
    fall back to the current working directory.

    This function implements a plugin interface named
    :ref:`wizard.user.passwd`.
    s   wizard.user.passwdN(   R   R   R   t   patht   realpatht   statt   st_uidR    R   t   Infot   pwentryR   R   t   KeyError(   R   R   R   (    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyt   passwdS   s    c         C   s   t  j t j |  ƒ ƒ S(   sq   
    This user converts a username into a :class:`Info` object using
    *only* the local password database.
    (   R#   R$   R   R   (   R   (    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyt   pwnaml   s    R#   c           B   sY   e  Z d  Z d Z d Z d Z d Z d Z d Z	 e
 d „  ƒ Z d „  Z e d „  ƒ Z RS(   sC  
    Object containing information describing a user.  It is analogous to
    passwd, but has dropped the password field and dedicated the
    ``gecos`` field for real name information.

    .. note::

        If a platform does not support retrieving information about a
        field, it may have the value ``None``.
    c         C   s8   t  |  j |  j |  j |  j j d ƒ d |  j |  j ƒ S(   Nt   ,i    (   R#   R   t   pw_uidt   pw_gidt   pw_gecost   splitt   pw_dirt   pw_shell(   R$   (    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyR$   Š   s    c         C   sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d  |  _ d  S(   N(   R   R   t   gidt   realnamet   homedirt   shellR   t   _email(   t   selfR   R   R/   R0   R1   R2   (    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyt   __init__Ž   s    						c         C   s+   |  j  d k r$ t |  j ƒ |  _  n  |  j  S(   s.   The email of this user, calculated on the fly.N(   R3   R   R   R   (   R4   (    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyR   –   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R/   R0   R1   R2   t   staticmethodR$   R5   t   propertyR   (    (    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyR#   s   s   
	(   R8   t   pkg_resourcesR   R   R	   R   t   wizardR    R   R   R   R   R&   R'   t   objectR#   (    (    (    s9   /afs/athena.mit.edu/contrib/scripts/wizard/wizard/user.pyt   <module>   s   		