Ñò
ÝT~Kc        	   @   s  d  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 e ƒ  a d g Z	 d „  Z
 d „  Z e e d „ Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z e i d „ Z d S(   s§  
Planet Configuration

This module encapsulates all planet configuration.  This is not a generic
configuration parser, it knows everything about configuring a planet - from
the structure of the ini file, to knowledge of data types, even down to
what are the defaults.

Usage:
  import config
  config.load('config.ini')

  # administrative / structural information
  print config.template_files()
  print config.subscriptions()

  # planet wide configuration
  print config.name()
  print config.link()

  # per template configuration
  print config.days_per_page('atom.xml.tmpl')
  print config.encoding('index.html.tmpl')

Todo:
  * error handling (example: no planet section)
iÿÿÿÿN(   t   ConfigParser(   t   urljoint   filtersc       	      sC  d d k  ‰ d „  ‰  d „  ‰ ‡  ‡ f d †  }  d ‡  ‡ f d † } d ‡  ‡ ‡ f d	 † } ‡  ‡ f d
 †  } ‡  ‡ f d †  } |  d d ƒ |  d d ƒ |  d d ƒ |  d d ƒ |  d d ƒ |  d d ƒ |  d d ƒ |  d d ƒ |  d d ƒ |  d d ƒ |  d d ƒ |  d  d ƒ |  d! d" ƒ |  d# d ƒ | d$ d ƒ | d% d& ƒ | d' d( ƒ | d) ƒ | d* ƒ | d+ d, ƒ | d- ƒ | d. d ƒ | d/ d0 ƒ | d1 d ƒ | d2 d3 ƒ | d4 d3 ƒ | d5 d ƒ | d6 d ƒ | d7 d ƒ | d8 d ƒ | d4 d ƒ | d9 d: ƒ | d; d ƒ | d< d ƒ | d= d ƒ d S(>   s"   define the struture of an ini fileiÿÿÿÿNc         S   s{   |  o$ t  i |  | ƒ o t  i |  | ƒ St  i d | ƒ o5 | d j o t  i d | d t ƒSt  i d | ƒ S| Sd  S(   Nt   Planett
   log_formatt   raw(   t   parsert
   has_optiont   gett   True(   t   sectiont   optiont   default(    (    s   /net/bzr/venus/planet/config.pyR   *   s    c   
      S   s¸   g  } t  i d ƒ } xœ |  i ƒ  D]Ž } | i | ƒ } | oe | i ƒ  \ } } } xZ t ƒ  D]> } t | ƒ i | d  ƒ }	 |	 o | i	 | |	 | ƒ q] q] Wq" | i	 | ƒ q" W| S(   Ns   ^(.*)#{(\w+)}(.*)$(
   t   ret   compilet   splitt   matcht   groupst   subscriptionst   feed_optionsR   t   Nonet   append(
   t   listt   outputt   wildt   fileR   t   pret   vart   postt   subt   value(    (    s   /net/bzr/venus/planet/config.pyt   expand5   s     
 !c            s0   t  ˆ ˆ  | ‡  ‡ f d † ƒ t i ˆ  ƒ d  S(   Nc            s   ˆ d  ˆ  |  ƒ S(   N(   R   (   R   (   t   nameR   (    s   /net/bzr/venus/planet/config.pyt   <lambda>F   s    (   t   setattrt   planet_predefined_optionsR   (   R    R   (   R   t   config(   R    s   /net/bzr/venus/planet/config.pyt   define_planetE   s    i    c            s0   t  ˆ ˆ  ‡ ‡  ‡ f d †  ƒ t i ˆ  ƒ d  S(   Nc              s   t  ˆ d  ˆ ˆ  ƒ ƒ S(   N(   t   intR   (    (   R   R    R   (    s   /net/bzr/venus/planet/config.pyR!   K   s    (   R"   R#   R   (   R    R   (   R   R$   (   R    R   s   /net/bzr/venus/planet/config.pyt   define_planet_intJ   s    t    c            s3   t  ˆ ˆ  ‡ ‡  ‡ ‡ f d †  ƒ t i ˆ  ƒ d  S(   Nc              s   ˆ ˆ d  ˆ ˆ  ƒ ƒ S(   N(   R   (    (   R   R    R   R   (    s   /net/bzr/venus/planet/config.pyR!   P   s    (   R"   R#   R   (   R    R   (   R   R$   R   (   R    R   s   /net/bzr/venus/planet/config.pyt   define_planet_listO   s    "c            s#   t  ˆ ˆ  | ‡  ‡ f d † ƒ d  S(   Nc            s   ˆ |  ˆ  | ƒ S(    (    (   R
   R   (   R    R   (    s   /net/bzr/venus/planet/config.pyR!   U   s    (   R"   (   R    R   (   R   R$   (   R    s   /net/bzr/venus/planet/config.pyt   define_tmplT   s    c            s#   t  ˆ ˆ  | ‡  ‡ f d † ƒ d  S(   Nc            s   t  ˆ |  ˆ  | ƒ ƒ S(    (   R&   (   R
   R   (   R    R   (    s   /net/bzr/venus/planet/config.pyR!   Z   s    (   R"   (   R    R   (   R   R$   (   R    s   /net/bzr/venus/planet/config.pyt   define_tmpl_intY   s    R    s   Unconfigured Planett   linkt   cache_directoryt   cachet	   log_levelt   WARNINGR   s"   %(levelname)s:%(name)s:%(message)st   date_formats   %B %d, %Y %I:%M %pt   new_date_formats	   %B %d, %Yt	   generatort   Venust   generator_uris#   http://intertwingly.net/code/venus/t
   owner_names   Anonymous Cowardt   owner_emailt   output_themet
   output_dirR   t   spider_threadst   new_feed_itemst   feed_timeouti   t   cache_keep_entriesi
   t   template_filest   bill_of_materialst   template_directoriest   .t   filter_directoriest   days_per_paget   items_per_pagei<   t   activity_thresholdt   encodings   utf-8t   content_typet   ignore_in_feedt	   name_typet
   title_typet   summary_typet   future_datest   keept   xml_baset   filtert   exclude(   R$   R   (   R%   R'   R)   R*   R+   (    (   R   R$   R   s   /net/bzr/venus/planet/config.pyt   __init__%   sV    		


c            s‘  t  ƒ  a t i |  ƒ d d k } d d k } d d k l ‰ l ‰ l ‰  | i } | p" | i	 | i
 ƒ  | i ƒ  ƒ } n | i ƒ  } | oxd t i i t i d d ƒ f D]Ô} t i i | | ƒ } t i i | d ƒ } t i i | ƒ o‘| i ƒ  } | | j o | i | ƒ n t i i |  ƒ | j o | i t i i |  ƒ ƒ n t  ƒ  a t i | ƒ | i ƒ  }	 | g  }
 | i ƒ  D]- } | | j o |
 t i i | | ƒ q‹q‹~
 7} | i ƒ  } t i d d	 d ƒ t i |  ƒ x2 | i ƒ  D]$ } | |	 j o |	 i | ƒ qûqûWt i d d
 d i |	 ƒ ƒ t i d d d i | ƒ ƒ t i d d	 d i | | i ƒ  ƒ ƒ Pq² q² W| i d | ƒ n | i ƒ  } t i i t i d d ƒ } | | j o: t i i | ƒ o' t i d d d i | | g ƒ ƒ n | i ƒ  } | om t i i | i ƒ  ƒ p t i | i ƒ  ƒ n ‡ ‡ ‡  ‡ f d †  } x" | D] ‰ t ˆ t | ƒ qoWn d S(   s$    initialize and load a configurationiÿÿÿÿN(   t   opmlt   foaft
   csv_configR(   i    t   themess
   config.iniR   R>   R?   t    R@   s   Unable to find theme %sR   RB   c      	      s7  t  ˆ ƒ i d ƒ d j o ˆ i |  | ƒ nÞ t  ˆ ƒ i d ƒ d j o ˆ  i |  | ƒ n® t  ˆ ƒ i d ƒ d j o ˆ i |  | ƒ n~ t  ˆ ƒ i d ƒ d j o | i |  ƒ nQ d d k l } d d  k } | i | i | i	 t  ˆ ƒ |  i
 ƒ  d d	 ƒƒ ƒ | i ƒ  g  ˆ g g j o
 t ‚ n d  S(
   NRR   i    RS   t   csvR$   iÿÿÿÿ(   t   shellt   modeRO   (   RG   t   findt   opml2configt   foaf2configt
   csv2configt   readfpt   planetRX   t   StringIOt   runt   getvaluet   sectionst	   Exception(   t   datat   cached_configRX   R`   (   RS   RR   RT   R   (    s   /net/bzr/venus/planet/config.pyt   data2configÃ   s    "(   R    R   t   readR$   R_   RR   RS   RT   t   loggert	   getLoggerR/   R   R8   t   ost   patht   joint   syst   existsR@   R   t   dirnameR?   R>   t   sett   errorRB   t   reading_listst   cache_lists_directoryt   makedirst   downloadReadingList(   t   config_fileR$   R_   t   logt   themeRl   t	   theme_dirt
   theme_filet   dirst   bomt   _[1]t   dirR>   R   t
   filter_dirRs   Rg   (    (   RT   RS   RR   R   s   /net/bzr/venus/planet/config.pyt   load†   sb    		"# 	
A  	 ' c         C   s  d d k  l } d d  k } yId d  k } d d  k } d d k l }	 |	 | i ƒ  |  ƒ }
 h  } x- | i |  ƒ D] } | i	 |  | ƒ | | <qr WyU | oJ t
 ƒ  } | i |
 ƒ x1 | i |  ƒ D] } | i	 |  | ƒ | | <qÂ Wn Wn n Xt
 ƒ  } | i |  ƒ x- | i ƒ  D] \ } } | i |  | | ƒ qWt t i d d ƒ } t i i d ƒ d j  o t d t i i | ƒ ƒ } n@ t i i t i i ƒ } t d	 | i d
 d ƒ i d d ƒ ƒ } | i t | d |  ƒ ƒ } | i d ƒ o | i d | d ƒ n | i d ƒ o | i d | d ƒ n | i | ƒ } | i i d ƒ o | i |  d | i d ƒ n | i i d ƒ o | i |  d | i d ƒ n | i | i ƒ  ƒ } | o | | | ƒ n | o* t |
 d ƒ } | i | ƒ | i  ƒ  n | i! d |  ƒ | oO | o | i |
 ƒ qd| i ƒ  } | i | ƒ | i" d ƒ | i# | ƒ n Wn› yz | oo | o! | i |
 ƒ p t$ ƒ  ‚ qÐn4 | i ƒ  } | i | ƒ | i" d ƒ | i# | ƒ | i% d |  ƒ n Wq| i& d |  ƒ qXn Xd  S(   Niÿÿÿÿ(   Ri   (   t   filenamet   curdirRA   t   wini    s   file:s   file:///t   :t   |s   \t   /t   etags   If-None-Matchs   last-modifieds   If-Modified-Sincet   ws   Using %s readinglists   Using cached %s readinglists   Unable to read %s readinglist('   R_   Ri   R$   t   urllib2R`   t   planet.spiderR‚   Rt   t   optionsR   R    Rh   t   add_sectiont   itemsRq   t   getattrRk   Rl   Rn   t   platformRZ   R   t   abspathRƒ   t   replacet   Requestt   has_keyt
   add_headert   urlopent   headerst   opent   writet   closet   debugt   seekR^   Rd   t   infot	   exception(   R   t   orig_configt   callbackt	   use_cachet   re_readRi   R$   RŠ   R`   R‚   t   cache_filenameRŒ   t   keyRf   R   R   Rƒ   t   baseRl   t   requestt   responseRe   R.   t   cdata(    (    s   /net/bzr/venus/planet/config.pyRv   Ø   sŠ     	 "	 '	  c           C   sS   t  i d d ƒ o& t i i t ƒ  t  i d d ƒ ƒ n t i i t ƒ  d ƒ Sd  S(   NR   t   http_cache_directoryR.   (   R   R   Rk   Rl   Rm   R-   R   (    (    (    s   /net/bzr/venus/planet/config.pyR©   0  s    c           C   sP   t  i d d ƒ o# t i i t ƒ  t  i d d ƒ ƒ St i i t ƒ  d ƒ Sd  S(   NR   t   cache_sources_directoryt   sources(   R   R   Rk   Rl   Rm   R-   R   (    (    (    s   /net/bzr/venus/planet/config.pyRª   7  s    c           C   sA   t  i d d ƒ o t  i d d ƒ n t i i t ƒ  d ƒ Sd  S(   NR   Rt   t   lists(   R   R   R   Rk   Rl   Rm   R-   (    (    (    s   /net/bzr/venus/planet/config.pyRt   >  s    c          C   s©   t  i d d ƒ o t  i d d ƒ St ƒ  ow xt t ƒ  D]e }  t i i t i i |  ƒ ƒ d } | i	 d ƒ d j p | i	 d ƒ d j o t
 t ƒ  | ƒ Sq8 Wn d  S(   NR   t   feedi    t   atomt   rss(   R   R   R   R,   R>   Rk   Rl   t   splitextt   basenameRZ   R   (   t   template_fileR    (    (    s   /net/bzr/venus/planet/config.pyR­   D  s    

 ",c           C   s{   t  i d d ƒ o t  i d d ƒ nQ t ƒ  o t ƒ  i d ƒ d j o d St ƒ  o t ƒ  i d ƒ d j o d Sd  S(   NR   t   feedtypeR®   i    R¯   (   R   R   R   R­   RZ   (    (    (    s   /net/bzr/venus/planet/config.pyR³   M  s    ##c           C   s   t  d d „  t i ƒ  ƒ S(   s    list the feed subscriptions RO   c         S   s(   |  d  j o |  t  ƒ  t ƒ  t ƒ  j S(   R   (   R>   R   Rs   (   R­   (    (    s   /net/bzr/venus/planet/config.pyR!   W  s   (   t   __builtins__R   Rc   (    (    (    s   /net/bzr/venus/planet/config.pyR   U  s    c          C   sÉ   g  }  x¼ t  i ƒ  D]® } t  i | d ƒ o• t  i | d ƒ } | i d ƒ d j pX | i d ƒ d j pB | i d ƒ d j p, | i d ƒ d j p | i d ƒ d j o |  i | ƒ qÁ q q W|  S(   s%    list of lists of feed subscriptions RG   RR   i    RS   RW   R$   RA   (   R   Rc   R   R   RZ   R   (   t   resultR
   t   type(    (    s   /net/bzr/venus/planet/config.pyRs   [  s     ,,c         C   s÷   g  } t  i d d ƒ o  | t  i d d ƒ i ƒ  7} n t |  ƒ o$ | i d t i t |  ƒ ƒ ƒ n t |  ƒ o$ | i d t i t |  ƒ ƒ ƒ n xU |  o
 |  g p t	 ƒ  D]9 }  t  i |  d ƒ o  | t  i |  d ƒ i ƒ  7} q¶ q¶ W| S(   NR   R   s   regexp_sifter.py?require=s   regexp_sifter.py?exclude=(
   R   R   R   R   RO   R   t   urllibt   quoteRP   R>   (   R
   R   (    (    s   /net/bzr/venus/planet/config.pyR   g  s     		 $c           C   s   t  t d „  t i d ƒ ƒ ƒ S(   s"    dictionary of planet wide optionsc         S   s"   |  t  i d  |  d |  d j ƒf S(   R   R   R   (   R   R   (   t   opt(    (    s   /net/bzr/venus/planet/config.pyR!   x  s   R   (   t   dictt   mapR   RŒ   (    (    (    s   /net/bzr/venus/planet/config.pyt   planet_optionsv  s    c      
      sŸ   d d k  } t g  } t ƒ  i ƒ  D]* \ } } | t j o | | | f q# q# ~ ƒ } t i ˆ  ƒ o2 | i t t ‡  f d †  t i	 ˆ  ƒ ƒ ƒ ƒ n | S(   s$    dictionary of feed specific optionsiÿÿÿÿNc            s   |  t  i ˆ  |  ƒ f S(    (   R   R   (   R¹   (   R
   (    s   /net/bzr/venus/planet/config.pyR!   ‚  s    (
   R$   Rº   R¼   RŽ   R#   R   t   has_sectiont   updateR»   RŒ   (   R
   R$   R~   R¤   R   RŒ   (    (   R
   s   /net/bzr/venus/planet/config.pyR   |  s    #*c         C   s
   t  |  ƒ S(   s(    dictionary of template specific options(   R   (   R
   (    (    s   /net/bzr/venus/planet/config.pyt   template_options†  s    c         C   s
   t  |  ƒ S(   s&    dictionary of filter specific options(   R   (   R
   (    (    s   /net/bzr/venus/planet/config.pyt   filter_optionsŠ  s    c         C   s   t  i |  ƒ GHd S(   s    write out an updated template N(   R   R™   (   R   (    (    s   /net/bzr/venus/planet/config.pyR™   Ž  s    (   t   __doc__Rk   Rn   R   R·   R    t   urlparseR   R   R#   RQ   R   R	   Rv   R©   Rª   Rt   R­   R³   R   Rs   R   R   R¼   R   R¿   RÀ   t   stdoutR™   (    (    (    s   /net/bzr/venus/planet/config.pyt   <module>   s*   0			a	RX										
		
