Ñò
ëh°Xc           @   sÔ   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 l Z d  d k l	 Z	 d  d k
 l Z d  d k
 l Z d  d k
 l Z d  d k
 l Z d  d k
 l Z d	 „  Z d
 „  Z g  d „ Z d S(   iÿÿÿÿN(   t   Popent   PIPE(   t   gethostname(   t   bcol(   t	   calcWidth(   t   getCols(   t   domainExists(   t
   userExistsc         C   sn   d d d d d  d! d" d# d$ d% d& d' g } x= | D]5 } |  i  ƒ  i | d i  ƒ  ƒ d j p	 | d Sq1 Wt S((   Ns   Extracting tarballs   Extracting data from backup..s   Extracting Domains+   Extracting domain information from backup..s   Generating Accounts   Generating cPanel account..s   Restoring MySQL databasess   Restoring MySQL databases..s   Restoring Mailman listss   Restoring Mailman lists..s   Restoring Mailman Archivess   Restoring Mailman archives..s   Restoring Domainss   Restoring domains..s   Rebuilding Apache Confs&   Rebuilding Apache configuration file..s   Restoring Homedirs   Restoring home directory..s   Restoring Mail filess   Restoring mail files..s   Restoring Dns Zoness   Restoring DNS zones..s   Account Restore Completes   Account restore complete..i    iÿÿÿÿi   (   s   Extracting tarballs   Extracting data from backup..(   s   Extracting Domains+   Extracting domain information from backup..(   s   Generating Accounts   Generating cPanel account..(   s   Restoring MySQL databasess   Restoring MySQL databases..(   s   Restoring Mailman listss   Restoring Mailman lists..(   s   Restoring Mailman Archivess   Restoring Mailman archives..(   s   Restoring Domainss   Restoring domains..(   s   Rebuilding Apache Confs&   Rebuilding Apache configuration file..(   s   Restoring Homedirs   Restoring home directory..(   s   Restoring Mail filess   Restoring mail files..(   s   Restoring Dns Zoness   Restoring DNS zones..(   s   Account Restore Completes   Account restore complete..(   t   lowert   findt   False(   t   linet   stepst   step(    (    s%   /root/bin/ikeamodules/ikea/restore.pyt   restoreStatus   s"    	 &c         C   s™   g  } |  i  p | i d ƒ n xI |  i d D]: } d  } t | ƒ } | o | i d | | f ƒ q/ q/ Wt |  i ƒ o | i d |  i ƒ n | S(   Nsp   No downloaded backup file found. If you downloaded the file previously, please use /scripts/restorepkg manually.t   domainss=   The domain %s already exists on the server and is owned by %ss(   The user %s already exists on the server(   t   dledfilet   appendt   infot   NoneR   R   t   username(   t   acctt   errorst   domaint   domainowner(    (    s%   /root/bin/ikeamodules/ikea/restore.pyt   preRestoreCheck#   s    
 c      
   C   s½  t  ƒ  } d } Ht i d i | d ƒ t i GHt | d d ƒ } d i | d ƒ d i | d ƒ GHt i d	 ƒ } xC|  D];} t | ƒ } t i	 d
 | i
 d t i } t i | i d t i d | }	 t | ƒ d |	 }
 t |
 ƒ t | i d |
 ƒ ƒ } t | ƒ d j op t i d | d t i } t | ƒ t | i d | ƒ ƒ } |
 i | d | ƒ | i | d | ƒ GHqz n d | i } t i d t i } t | ƒ t | i d | ƒ ƒ } |
 i | d | ƒ | i | d | ƒ GHt i d | t i } t | ƒ t | i d | ƒ ƒ } |
 i | d | ƒ | i | d | ƒ GHt i i ƒ  t i d ƒ y*t | i ƒ  d t d t ƒ} g  } xÕ t oÍ | i i ƒ  } | i | ƒ | d j o | i ƒ  d  j o Pn t | ƒ } | o: t i | t i } t | ƒ t | i d | ƒ ƒ } n |
 i | d | ƒ | i | d | ƒ d Gt i i ƒ  qžWt  | i
 ƒ oy t! | i d ƒ oe t i	 d t i } t | ƒ t | i d | ƒ ƒ } |
 i | d | ƒ | i | d | ƒ GHn¢ t" | i
 d d ƒ } | i# t$ i% i& | ƒ ƒ | i' ƒ  t i( d | i
 t i } t | ƒ t | i d | ƒ ƒ } |
 i | d | ƒ | i | d | ƒ GHWn
 ‚  n X| d 7} qz Wd  S(   Ni   s   ___Restoring backupst   _i    iD   s   #  Primary Domaini    t   Statuss   \x1B\[[^A-Za-z]*[A-Za-z]t   (t   )t   primarydomaint    s   . t    s   Skipped s   /scripts/restorepkg %ss   Starting restore processs   Running command: i   t   stdoutt   stderrs   s   Account restore completed.s   .logt   as;   Account restore failed, consult %s.log for more information()   R   R   t   HEADERt   ljustt   ENDCR   t   ret   compileR   t   OKGREENR   R   t   strt   lent   subt   WARNINGR   t   OKBLUEt   sysR!   t   flusht   timet   sleepR    t   splitR   t   Truet   readlineR   t   pollR   R   R   R   t   opent   writet   ost   linesept   joint   closet   FAIL(   t   acctst   backupst   columnst   countt   colst   aansiR   R   t   userR   t   c1t   a1t   c2t   a2t   cmdt   pt   logt   ot   stt   file(    (    s%   /root/bin/ikeamodules/ikea/restore.pyt   restoreBackups7   sp    	# #""+"+"+   &.$"/
"/(   R'   R9   R/   t   globR1   t
   subprocessR    R   t   socketR   t   helpersR   R   R   R   R   R   R   RO   (    (    (    s%   /root/bin/ikeamodules/ikea/restore.pyt   <module>   s   		