ó
¸9—^c           @   sŒ   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d  d l m Z m	 Z	 d  d l
 m Z d  d l m Z d e f d	 „  ƒ  YZ d S(
   iÿÿÿÿN(   t   defaultdict(   t   apps(   t   settings(   t   BaseCommandt   CommandError(   t   models(   t   signalcommandt   Commandc           B   s   e  Z d  Z e d „  ƒ Z RS(   sQ   Prints a list of all files in MEDIA_ROOT that are not referenced in the database.c         O   s™  t  t d ƒ s t d ƒ ‚ n  t ƒ  } x\ t j t j ƒ D]H \ } } } x6 | D]. } | j t j j	 t j j
 | | ƒ ƒ ƒ qP Wq: Wt t ƒ } xT t j ƒ  D]F }	 x= |	 j j D]/ }
 t |
 j t j ƒ r² | |	 j |
 ƒ q² q² WqŸ Wt ƒ  } x€ | D]x }	 |	 j j ƒ  j ƒ  } xZ | D]R } xI | |	 D]= }
 t  | |
 j ƒ } | r,| j t j j	 | j ƒ ƒ q,q,WqWqù W| | } x | D] } | GHq†Wd  S(   Nt
   MEDIA_ROOTs$   MEDIA_ROOT is not set, nothing to do(   t   getattrR   R   t   sett   ost   walkR   t   addt   patht   abspatht   joinR    t   listR   t
   get_modelst   _metat   fieldst
   issubclasst	   __class__R   t	   FileFieldt   appendt   objectst   allt   iteratort   name(   t   selft   argst   optionst   mediat   roott   dirst   filest   ft
   model_dictt   modelt   fieldt
   referencedR   t   objectt   target_filet   not_referenced(    (    sZ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/unreferenced_files.pyt   handle   s,    	"0	+
(   t   __name__t
   __module__t   helpR   R,   (    (    (    sZ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/unreferenced_files.pyR      s   (   R   t   collectionsR    t   django.appsR   t   django.confR   t   django.core.management.baseR   R   t	   django.dbR   t"   django_extensions.management.utilsR   R   (    (    (    sZ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/unreferenced_files.pyt   <module>   s   