³ò
°QþNc           @   sn  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k l Z d d k	 l
 Z
 l Z d d k l Z d d k l Z d d k l Z d d k l Z l Z yE d d k Z e i d	 ƒ d d
 k l Z d d k Z d d k Z Wn e j
 o n Xd e i f d „  ƒ  YZ d d „ Z d d „ Z d d „ Z d d „ Z d S(   sF   
    KeepNote Extension 
    backup_tar

    Tar file notebook backup
iÿÿÿÿN(   t   unicode_gtk(   t   NoteBookErrort   get_unique_filename(   t   notebook(   t   tasklib(   t   tarfile(   t	   extensiont   FileChooserDialogs   2.0(   t   gdkt	   Extensionc           B   sM   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z	 RS(   c         C   s    t  i i |  | ƒ | |  _ d S(   s   Initialize extensionN(   R   R	   t   __init__t   app(   t   selfR   (    (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyR
   <   s    c         C   s   d d d f g S(   Nt   keepnotes   >=i    i   i   (   i    i   i   (    (   R   (    (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyt   get_dependsC   s    c            sX   ˆ  i  ˆ d d ‡  ‡ f d †  ƒ ˆ  i  ˆ d d ‡  ‡ f d †  ƒ ˆ  i ˆ d ƒ d S(	   s,   Initialize extension for a particular windows   Backup Notebooks   _Backup Notebook...c            s   ˆ  i  ˆ ˆ i ƒ  ƒ S(    (   t   on_archive_notebookt   get_notebook(   t   w(   R   t   window(    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyt   <lambda>L   s   s   Restore Notebooks   R_estore Notebook...c            s   ˆ  i  ˆ ƒ S(    (   t   on_restore_notebook(   R   (   R   R   (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyR   O   s    su  
            <ui>
            <menubar name="main_menu_bar">
               <menu action="File">
                  <placeholder name="Extensions">
                     <menuitem action="Backup Notebook"/>
                     <menuitem action="Restore Notebook"/>
                  </placeholder>
               </menu>
            </menubar>
            </ui>
            N(   t
   add_actiont   add_ui(   R   R   (    (   R   R   s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyt	   on_add_uiG   s    	c         C   s  | d j o d Sn t d | d t i d d t i d t i f d |  i d d	 ƒ} |  i i d	 ƒ } t i	 i
 | ƒ o; t i | t i	 i | i ƒ  ƒ t i d
 ƒ d d ƒ } n* t i	 i | i ƒ  ƒ t i d
 ƒ d } | i t i	 i | ƒ ƒ t i ƒ  } | i d ƒ | i d ƒ | i | ƒ t i ƒ  } | i d ƒ | i d ƒ | i | ƒ | i ƒ  } | t i j oh | i ƒ  o[ t | i ƒ  ƒ } | i ƒ  d | j o | d 7} n | i d ƒ |  i | | | ƒ Sn# | t i j o | i ƒ  t Sn d S(   s*   Callback from gui for archiving a notebookNs   Backup Notebookt   actiont   buttonst   Cancelt   BackupR   t   persistent_patht   archive_notebook_paths	   -%Y-%m-%ds   .tar.gzt   .u   .tar.gzs   *.tar.gzs   Archives (*.tar.gz)t   *s   All files (*.*)u   .s   Archiving...(   t   NoneR   t   gtkt   FILE_CHOOSER_ACTION_SAVEt   RESPONSE_CANCELt   RESPONSE_OKR   t   get_default_patht   ost   patht   existst   notebooklibR   t   basenamet   get_patht   timet   strftimet   set_current_namet
   FileFiltert   add_patternt   set_namet
   add_filtert   runt   get_filenameR    t   destroyt
   set_statust   archive_notebookt   False(   R   R   R   t   dialogR'   t   filenamet   file_filtert   response(    (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyR   a   sH    					)

c         C   ss  t  d | d t i d d t i d t i f d |  i d d ƒ} t i ƒ  } | i d	 ƒ | i d
 ƒ | i	 | ƒ t i ƒ  } | i d ƒ | i d ƒ | i	 | ƒ | i
 ƒ  } | t i j o- | i ƒ  o  t | i ƒ  ƒ } | i ƒ  n# | t i j o | i ƒ  d Sn t  d | d t i d d t i d t i f d |  i d d ƒ} t i ƒ  } | i d ƒ | i d ƒ | i	 | ƒ t i ƒ  } | i d	 ƒ | i d ƒ | i	 | ƒ t i ƒ  } | i d ƒ | i d ƒ | i	 | ƒ | i
 ƒ  } | t i j oM | i ƒ  o@ t | i ƒ  ƒ } | i ƒ  | i d ƒ |  i | | | ƒ n | t i j o | i ƒ  n d S(   s:   Callback from gui for restoring a notebook from an archives   Chose Archive To RestoreR   R   R   t   RestoreR   R   R   s   *.tar.gzs   Archive (*.tar.gz)R   s   All files (*.*)Ns   Choose New Notebook Namet   Newt   new_notebook_paths   *.nbks   Notebook (*.nbk)s   Archives (*.tar.gz)s   Restoring...(   R   R!   t   FILE_CHOOSER_ACTION_OPENR#   R$   R   R/   R0   R1   R2   R3   R4   R    R5   R"   R6   t   restore_notebook(   R   R   R9   R;   R<   t   archive_filenamet   notebook_filename(    (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyR   ™   sd    					
					
	c   	         s(  ˆ d j o d Sn t i ‡ ‡  f d †  ƒ } | oÝ | i d t i i ˆ  ƒ d | ƒ y; | i ƒ  \ } } } | o
 | ‚ n | i d ƒ t	 SWq$t
 j
 o4 } | i d ƒ | i d | i | | ƒ t Sq$t j
 o- } | i d ƒ | i d | | ƒ t Sq$Xn t ˆ ˆ  d ƒ d S(	   s   Archive a notebookNc            s   t  ˆ  ˆ |  ƒ S(    (   R7   (   t   task(   R   R:   (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyR   è   s    s   Creating archive '%s'...s   Beginning archive...s   Notebook archivedt    s"   Error while archiving notebook:
%ss   unknown error(   R    R   t   Taskt   wait_dialogR&   R'   R*   t   exc_infoR6   t   TrueR   t   errort   msgR8   t	   ExceptionR7   (	   R   R   R:   R   RD   t   tyRJ   t   tracebkt   e(    (   R:   R   s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyR7   á   s0    	
c   	         s)  | o| i  ƒ  t i ‡ ‡  f d †  ƒ } | i d t i i ˆ ƒ d | ƒ y7 | i ƒ  \ } } } | o
 | ‚ n | i d ƒ Wnx t	 j
 o4 } | i d ƒ | i
 d | i | | ƒ d Sn: t j
 o- } | i d ƒ | i
 d | | ƒ d Sn X| i ˆ  ƒ n t ˆ ˆ  t d ƒ d S(	   s   Restore notebookc            s   t  ˆ  ˆ t |  ƒ S(    (   RA   RI   (   RD   (   RB   RC   (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyR     s    s   Restoring notebook from '%s'...s   Opening archive...s   Notebook restoredRE   s   Error restoring notebook:
%sNs   unknown error(   t   close_notebookR   RF   RG   R&   R'   R*   RH   R6   R   RJ   RK   RL   t   open_notebookRA   RI   R    (	   R   RB   RC   R   RD   RM   RJ   RN   RO   (    (   RC   RB   s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyRA     s,    
	
	N(
   t   __name__t
   __module__R
   R   R   R   R   R    R7   RA   (    (    (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyR	   :   s   				8	H+id   c         C   s.   t  |  ƒ | j o d |  | d }  n |  S(   Ns   ...i   (   t   len(   R:   t   maxsize(    (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyt   truncate_filename4  s    c            sm  ˆ  d j o t i ƒ  ‰  n t i i ˆ ƒ o t d ˆ ƒ ‚ n y |  i ƒ  Wn$ t j
 o } t d | ƒ ‚ n Xt	 i
 ˆ d d t	 i ƒ‰ |  i ƒ  } d ‰ x0 t i | ƒ D] \ } } } ˆ t | ƒ 7‰ q¶ Wˆ  i d d ˆ f ƒ d g ‰ ‡  ‡ ‡ ‡ ‡ ‡ f d †  ‰ ˆ | t i i | ƒ ƒ ˆ  i d ƒ ˆ  i d ƒ ˆ i ƒ  ˆ  o ˆ  i ƒ  n d S(   sS   Archive notebook as *.tar.gz

       filename -- filename of archive to create
    s   File '%s' already existss(   Could not save notebook before archivings   w:gzt   formati    t   texts   Archiving %d files...c            s$  ˆ i  |  | t ƒ t i i |  ƒ oS ˆ d c d 7<ˆ  o8 ˆ  i d t |  ƒ f ƒ ˆ  i ˆ d t ˆ ƒ ƒ qy n t i i	 |  ƒ o” x‘ t i
 |  ƒ D]| } ˆ  i ƒ  o' ˆ i ƒ  t i ˆ ƒ t d ƒ ‚ n t i i | ƒ p/ ˆ t i i |  | ƒ t i i | | ƒ ƒ qœ qœ Wn d  S(   Ni    i   t   details   Backup canceled(   t   addR8   R&   R'   t   isfilet   set_messageRV   t   set_percentt   floatt   isdirt   listdirt   abortedt   closet   removeR   t   islinkt   join(   R'   t   arcnamet   f(   RD   t   nfiles2R:   t   nfilest   walkt   archive(    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyRj   [  s     # 
s   Closing archive...RY   RE   N(   s   texts   Closing archive...(   s   detailRE   (   R    R   RF   R&   R'   R(   R   t   saveRL   R   t   opent
   PAX_FORMATR+   Rj   RT   R\   R*   Rb   t   finish(   R   R:   RD   RO   R'   t   roott   dirst   files(    (   RD   Rh   R:   Ri   Rj   Rk   s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyR7   :  s.     	
c      	   C   s¯  | d j o t i ƒ  } n | d j o t d ƒ ‚ n t i d d | ƒ } t i |  d d t i ƒ} | oàt	 i
 i | ƒ p/ t t	 i
 i | ƒ t	 i
 i | d ƒ ƒ } n t d ƒ ‚ yMt | i ƒ  ƒ } | o! | i d d	 t | ƒ f ƒ n x¯ t | ƒ D]¡ \ } } d
 | i j o | i d
 | _ n | oZ | i ƒ  o t d ƒ ‚ n | i d t | i ƒ f ƒ | i | t t | ƒ ƒ ƒ n | i | | ƒ q	Wt	 i | ƒ }	 t	 i
 i | |	 d ƒ }
 | o. | i d ƒ t i |
 | ƒ t	 i | ƒ n Wq¡t j
 o } | ‚ q¡t  j
 o } t d | ƒ ‚ q¡XnQ y) | o | i d ƒ n | i! | ƒ Wn$ t  j
 o } t d | ƒ ‚ n X| i" ƒ  d S(   sà   
    Restores a archived notebook

    filename -- filename of archive
    path     -- name of new notebook
    rename   -- if True, path contains notebook name, otherwise path is
                basedir of new notebook
    RE   s*   Must specify a path for restoring notebooks   /+$s   r:gzRW   s   -tmps   Notebook path already existsRX   s   Restoring %d files...R'   s   Restore canceledRY   i    s   Finishing restore...s,   File writing error while extracting notebooks   Restoring archive...N(   s   texts   Finishing restore...(   s   texts   Restoring archive...(#   R    R   RF   R   t   ret   subR   Rm   Rn   R&   R'   R(   R   t   dirnameR*   t   listt
   getmembersR\   RT   t	   enumeratet   pax_headerst   nameRa   RV   R]   R^   t   extractR`   Re   t   shutilt   movet   rmdirRL   t
   extractallRo   (   R:   R'   t   renameRD   t   tart   tmppatht   memberst   it   memberRr   t   extracted_pathRO   (    (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyRA   ‚  sV    
 !
c            so  t  i i | ƒ o t d | ƒ ‚ n y |  i ƒ  Wn$ t j
 o } t d | ƒ ‚ n Xyè t i | d t i t	 ƒ ‰ |  i
 ƒ  } d ‰ x0 t  i | ƒ D] \ } } } ˆ t | ƒ 7‰ qœ Wd g ‰ t g ‰ ‡  ‡ ‡ ‡ ‡ ‡ f d †  ‰ ˆ | t  i i | ƒ ƒ ˆ i ƒ  ˆ d o t  i | ƒ n ˆ  o ˆ  i ƒ  n Wn$ t j
 o } t d | ƒ ‚ n Xd S(   s´   Archive notebook as *.tar.gz

       filename -- filename of archive to create
       progress -- callback function that takes arguments
                   (percent, filename)
    s   File '%s' already existss(   Could not save notebook before archivingR   i    c            s  t  i i |  ƒ o ˆ i |  | ƒ n t  i i |  ƒ oG ˆ d c d 7<ˆ  o, ˆ  i |  ƒ ˆ  i ˆ d t ˆ ƒ ƒ q n t  i i |  ƒ o x| t  i |  ƒ D]g } ˆ  i	 ƒ  p t
 ˆ d <d  Sn t  i i | ƒ p/ ˆ t  i i |  | ƒ t  i i | | ƒ ƒ q¤ q¤ Wn d  S(   Ni    i   (   R&   R'   R[   t   writeR\   R]   R^   R_   R`   t
   is_runningRI   Rd   Re   (   R'   Rf   Rg   (   RD   Rh   Rj   t   abortRi   Rk   (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyRj   ô  s     # 
s   Error while archiving notebookN(   R&   R'   R(   R   Rl   RL   t   zipfilet   ZipFilet   ZIP_DEFLATEDRI   R+   Rj   RT   R8   R*   Rb   Rc   Ro   (   R   R:   RD   RO   R'   Rp   Rq   Rr   (    (   RD   R‰   Rh   Ri   Rj   Rk   s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pyt   archive_notebook_zipÖ  s0     		
(    t   __doc__t   gettextR&   Rs   R|   t   sysR,   R   R    t   keepnote.notebookR   R   R   R)   R   R   t   keepnote.guiR   R   t   pygtkt   requireR!   R   t	   gtk.gladet   gobjectt   ImportErrorR	   RV   R    R7   RA   R   (    (    (    s–   \\192.168.178.73\Gero\!!!!!!!!!!!!!!! Neue Aufgaben ab 26.02.2022\2 Datenbank portable\KeepNotePortable\App\KeepNote\extensions\backup_tar\__init__.pys   <module>   s4   úHT