mò
d{£>c           @   s¥  d  Z  d d d !Z d d d !Z d d d !Z d k Z d k Z d k Z d k Z d k	 l
 Z
 d	 k l Z d
 k l Z d g a d g a g  a g  a d d d d g a d g a d d d d d d d d d d d d d d d d d  d! d" g a d# „  Z d$ „  Z d% „  Z d& „  Z d' „  Z d( „  Z d) „  Z g  a d* d* d d* d* d* d* d* d* d* d d+ „ Z  d* d* d d* d* d* d* d* d* d* d, „
 Z! d- „  Z" d. „  Z# d/ „  Z$ d S(0   s4  
$RCSfile: ExternalFileBatch.py,v $

A Factory for creating batches of ExternalFile instances in one go.
This class can be subclassed so that other kinds of similar objects
can be created in a batch.  cf. CVSFile.CVSFileBatch

Author: <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
Release: 1.2
s	   $Name:  $i   iþÿÿÿs   $Date: 2003/04/21 01:52:57 $s   $Revision: 1.7 $i
   N(   s   MessageDialog(   s   BadRequestException(   s   addExternalFilet   CVSt   .t   @t   _t   #t   ~t   %t   :t   !t   `t   ^t   *t   =t   +t   |s   \t   /t   <t   >t   ?t   [t   ]t   {t   }c         C   s   d i  t ƒ S(   Nt    (   t   joint   omittedDirNames(   t   folder(    (    tM   /home2/kennisonb/webapps/zope/Zope/Products/ExternalFile/ExternalFileBatch.pyt   omittedDirNamesAsString5   s    c         C   s   d i  t ƒ S(   NR   (   R   t   omittedDirPrefixes(   R   (    (    R   t   omittedDirPrefixesAsString7   s    c         C   s   d i  t ƒ S(   NR   (   R   t   omittedDirSuffixes(   R   (    (    R   t   omittedDirSuffixesAsString9   s    c         C   s   d i  t ƒ S(   NR   (   R   t   omittedFileNames(   R   (    (    R   t   omittedFileNamesAsString;   s    c         C   s   d i  t ƒ S(   NR   (   R   t   omittedFilePrefixes(   R   (    (    R   t   omittedFilePrefixesAsString=   s    c         C   s   d i  t ƒ S(   NR   (   R   t   omittedFileSuffixes(   R   (    (    R   t   omittedFileSuffixesAsString?   s    c         C   s   d i  t ƒ S(   NR   (   R   t   illegalChars(   R   (    (    R   t   illegalCharsAsStringA   s    t    c         C   s…   d } y2 | |  i | | | | | | | | |	 |
 ƒ
 } Wn% t j
 o } | t | ƒ } n Xt d d d | i d d ƒ d d ƒ S(
   sg   
    Factory method to create a batch of instances of ExternalFile,
    called from GUI in the ZMI
    s,   <h2>External File Batch Create Results:</h2>t   titlet   resultst   messages   
s   <br/>t   actiont   manage_mainN(   R+   R   t   manage_addBatcht
   target_dirt   basedirt	   recursiveR'   t   dirNamest   dirPrefixest   dirSuffixest	   fileNamest   filePrefixest   fileSuffixest	   Exceptiont   et   strt   MessageDialogt   replace(   R   R0   R1   R2   R'   R3   R4   R5   R6   R7   R8   t   REQUESTR+   R:   (    (    R   t   manage_addBatchViaGuiK   s     			c         C   s™  | p d } t | ƒ ‚ n t i i | | ƒ } | p( t i i | ƒ p t i i	 | ƒ o d | } t | ƒ ‚ n g  a
 t i | ƒ a t i | ƒ a t i | ƒ a t i | ƒ a t i |	 ƒ a t i |
 ƒ a y… | o t i i | t |  ƒ na t | d „ t i | ƒ ƒ } t  | ƒ d j o t
 i! d ƒ n x | D] } t# |  | ƒ qIWWn( t$ j
 o } t
 i! t& | ƒ ƒ n Xd i t
 ƒ S(   sˆ   
    Factory method to actually create a batch of instances of
    ExternalFile.  This is designed to be called from PythonScripts.
    s;   ERROR: You must specify a source directory.
No action takens\   
        ERROR: directory ''%s'' does not exist or is not readable.
        No action taken.c         C   s   t  i i | |  ƒ S(   N(   t   ost   pathR   t   dirt   f(   RC   RB   (    (    R   t   <lambda>Š   s    i    s   No files found.s   
N('   R0   R,   R9   R@   RA   R   R1   t   dirnamet   existst   isdirt   messagest   stringt   splitR3   R   R4   R   R5   R   R6   R!   R7   R#   R8   R%   R2   t   walkt
   nodeactionR   t   mapt   listdirt   filelistt   lent   appendt   filepatht   createObjectFromFilet   OSErrorR:   R;   (   R   R0   R1   R2   R'   R3   R4   R5   R6   R7   R8   R,   RE   R:   RR   RO   (    (    R   R/   b   sF     0
        c   
      C   sT  t  i i | ƒ t j o t i d | d ƒ d Sn g  g  } } xž | D]– } t  i i | | ƒ } t t d „ | ƒ } t  i i | ƒ o  | i t  i i | | ƒ ƒ n t  i i | ƒ o  | i t  i i | | ƒ ƒ qJ qJ Wt i d | t | ƒ t | ƒ f ƒ g  | (x | D] }	 t |  |	 ƒ qWx | D] } t |  | | ƒ q6Wd S(   sa   
    This method is called at every node of the file tree to create
    objects and folders.
    s   Skipping directory s    ...matches omitted nameNc         C   s
   |  | j S(   N(   t   xt   baddies(   RU   RV   (    (    R   RD   ©   s    s   Processing %s files %s dirs %s(   R@   RA   t   basenameRE   R   RH   RQ   t   filest   dirsRO   RC   R   t   fft   filterR'   R:   t   isfileRG   RP   RR   RS   R   t   subdirt   createFolderFromDirectory(
   R   RE   RO   RX   RY   R]   R:   RZ   RC   RR   (    (    R   RL   ˜   s0          $&  c         C   s
  t  t i i | ƒ ƒ } x8 t D]0 } | | j o t i	 d | d ƒ d Sq q WxB t
 D]: } | t | ƒ  | j o t i	 d | d ƒ d SqZ qZ WxF t D]> } | d t | ƒ | j o t i	 d | d ƒ d SqŸ qŸ Wt i i | ƒ o t i	 d | d ƒ d Sn t i i | ƒ p t i	 d | d	 ƒ d Sn y9 t |  | d
 d
 | d
 d ƒ t i	 d | d | ƒ Wn‰ t j
 o( } t i	 d | d t  | ƒ ƒ nW t j
 oJ t i ƒ  d i d ƒ d j o t i	 d | d | ƒ qt ‚ n Xd S(   s8   Factory to create objects from files in the file system.s   Skipping file: s    ...matches omitted name Ns    ...matches omitted prefixiÿÿÿÿs    ...matches omitted suffixs
   Skipping: s)    ...because it is a directory, not a files    ...not regular fileR)   s   created object instance: s    pointing to file: s    ...i   s   already in uses    ...duplicate Zope ID (   R;   R@   RA   RW   RR   t   fileidR!   t   nameRH   RQ   R#   t   prefixRP   R%   t   suffixRG   R\   t	   addObjectR   t   NoneR9   R:   t   BadRequestExceptiont   syst   exc_infot   find(   R   RR   R`   Ra   Rb   R:   R_   (    (    R   RS   ½   sH            # c         C   sï  t  t i i | ƒ ƒ } t  t i i | | ƒ ƒ } | t	 j o t
 i d | d ƒ d Sn xB t D]: } | t | ƒ  | j o t
 i d | d ƒ d Sqd qd WxF t D]> } | d t t ƒ t j o t
 i d | d ƒ d Sq© q© WyU |  i i d | d	 | ƒ t
 i d
 | d | ƒ t i i | t t |  | ƒ ƒ Wn¨ t j
 o( } t
 i d | d t  | ƒ ƒ nv t j
 oi t i ƒ  d i d ƒ d j o< t
 i d | d | ƒ t i i | t t |  | ƒ ƒ qët ‚ n Xd S(   sS   
    Factory for creating Zope folders from directories in the file
    system
    s   Skipping directory s    ...matches omitted nameNs   Skipping directory: s    ...matches omitted prefixiÿÿÿÿs    ...matches omitted suffixt   idR*   s   created Zope Folder instance: s    from directory s    ...i   s   already in uses    ...duplicate Zope ID (   R;   R@   RA   RW   R]   RE   R   t	   parentdirt   fullpathR   RH   RQ   R   Ra   RP   R   Rb   R   t   manage_addProductt   manage_addFolderRK   RL   t   getattrR9   R:   Re   Rf   Rg   Rh   (   R   Rj   R]   R:   Ra   RE   Rk   (    (    R   R^   ò   s@           
## #(%   t   __doc__t
   __cvstag__t   __date__t   __version__t   os.pathR@   RI   Rf   t	   tracebackt   GlobalsR<   t   OFS.ObjectManagerRe   t   ExternalFilet   addExternalFileRc   R   R   R   R!   R#   R%   R'   R   R   R    R"   R$   R&   R(   RH   Rd   R?   R/   RL   RS   R^   (   RL   R(   Re   R   R?   Rp   R$   Rr   Rc   RI   R&   Rf   R"   R<   R    R   RS   R/   R^   Rt   Rq   R@   (    (    R   R   
   s6   $			?							*'6	%	5