ó
‚•oTc           @€  s¡  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m	 Z	 d  d l
 Z
 d  d l Z
 d  d l m Z m Z d  d l m Z d  d l m Z d  d l m Z y" d  d l Z e j j d ƒ Z Wn e k
 rõ e Z n XyB d  d l Z e j ƒ   e j d	 ƒ d  d l Z Wd QXe Z  Wn e Z  n Xd
 „  Z! i e! d ƒ d 6e! d ƒ d 6e! d ƒ d 6e! d ƒ d 6e! d ƒ d 6Z" d a$ e a% d „  Z& d „  Z' d „  Z( e d d „ Z) d „  Z* d d „ Z+ d d „ Z, e rgd a- e j j d ƒ r"e j. j/ d ƒ Z0 n9 e j j d ƒ rIe j. j/ d ƒ Z0 n e j. j1 d ƒ Z0 d „  Z2 n  e  re a3 d  „  Z4 n  d! „  Z5 d" „  Z6 e d# „ Z7 d S($   iÿÿÿÿ(   t   with_statementN(   t   Thread(   t   unicodert   latin1(   t   NOTIFY_KEYS(   t   GNTPRegister(   t   GrowlNotifiers<   /Library/PreferencePanes/Growl.prefPane/Contents/MacOS/Growlt   errorc         C€  s   |  S(   N(    (   t   x(    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyt   <lambda>7   s    s   Startup/Shutdownt   startups	   Added NZBt   downloads   Post-processing startedt   pps   Job finishedt   completes   Other Messagest   otherc          C€  s°   t  j j t  j j t j d ƒ d ƒ }  t  j j |  ƒ sT t  j j t j d ƒ }  n  t  j j |  ƒ r¦ t j sx t j r t |  d ƒ } | j	 ƒ  }  | j
 q¬ d }  n d  }  |  S(   Nt   iconss   sabnzbd.icot   rbs6   http://sabnzbdplus.sourceforge.net/version/sabnzbd.ico(   t   ost   patht   joint   sabnzbdt   DIR_PROGt   isfilet   WIN32t   DARWINt   opent   readt   closet   None(   t   icont   fp(    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyt   get_iconH   s    '
	c           C€  s
   t  a d  S(   N(   t   Falset
   _GROWL_REG(    (    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyt   change_valueZ   s    c           C€  s
   t  t ƒ S(   N(   t   boolt   _HAVE_NTFOSD(    (    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyt   have_ntfosdb   s    c         C€  s½  g  } | t  j j ƒ  k s! | r—| r~ | j d ƒ d k } | j d ƒ d k } | j d ƒ d k } | j d ƒ px d  }	 n< t  j j ƒ  } t  j j ƒ  } t  j j ƒ  } t  j j ƒ  }	 t  j	 rå | rå | j
 t |  | | ƒ ƒ n  | rlt r|	 rt |  | | ƒ S| r-| j
 t |  | | | ƒ ƒ ql| j
 d ƒ t d t d |  | | f ƒ j ƒ  t j d	 ƒ n  | r—t ƒ  r—| j
 t |  | ƒ ƒ q—n  d
 j g  | D] }
 |
 r¤|
 ^ q¤ƒ S(   Nt   ncenter_enablet   truet   ntfosd_enablet   growl_enablet   growl_servert   okt   targett   argsg      à?s    / (   R   t   cfgt   notify_classest   getR   R&   R(   R)   R*   t	   DARWIN_MLt   appendt   send_notification_centert   _HAVE_CLASSIC_GROWLt   send_local_growlt
   send_growlR   t   startt   timet   sleepR%   t   send_notify_osdR   (   t   titlet   msgt   gtypet   waitt   testt   resR&   R(   R)   R*   t   r(    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyt   send_notificationi   s0    "c           C€  s   d  a t a d  S(   N(   R   t   _GROWLR    R!   (    (    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyt   reset_growl   s    c         C€  sÉ  d  } |  r- |  j d ƒ } |  j d ƒ } n t j j ƒ  } t j j ƒ  } t j j | ƒ \ } } t | ƒ } g  t	 _
 i  t	 _ t d d | d t ƒ  d g  t D] } t t | ƒ ^ q¡ d | pÆ d d	 | pÒ d
 d | pÞ d  ƒ } yg | j ƒ  }	 |	 d  k st |	 t ƒ r$t j d ƒ | }	 n& d t |	 ƒ } t j | ƒ ~ d  }	 Wnq t j k
 r‰}
 d t |
 ƒ } t j | ƒ ~ d  }	 n6 d } t j | ƒ t j d d t ƒ~ d  }	 n X|	 | f S(   NR*   t   growl_passwordt   applicationNames	   SABnzbd%st   applicationIcont   notificationst   hostnamet	   localhostt   portiZ  t   passwords   Registered with Growls   Cannot register with Growl %ss    Unknown Growl registration errors   Traceback: t   exc_info(   R   R0   R   R.   R*   RE   t   misct
   split_hostRI   R   RH   t   headersR   R   R   t   Txt   NOTIFICATIONt   registert
   isinstanceR#   t   loggingt   infot   strt   debugt   socketR   t   True(   R?   R   R*   RE   t   hostRK   t   sys_namet   keyt   growlert   rett   err(    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyt   register_growl˜   sL    		
	#	
	
c   	   	   C€  s®  x§d D]Ÿ} t  s d  a n  | r, t ƒ  n  t sG t | ƒ \ a } n  t rt a  t | t ƒ r‚ t | t ƒ r‚ t | ƒ } n  t	 j
 d | t |  ƒ t | ƒ ƒ y“ t j d t t j | d ƒ ƒ d |  d t | ƒ ƒ } | d  k sø t | t ƒ rd  } n5 | d d k rt a n t	 j
 d	 | ƒ d	 | f } Wq•t j k
 rl} d	 | } t	 j
 | ƒ | } q•d
 } t	 j
 | ƒ | } q•Xn | } | r¥t ƒ  n  | SWd  S(   Ni    i   s   Send to Growl: %s %s %st   noteTypeR   R;   t   descriptiont   401s   Growl error %ss   Growl error (unknown)(   i    i   (   R!   R   RC   RD   Ra   RZ   RT   RW   t   unicodeRU   RX   R   t   notifyRQ   RR   R0   R   R#   R    RY   R   (	   R;   R<   R=   R?   t   nR   R_   t   resultR`   (    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyR6   Ï   sH     	
 "			
	
s   sabnzbdplus.icnss   osx/resources/sabnzbdplus.icnst   Terminalc      	   C€  sƒ   t  sZ g  t D] } t t | ƒ ^ q } t j d d d t d | d | ƒ a  t  j ƒ  n  t  j t t j	 | d ƒ ƒ |  | ƒ d  S(   NRF   t   SABnzbdRG   RH   t   defaultNotificationsR   (   t   _local_growlR   RQ   RR   t   GrowlR   t	   _OSX_ICONRS   Rf   R0   R   (   R;   R<   R=   R]   t   notes(    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyR5     s    #		%c         C€  sµ   d } t  j j ƒ  r­ t j j t  j d ƒ } t p? t j	 d ƒ a t r¦ t
 j d t |  ƒ t | ƒ ƒ y# t j |  | | ƒ } | j ƒ  Wn t
 j | ƒ | SXd  S| Sn d Sd  S(   Ns   NotifyOSD not workings   sabnzbd.icos   icon-summary-bodys   Send to NotifyOSD: %s / %ss   Not enabled(   R   R.   R(   R   R   R   R   t   _NTFOSDt   pynotifyt   initRU   RV   R   t   Notificationt   showR   (   R;   t   messageR   R   t   note(    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyR:   !  s    c          C€  sB   t  j j t  j j t j d ƒ ƒ }  t  j j |  ƒ r: |  Sd  Sd  S(   Ns/   ../Resources/SABnzbd.app/Contents/MacOS/SABnzbd(   R   R   t   normpathR   R   R   t   existsR   (   t   tool(    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyt   ncenter_path9  s    $c      
   C€  sð   t  ƒ  } | rÝ y˜ | d |  d | d t t j | d ƒ ƒ d d g	 } t j | d t j d t j d	 t ƒ} | j j	 ƒ  } | j
 ƒ  d
 | k s d | k r¦ d } n  Wqã t j d | ƒ t j d d t ƒd } qã Xn d } | j d ƒ S(   Ns   -titles   -messages   -groupR   s   -senders   org.sabnzbd.teamt   stdoutt   stderrt   shells   Notification delivereds   Removing previouslyt    s   Cannot run notifier "%s"s   Traceback: RM   s   Notifier tool crasheds   Notifier app not founds   *
 (   Rz   RQ   RR   R0   t
   subprocesst   Popent   PIPER    R{   R   R>   RU   RV   RX   RZ   t   strip(   R;   R<   R=   Ry   t   commandt   proct   output(    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyR3   A  s     	''
c         C€  sa   t  j r! t j j d d ƒ } n$ y t j ƒ  d } Wn d } n X|  rY d | j ƒ  Sd Sd  S(   Nt   computernamet   unknowni   s   @%sR~   (   R   R   R   t   environR0   t   unamet   lower(   R[   R\   (    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyRI   W  s    	
(8   t
   __future__R    t   os.pathR   RU   RY   R8   R   t	   threadingR   R   t   sabnzbd.cfgt   sabnzbd.encodingR   R   t   sabnzbd.constantsR   t   gntpR   t   gntp.notifierR   Rm   R   R   R4   t   ImportErrorR    t   warningst   catch_warningst   simplefilterRq   RZ   R$   t   TTRR   R   RC   R!   R   R"   R%   RB   RD   Ra   R6   Rl   t   Imaget   imageFromPathRn   t   imageWithIconForApplicationR5   Rp   R:   Rz   R3   RI   (    (    (    s#   /var/www/SABnzbd/sabnzbd/growler.pyt   <module>   sn   


				&		74		