³ò
àŸÔPc           @   sn   d  d k  Z  d  d k Z d  d k l Z d  d k Z e i ƒ  d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d S(   iÿÿÿÿN(   t	   ConfigObjt   AddonCFGc           B   s•   e  Z d  Z d Z d Z d Z e e i d ƒ ƒ i	 d d ƒ Z
 d d „ Z e d	 „ Z d
 d „ Z d „  Z d „  Z e d „ Z d „  Z d „  Z RS(   s%    Class for handling addon .cfg files i    i   i   t   eventscripts_gamedirs   \t   /i   c         C   s@   | i  d d ƒ |  _ | |  _ g  |  _ t ƒ  |  _ h  |  _ d  S(   Ns   \R   (   t   replacet   cfgpatht	   indentiont   cfglistt   sett   commandst   cvars(   t   selfR   R   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   __init__   s
    		c         C   sP   | i  ƒ  p
 t } n |  i i |  i | o d n d t | ƒ d f ƒ d S(   s#    Adds the given text to the config s   // t    s   
N(   t   stript   FalseR   t   appendt	   TYPE_TEXTt   str(   R   t   textt   comment(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyR       s    R   c         C   sF   | | | f } |  i  | <|  i i |  i | f ƒ t i | | | ƒ S(   sD    Adds the named cvar to the config and returns a ServerVar instance (   R
   R   R   t	   TYPE_CVARt   est	   ServerVar(   R   t   namet   defaultt   descriptiont   var(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   cvar%   s    c         C   s-   |  i  i | ƒ |  i i |  i | f ƒ d S(   s?    Designates a place for the named server command in the config N(   R	   t   addR   R   t   TYPE_COMMAND(   R   R   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   command,   s    c      	   C   sU  |  i  ƒ  } d |  i } t |  i d ƒ } xT|  i D]I\ } } | |  i j o | i | ƒ q5 | |  i j o© | \ } } } | i d ƒ | o | i d | ƒ n | | j o( | i | | | d d ƒ | | =q~| i | | d t | t	 ƒ o d n d | d ƒ q5 | |  i
 j oS | | j oB | i d ƒ x' | | D] }	 | i | |	 d ƒ qPW| | =q~q5 q5 W| o | i d ƒ n xQ t t d „  | ƒ ƒ D]7 } x' | | D] }
 | i | |
 d ƒ qÄW| | =q³W| o | i d ƒ n x> t | ƒ D]0 } x' | | D] }
 | i d	 |
 d ƒ q$WqW| i ƒ  d
 S(   s    Writes the config to file t    t   ws   
s   // %s
i    s   "%s"s   %sc         S   s#   t  i d  |  ƒ p t  i d |  ƒ S(   t   variableR   (   R   t   exists(   t   x(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   <lambda>Z   s    s   // N(   t   _parseR   t   openR   R   R   t   writeR   t
   isinstanceR   R   t   sortedt   filtert   close(   R   t   current_cfgR   t   cfgfilet   ltypet   dataR   R   R   t   old_linet   line(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyR(   2   sN    
 <     c         C   s*   t  i d |  i i |  i d d ƒ ƒ d S(   s    Executes the config s   ..R   i   N(   R   t   mexecR   R   t   gamedir(   R   t   queuecmd(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   executeh   s    c         C   s   |  i  i ƒ  S(   s    Returns the cvars dictionary (   R
   t   copy(   R   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   getCvarsl   s    c         C   s:  t  i i |  i ƒ p h  Sn t |  i ƒ } t t i | i ƒ  ƒ } | i	 ƒ  h  } xÞ | D]Ö } | i
 d ƒ p | o q\ n | i d d ƒ d } | |  i j p | |  i j o | i d ƒ p q\ qÒ n | | j o g  | | <n | | | j o4 | | i | | i d ƒ d o d n d ƒ q\ q\ W| S(   sG    Internal function: Parses the config and returns the current settings s   //R    i   i    t   "i   R   (   t   ost   patht   isfileR   R'   t   mapR   R   t	   readlinesR,   t
   startswitht   splitR	   R
   t   countR   (   R   R.   t   cfglinesR-   R2   R   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyR&   r   s"    
  8(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R4   R   t   TrueR   R   R   R(   R   R6   R8   R&   (    (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyR      s   !
		6	t   AddonINIc           B   s   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 d „ Z
 d „  Z d d	 „ Z d
 „  Z d „  Z d „  Z e d „  ƒ Z RS(   s9    Class for handling addon .ini files, mostly for langlib c         O   sD   t  t |  ƒ i | | | Ž t |  _ | |  _ d  |  _ g  |  _ d  S(   N(	   t   superRG   R   RF   t   unreprt   filepatht   Nonet   filenamet   order(   R   RL   t   at   kw(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyR   ª   s
    			c         C   sT   t  | t ƒ o | g } n | o | d o | d =n t |  i | ƒ |  _ d S(   sK    Sets the comments at the top of the ini file, lists or strings acceptable i    Niÿÿÿÿiÿÿÿÿ(   R)   t
   basestringR=   t   formatCommentt   initial_comment(   R   t   comment_list(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   setInitialComments´   s
    c         C   s[   t  | t ƒ o | g } n | o | d o | d =n d g t |  i | ƒ |  _ d S(   sN    Sets the comments at the bottom of the ini file, lists or strings acceptable i    R   Niÿÿÿÿiÿÿÿÿ(   R)   RP   R=   RQ   t   final_comment(   R   RS   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   setFinalComments¼   s
    c         C   s,   |  i  i | ƒ |  | d g |  i | <d S(   s[    Adds a group (tranlation phrase identifier) to the ini for another phrase for translation R   N(   RM   R   t   comments(   R   t   header(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   addGroupÇ   s    c         C   s   | |  j o |  | =n d S(   s#    Removes a group from the ini file N(    (   R   RX   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   delGroupÍ   s    c         C   sA   t  | t ƒ o | f } n d g t |  i | ƒ |  i | <d S(   sS    Sets the comments associated with a group, comments acceptable as list or strings R   N(   R)   RP   R=   RQ   RW   (   R   RX   RS   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   setGroupCommentsÒ   s    c         C   s2   | |  | j p | o | |  | | <t  Sn t S(   sÛ   
      Adds an identifier (language abbreviation) and corresponding value (translation) to
      a group. This function will be ignored if the identifier already exists unless
      the overwrite keyword is True.
      (   RF   R   (   R   RX   t
   identifiert   valuet	   overwrite(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   addValueToGroupÛ   s    c         C   s$   | |  | j o |  | | =n d S(   s[    Removes an identifier (language abbreviation and corresponding translation) from ini file N(    (   R   RX   R\   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   delValueFromGroupç   s    c            s3  d | j o: t  | ƒ d j o' | d	 j o t t |  ƒ i |   Sn |  i o |  i d
 o |  i d =n |  i o@ t t |  i ƒ ƒ ‰  t	 |  i
 d ‡  f d †  d t ƒ|  _
 n | d	 j oE t |  i d ƒ } | i d i t t |  ƒ i ƒ  ƒ ƒ | i ƒ  n& | i d i t t |  ƒ i ƒ  ƒ ƒ d	 S(   s°   
      Writes contents of the ini to file
      We only override this function so the user doesn't have to provide a file name
      and we can write the file ourselves.
      t   sectioni   i    t   keyc            s%   |  ˆ  j o ˆ  i  |  ƒ d  n d S(   i   i    (   t   index(   R$   (   t
   sort_order(    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyR%      s    t   reverseR!   s   
Niÿÿÿÿiÿÿÿÿ(   t   lenRK   RH   RG   R(   RR   RM   t   listt   reversedR*   t   sectionsRF   R'   RJ   t   joinR,   (   R   t   outfileRO   t   f(    (   Rd   sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyR(   ï   s    -
+%c         C   s1   | |  j o h  |  | <n t  t |  ƒ i | ƒ S(   sL    If the item to get doesn't exist we initialize it with an empty dictionary (   RH   RG   t   __getitem__(   R   t   item(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyRm   
  s    c         C   s   |  i  S(   N(   RL   (   R   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt   __str__  s    c         C   s%   t  t | ƒ o |  i | f Sn d  S(   N(   R)   R   RL   RK   (   R   t   other(    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyt
   __coerce__  s    c         C   s6   |  i  ƒ  }  |  o |  i d ƒ o d |  }  n |  S(   Nt   #s   # (   R   R?   (   R   (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyRQ     s    N(   RC   RD   RE   R   RT   RV   RY   RZ   R[   R   R_   R`   RK   R(   Rm   Ro   Rq   t   staticmethodRQ   (    (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pyRG   §   s   	
										(
   R   t   os.pathR:   t	   configobjR    t   psycot   fullt   objectR   RG   (    (    (    sM   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/cfglib.pys   <module>   s   
œ©