
B3IHc           @   s  d  d k  Z  d  d k Z e i i   Z d e d <e d e Z d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d Z	 d d* d     YZ
 g  d  Z d	   Z d
 d d d  Z d   Z d g  d
 d
 g  d d
 d  Z d   Z d   Z d   Z d
 d d d  Z d   Z d   Z d   Z d g  g  d d  Z d
 d  Z d d  Z e d  Z d d  Z d d  Z d d  Z d d d  d! d" d# d$ d% d& g	 Z  e! d' j o e d( d)  GHn d S(+   iNs   eXtended os related scripts.

Changes:
    - 2003/10/08: New userPath function by Greg Brunet
    - 2003/09/25: Added userPath function from Andrei (http://come.to/project5)t   descriptiont   doci   t
   TitleTimerc           B   s,   e  Z d  Z d d d  Z d d d  Z RS(   sB   Display the time left in mm:ss in the title of the console window.i   i    c         C   sN   | |  _  | |  _ d |  _ t i   |  _ |  _ |  i | |  _ | |  _ d  S(   Ni    (   t   totalt   refresht   currentt   timet   alarmt   startt   title(   t   selfR   R   R	   (    (    s   C:\py\_spe\sm\osx.pyt   __init__   s    			t    c         C   s   | o | |  _  n |  i  d |  _  t i   |  i j o t i   |  _ t |  i |  i |  i |  i  |  i   } |  i |  i |  _ t | d  d t i	 | d d  | } |  i
 o |  i
 i |  q t o t i d | d  q | GHn d S(   R   i   i<   t   :i   s   title "t   "N(   R   R   R   t   intR   R   R   t   strt   stringt   zfillR	   t   SetLabelt   displayTitlet   ost   system(   R
   R   t   commentt   secondst   message(    (    s   C:\py\_spe\sm\osx.pyt   tick   s     +,
 N(   t   __name__t
   __module__t   __doc__R   t   NoneR   (    (    (    s   C:\py\_spe\sm\osx.pyR      s   c         C   s`   t  |  d  } | i t  | d   x4 | D], } | | j o t i | d |  q, q, Wd S(   s$   Copy one level of empty directories.t   foldert   /N(   t   listdirt   extendR   t   mkdir(   t   baset   tot   ignoret   baseDirst   dir(    (    s   C:\py\_spe\sm\osx.pyt   copydirs.   s      c         C   sy   t  |  d  } d i g  } | i   D] } | | i   q& ~  } | i   t  | d  } | i |  | i   d  S(   Nt   rs   
t   w(   t   filet   joint	   readlinest   rstript   closet   write(   t   srcPyt   dstPyt   ft   _[1]t   linet   script(    (    s   C:\py\_spe\sm\osx.pyt
   copyPython5   s    6
i    R   c         C   s  t  i |   } y t  i |  Wn n Xt |  } x{| D]s} t  i i |  |  } t  i i | |  }	 y| o6 t  i i |  o# t  i |  }
 t  i |
 |	  n t  i i	 |  o> | p | o+ | |  | j o t
 | |	 | | |  qtnw | o_ t  i i |  d i   } | | j o2 | d j o t | |	  q`t i | |	  qtn t i | |	  Wq= t t  i f j
 o# } d | |	 t |  f GHq= Xq= Wd S(   s  Recursively copy a directory tree using copy2().

    The destination directory CAN ALREADY EXIST.
    Error are reported to standard output.

    If the optional symlinks flag is true, symbolic links in the
    source tree result in symbolic links in the destination tree; if
    it is false, the contents of the files pointed to by symbolic
    links are copied.

    XXX Consider this example code rather than the ultimate tool.

    is   .pys   .pyws   Can't copy %s to %s: %sN(   s   .pys   .pyw(   R   R!   R#   t   lent   pathR-   t   islinkt   readlinkt   symlinkt   isdirt   copytreet   splitextt   lowerR8   t   shutilt   copy2t   IOErrort   errorR   (   t   srct   dstt   symlinkst
   extensionst   excludePrefixFolderst   namest   ext   namet   srcnamet   dstnamet   linktot	   extensiont   why(    (    s   C:\py\_spe\sm\osx.pyR?   =   s4        c         C   sU   t  i |  } g  } |  D]4 } t i i |  d i   | j o | | q q ~ S(   s4   Filters file list by a list of lowercase extensions.i   (   t   smt
   assertListR   R:   R@   RA   (   t   fileListRI   R5   R4   (    (    s   C:\py\_spe\sm\osx.pyt   filterByExtensionf   s    c         C   s  | d j p
 | d j } y t  i |   } Wn g  Sn X| o t t  i i |  } n | i   | p | p | o4 g  }	 | D] }
 |	 t  i i |  |
  q ~	 } n | p | o t t  i i |  } n | o | o g  } t	 |  } xy | D]g } t  i i
 |  } | | j p | o; | |  | j o* | t | d | d | d | d 7} q q Wn g  } | o. | o | | Sqt t  i i
 |  | Sn+ | g  j o | | Sn t | |  | Sd S(   s   Directory listings with options for extension and folder filtering.
    Parameter:
        - extensions: list of file extensions or 'folder' for folders only
        - ...
    R   t   foldersRI   t   absPatht	   recursivei   N(   R   R!   t   mapR:   t   normcaset   sortR-   t   filterR>   R9   t   basenameRV   (   R(   RI   RX   RY   t   excludeFoldersRJ   R[   RW   RU   R5   R4   t
   folderListt   recursiveListRL   R   t
   baseFolder(    (    s   C:\py\_spe\sm\osx.pyR!   k   s<     
 4  c         C   s   t  i |   t i S(   N(   R   t   statt   ST_MTIME(   t   fileName(    (    s   C:\py\_spe\sm\osx.pyt   lastModified   s    c         C   s'   y t  i |   d SWn d Sn Xd  S(   Ni   i    (   R   R#   (   t   x(    (    s   C:\py\_spe\sm\osx.pyR#      s
    c         C   s)   t  i i |  o t |   t |  j S(   N(   R   R:   t   existsRf   (   t   f1t   f2(    (    s   C:\py\_spe\sm\osx.pyt   newer   s    c         C   s)  g  } t  i |   D] } | t  i i |  |  q ~ } g  } | D]P } t  i i |  o6 | p# t  i i |  d i   | j o | | qD qD ~ } | oI xF | D]: }  t  i i |   o! | i t |  | d |   q q Wn | p1 g  }	 | D] }
 |	 t  i i	 |
  q ~	 } n | S(   sP   List recursively all files with a certain extension and limited recursion depth.ii   (
   R   R!   R:   R-   R>   R@   RA   R"   t   listdirRR^   (   R   t	   recursionRI   t   absoluteR5   R,   t   filest   _[2]t   resultt   _[3]Rg   (    (    s   C:\py\_spe\sm\osx.pyRl      s    9%? ) 1c         C   sA   t  i i |   } t i | d d  } | d | d | d f S(   s$   Splits into path,basename,extension.i   t   .i    (   R   R:   t   splitR   (   R4   t   st   t(    (    s   C:\py\_spe\sm\osx.pyt	   pathSplit   s    c         C   s%   t  i i |   i d d  i d  S(   s   Splits its directory in a list of all subdirectories.

    Example:
        >>> dirSplit('d:\hello\world\readme.txt')
        ['d:', 'hello', 'world']
    s   \R    (   R   R:   t   dirnamet   replaceRt   (   R4   (    (    s   C:\py\_spe\sm\osx.pyt   dirSplit   s    c         C   s    t  o t i d |   n d S(   s$   Set the title of the console window.s   title N(   R   R   R   (   Rv   (    (    s   C:\py\_spe\sm\osx.pyR	      s     s   \c   	      C   s#  g  } t  i |   D] } | t  i i |  |  q ~ } |  g  } | D]p } t  i i |  oW t  i i |  | j p  t  i i |  t |   | j o | t | | | |  qG qG ~ g  } | D]P } t  i i |  o6 | p# t  i i |  d i	   | j o | | q q ~ f S(   Ni   (
   R   R!   R:   R-   R>   R^   R9   t   treeDirR@   RA   (	   R:   RI   R&   t   ignorePathPrefixR5   Rg   R(   Rp   Rr   (    (    s   C:\py\_spe\sm\osx.pyR{      s    9,D%c         C   s3   y t  i |   Wn | o d G|  GHq/ n Xd S(   s:   Tries to remove a directory tree, otherwise print warning.s    - Can't remove pathN(   RB   t   rmtree(   t   pt   output(    (    s   C:\py\_spe\sm\osx.pyR}      s
      c      
   C   s   y@ t  i i d  } t  i i |  o t  i i | |   Sn Wn n XxS d D]K } y; t  i | } t  i i |  o t  i i | |   Sn WqQ qQ XqQ Wt  i i t  i i t  i i t   |   S(   s#   'safer' function to find user path.t   ~t   HOMEt   USERPROFILEt   TMP(   s   HOMER   R   (	   R   R:   t
   expanduserR>   R-   t   environRx   t   abspatht   __file__(   Rx   R:   t   evar(    (    s   C:\py\_spe\sm\osx.pyt   userPath   s     c      
   C   s   d   } d i  g  } |  D]7 } | d i  g  } | D] } | | |  q4 ~  q ~  } | i d d  i d d  } d | } | i d	 d
  } d | } | o d | } n t i |  d S(   s   Start a list of commands in the terminal window.
    Each command is a list of program name, parameters.
    Handles the quoting properly through shell, applescript and shell again.
    c         S   sE   t  |  t  o |  d Sn |  i   o |  Sn d |  i d d  S(   s   Adjust a parameter for the shell.
        Adds single quotes,
        unless the parameter consists of letters only
        (to make shell builtins work)
        or if the parameter is a list
        (to flag that it already is list a parameters).
        i    s   '%s't   's   '\''(   t
   isinstancet   listt   isalphaRy   (   t	   parameter(    (    s   C:\py\_spe\sm\osx.pyt   adjustParameter   s
      t   ;t    s   \s   \\R   s   \"s-   tell application "Terminal" to do script "%s"R   s   '\''s   osascript -e '%s's7   osascript -e 'tell application "Terminal" to activate';N(   R-   Ry   R   t   popen(   t   commandListt   activateFlagR   R5   t   commandRp   R   (    (    s   C:\py\_spe\sm\osx.pyt   startAppleScript   s    	G

s   Python.Filec         C   s   y? d d  k  } t |  d | |  f } | i | i |  } Wn n Xy= | d | i | d f GH| i | d | i | d  d SWn d  Sn Xd  S(   Nis   %s\shell\%sR   s    "%1"i   (   t   _winregt   reloadt	   CreateKeyt   HKEY_CLASSES_ROOTt   REG_SZt   SetValueR   (   t   labelt   actiont   fileTypeR   t   key(    (    s   C:\py\_spe\sm\osx.pyt   registerFileCreate  s    
c         C   sG   d d k  } d t i i | i d  | f } t d |  d | d |  S(   s   action is a python fileiNs	   "%s" "%s"s   pythonw.exeR   R   R   (   t   sysR   R:   R-   t   exec_prefixR   (   R   R   R   R   (    (    s   C:\py\_spe\sm\osx.pyt
   registerPy#  s    "c      
   C   sx   yA d d  k  } t |  d | |  f } | i | i | d  Wn n Xy | i | i |  d SWn d  Sn Xd  S(   Nis   %s\shell\%ss   \commandi   (   R   R   t	   DeleteKeyR   R   (   R   R   R   R   (    (    s   C:\py\_spe\sm\osx.pyt   registerFileDelete)  s    
R    t   <t   >R   t   |t   ?R   t   *t   __main__s   c:/tempt   PACK(    ("   R   RS   t   INFOt   copyR   R   RB   R   Rc   R   R   R)   R8   R   R?   RV   R!   Rf   R#   Rk   Rl   Rw   Rz   R	   R{   R}   R   t   TrueR   R   R   R   t   NOT_FILE_CHARSR   (    (    (    s   C:\py\_spe\sm\osx.pys   <module>   s<   
<	)	$							
*!