ó
VQc           @   sâ  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z e j j d ƒ Z d Z d Z	 d Z
 e Z d Z d Z d Z d	 Z d
 Z xX e j e j d f D]@ Z e j j e d ƒ Z e j j e ƒ r› e GHe e ƒ Pq› q› Wd  d l m Z d  d l Td Z d j e d „  e j ƒ  ƒ ƒ Z i  a e j j e e	 ƒ Z	 e j j e e
 ƒ Z
 e j j e e ƒ Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) e* d k rÞe) ƒ  n  d S(   iÿÿÿÿNs
   ~/newspages   news.example.comt	   grouptreet
   newsgroupst    t   rooti   s;   ... <img src="http://pelican.cl.cam.ac.uk/icons/page.xbm"> i   t   HOMEs   .newslistrc.py(   t   NNTP(   t   *s
   $Revision$t    c         C   s
   d |  k S(   Nt   $(    (   t   s(    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt   <lambda>m   s    c         C   s6   d GHx* | D]" } | j  d ƒ } t |  | ƒ q Wd  S(   Ns   Updating tree...t   .(   t   splitt   makeleaf(   t   treet   groupst   it   parts(    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt	   addtotreex   s    c         C   st   | d } t  | ƒ } | |  k r/ i  |  | <n  | d k rL d |  | d <n  | d k rp t |  | | d ƒ n  d  S(   Ni    i   R   (   t   lenR   (   R   t   patht   jt   l(    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyR      s    
c      	   C   s  t  j j t |  d ƒ } |  t k r. d } n
 d |  } t | d ƒ ¸ } | j d ƒ | j d | ƒ | j d ƒ | j d | ƒ | j d	 t t f ƒ t | | d
 | ƒ | j d ƒ | j d t	 ƒ | j t
 j t
 j
 ƒ  ƒ d ƒ | j d ƒ Wd  QXd  S(   Ns   .htmlR   s    under t   ws   <html>
<head>
s&   <title>Newsgroups available%s</title>
s   </head>
<body>
s    <h1>Newsgroups available%s</h1>
s-   <a href="%s%s.html">Back to top level</a><p>
i    s   
<p>s7   <i>This page automatically created by 'newslist' v. %s.s   </i>
s   </body>
</html>
(   t   osR   t   joint   pagedirt   rootpaget   opent   writet   httppreft	   printtreet   rcsrevt   timet   ctime(   R   R   t   pt   filenamet   detailt   f(    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt
   createpage   s"    	
		 c         C   s”  t  | ƒ } | t k r} | d k r} |  j d t | d f ƒ |  j | d d ƒ |  j d t ƒ t | d | | ƒ d  S| j ƒ  } | d k rÝ | j ƒ  | d k rÃ |  j d | d ƒ n |  j d ƒ | d } n  x” | D]Œ } | d k rQ|  j d	 | d | d f ƒ | d t k rA|  j d
 t | d ƒ qp|  j d ƒ qä t	 |  | | | | d | ƒ qä W| d k r|  j d ƒ n  d  S(   Ni    s   <li><b><a href="%s%s.html">i   s   .*s   </a></b>%s
s   <li>%s
<ul>s   <ul>R   s   <li><a href="news:%s">%s</a> s        <i>%s</i>
s   
s   
</ul>(
   R   t   sublistsizeR   R   t   pagelinkiconR'   t   keyst   sortt   descR   (   R&   R   t   indentR#   R   t   klR   (    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyR   ¨   s.    
#c      
   C   sÊ   i  a  |  d k r d  Sy’ t |  d ƒ } } d GHxn | D]f } | j ƒ  } y@ | d } d j | d ƒ } t | ƒ d k rˆ | t  | <n  Wq7 t k
 rœ q7 Xq7 WWd  QXWn t k
 rÅ d |  GHd  SXd  S(   NR   t   rs   Reading descriptions...i    R   i   s    Failed to open description file (   R,   R   R   R   R   t
   IndexErrort   IOError(   t   descfilet   dR   t   bitst   grpt   dsc(    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt   readdescÒ   s$    
	c         C   s…   t  j j |  ƒ s d |  GHd GHt j j ƒ  d d k rl y t  j |  d ƒ Wq~ d GHt j d ƒ q~ Xq d GHt j d ƒ n  d  S(	   Ns   Directory %s does not exist.s    Shall I create it for you? (y/n)i    t   yiÿ  s   Sorry - failed!i   s   OK. Exiting.(   R   R   t   isdirt   syst   stdint   readlinet   mkdirt   exit(   R   (    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt
   checkopdirì   s    	c         C   sÊ   d GHi  } y  t  j t j |  ƒ t ƒ } Wn' d |  GHd GHd GHt j d ƒ n Xd | d d | d | d	 f } y+ t |  d
 ƒ  } t j	 | ƒ } Wd  QXWn t
 k
 r¿ d |  GHn X| | f S(   Ns#   Reading current local group list...s&   
*** Failed to open local group cache s5   If this is the first time you have run newslist, thens   use the -a option to create it.i   s   %02d%02d%02di    id   i   t   rbs   Cannot open local group list (   R!   t	   localtimeR   t   statt   ST_MTIMER:   R>   R   t   marshalt   loadR1   (   t   treefileR   t   treetimet   treedatet   dump(    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt   readlocallistü   s      	#c         C   s`   y7 t  |  d ƒ  } t j | | ƒ } Wd  QXd |  GHWn" d G|  GHd GHt j d ƒ n Xd  S(   Nt   wbs   Saved list to %s
s,   Sorry - failed to write to local group caches8   Does it (or its directory) have the correct permissions?i   (   R   RD   RI   R:   R>   (   RF   R   RI   R   (    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt   writelocallist  s    	c         C   s®   d GHd } |  j  ƒ  d } g  } d GHt r4 d GHn  x` | D]X } | d j ƒ  d } t r† t | d ƒ t | d ƒ k  r† | d Gq; | j | ƒ q; Wd	 GHt rª d
 GHn  | S(   Ns   Getting list of all groups...t   010101i   s   Processing...s!   
Ignoring following empty groups:i    i   R   s   
s   (End of empty groups)(   t   listt	   skipemptyR   t   intt   append(   t   serverRH   t   infoR   R   t   grpname(    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt   getallgroups  s     &c         C   sn   d | G|  j  | d ƒ d } d t | ƒ GHd Gg  } x+ | D]# } | j ƒ  d } | j | ƒ q> Wd GH| S(   Ns/   Getting list of new groups since start of %s...t   000001i   s   got %d.s   Processing...i    t   Done(   t	   newgroupsR   R   RQ   (   RR   RH   RS   R   R   RT   (    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt   getnewgroups/  s    c          C   s<  i  }  t  t ƒ yD d t GHt j d d k rA t j t ƒ } n t t ƒ } t } Wn3 t j	 t j
 f k
 r‰ } d G| GHd GHt } n X| rÇ t t j ƒ d k rÇ t j d d k rÇ t | ƒ } n* t t ƒ \ }  } | rñ t | | ƒ } n  | rt |  | ƒ t t |  ƒ n  t t ƒ d GHt t |  d	 ƒ d
 GHd  S(   Ns   Connecting to %s...i    t   0s   Error connecting to host:s$   I'll try to use just the local list.i   s   -as   Creating pages...R   RW   (   R?   R   t   newshostR:   t   versionR   t   initt   Truet   nntplibt
   error_tempt
   error_permt   FalseR   t   argvRU   RJ   RF   RY   R   RL   R7   R2   R'   R   (   R   R	   t	   connectedt   xR   RH   (    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt   main=  s0    
	
	
.
t   __main__(+   R:   R_   RD   R!   R   R   t
   expandusert   topdirR[   RF   R2   R   R   R   RO   R)   R(   t   curdirt   environt   dirR   t   rcfilet   existst   execfileR   RB   R    t   filterR   R,   t   pageR   R   R'   R   R7   R?   RJ   RL   RU   RY   Rf   t   __name__(    (    (    s-   /usr/lib64/python2.7/Demo/scripts/newslist.pyt   <module>#   sJ   <	

!				*							)