³ò
àŸÔPc        
   @   sí   d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z e i ƒ  d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 e	 ƒ  Z
 d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d  d k Z d e i d
 „ Z e i d „ Z d „  Z d S(   iÿÿÿÿNt   InstallInfoc           B   sS   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sˆ   
   Class for keeping installation information for an addon
   Information stored includes basename, version, files, and directories
   t    c         C   s%   | |  _  t ƒ  |  _ t ƒ  |  _ d  S(   N(   t   basenamet   sett   filest   dirs(   t   selfR   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   __init__   s    	c         C   s   |  i  S(   s)    Returns the stored version of the addon (   t   version(   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt
   getVersion   s    c         C   s   | |  _  d S(   s&    Sets the stored version of the addon N(   R   (   R   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt
   setVersion   s    c         C   s   |  i  i | ƒ d S(   s(    Marks a file as belonging to the addon N(   R   t   add(   R   t   file(    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   addFile"   s    c         C   s   |  i  i ƒ  S(   s/    Returns a set of files belonging to the addon (   R   t   copy(   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   getFiles&   s    c         C   s   |  i  i | ƒ d S(   s-    Marks a directory as belonging to the addon N(   R   R   (   R   t   dir(    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   addDir*   s    c         C   s   |  i  i ƒ  S(   s5    Returns a set of directories belonging to the addon (   R   R   (   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   getDirs.   s    (   t   __name__t
   __module__t   __doc__R   R   R	   R
   R   R   R   R   (    (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR       s   						t   InstallInfoManagerc           B   sW   e  Z d  Z e i d ƒ d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   s1    Class that manages InstallInfo instaces on disk t   _libss   /python/installinfo/c         C   s.   t  i i |  i ƒ p t  i |  i ƒ n d S(   s7    Creates the installinfo directory if it doesn't exist N(   t   ost   patht   isdirt   infopatht   mkdir(   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR   7   s    c         C   s   |  i  | d S(   s8    Returns the absolute path to a basename's install info s   .db(   R   (   R   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   getInfoPath<   s    c         C   s   t  i i |  i | ƒ ƒ S(   sQ    Returns True if the basename has registered InstallInfo otherwise returns False (   R   R   t   isfileR   (   R   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   hasInstallInfo@   s    c         C   sR   |  i  | ƒ o2 t |  i | ƒ ƒ } t i | ƒ } | i ƒ  n t | ƒ } | S(   s3    Returns the InstallInfo instance for the basename (   R   t   openR   t   cPicklet   loadt   closeR    (   R   R   t   infofilet   info(    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   getInstallInfoD   s    c         C   s6   t  |  i | ƒ d ƒ } t i | | ƒ | i ƒ  d S(   s9    Saves the InstallInfo instance provided to the basename t   wN(   R    R   R!   t   dumpR#   (   R   R   R%   R$   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   saveInstallInfoO   s    c         C   sW   g  } t  d „  t i |  i ƒ ƒ D]- } | | | i d d ƒ i d ƒ d d !q# ~ S(   s=    Returns a list of basenames that have InstallInfo instances c         S   s   |  i  d  ƒ S(   s   .db(   t   endswith(   t   x(    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   <lambda>W   s    s   \t   /i   i   iýÿÿÿ(   t   filterR   t   listdirR   t   replacet   rfind(   R   t   _[1]t   addon(    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   getInstalledU   s    (   R   R   R   t   est   getAddonPathR   R   R   R   R&   R)   R4   (    (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR   3   s   					t   Addonc           B   s,   e  Z d  Z e Z d Z d „  Z d „  Z RS(   s\    Base Addon object that holds required attributes and functions for use with AddonInstaller c         C   s1   | |  _  | |  _ d |  _ d |  _ | |  _ d S(   s˜   
      Along with basename the Addon object also requires the addon file
      That addon file when be given when the download function is called
      t   1R   N(   R   t
   addon_filet   approvedt   currentversiont   es_load(   R   R   R9   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR   b   s
    				c         C   s   |  i  S(   s=    Returns the addon file given in the initialization function (   R9   (   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   downloadn   s    N(   R   R   R   t   infomanagert   NoneR9   R   R=   (    (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR7   ]   s
   	t   AddonInstallerc           B   sµ   e  Z d  Z d Z d Z d Z d Z d Z e e	 i
 d ƒ ƒ d Z e	 i d ƒ d Z d	 „  Z d
 „  Z d „  Z d „  Z e d d „ Z e d „ Z d d „ Z d „  Z d „  Z RS(   sI    Class that handles the installing, updating, and uninstalling of addons i    i   i   i   i   t   eventscripts_gamedirR-   t	   _autoloadc         C   s)   | |  _  t i |  i  i ƒ d |  _ d S(   sA    Installation of an addon requires an Addon-based class instance R-   N(   R3   R5   R6   R<   t   addondir(   R   R3   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR      s    	c         C   sn   |  i  i i d ƒ d } t t t i i |  i | d |  i d | d f ƒ ƒ p |  i  i	 i
 |  i  i ƒ S(   s@    Returns True if the addon is installed otherwise returns False R-   i    s   .pyt   es_s   .txtiÿÿÿÿ(   R3   R<   t   splitt   boolR.   R   R   R   RC   R>   R   R   (   R   t   filename(    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   isInstalledˆ   s    c         C   s!   t  i i |  i |  i i d ƒ S(   sA    Returns True if the addon is autoloaded otherwise returns False s   .cfg(   R   R   R   t   autoloadpathR3   R   (   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   isAutoLoaded   s    c         C   s~   |  i  |  i i d } | o8 t | d ƒ } | i d |  i i d ƒ | i ƒ  n% t i i	 | ƒ o t i
 | ƒ n d S(   s9    Sets or removes autoload for the addon based on "state" s   .cfgR'   s	   es_xload s   
N(   RI   R3   R   R    t   writeR<   R#   R   R   R   t   remove(   R   t   stateRI   t   autoloadfile(    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   setAutoload‘   s    c         C   s›   |  i  ƒ  o |  i Sn |  i i d j o |  i Sn | d j o |  i i ƒ  n | } | p |  i Sn |  i | t	 |  i i
 ƒ ƒ |  i | ƒ |  i S(   sÄ   
      Installs the addon, setting autoload if necessary. If the optional
      "addon_file" keyword is provided that file will be used in lieu of
      downloading the addon from the ESAM.
      R8   N(   RH   t   STATUS_ALREADY_DONER3   R:   t   STATUS_NOT_APPROVEDR?   R=   t   STATUS_NO_DOWNLOADt   _extractR    R   RO   t   STATUS_SUCCESSFUL(   R   t   autoloadR9   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   installŸ   s    #c         C   sý   |  i  i i |  i  i ƒ p |  i Sn |  i  i d j o |  i Sn |  i  i i |  i  i ƒ } | o1 | i ƒ  |  i  i	 j o | i ƒ  o |  i
 Sn |  i ƒ  } |  i  i ƒ  } | p |  i Sn |  i | ƒ } | |  i j o | Sn |  i | | ƒ S(   sƒ   
      Updates the addon it "force" is True or the ESAM version number is different
      from the installed version number.
      R8   (   R3   R>   R   R   t   STATUS_NO_INSTALL_INFOR:   RQ   R&   R	   R;   RP   RJ   R=   RR   t	   uninstallRT   RV   (   R   t   forcet   installinfoRU   R9   t   status(    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   update±   s    '9c      	   C   si  | d j oF |  i i i |  i i ƒ p |  i Sn |  i i i |  i i ƒ } n |  i i |  i ƒ  j o t	 i
 |  i i ƒ n x0 t t i i | i ƒ  ƒ D] } t i | ƒ qŸ WxP t t i i t | i ƒ  d t ƒƒ D]' } t i | ƒ p t i | ƒ qÞ qÞ WxV t t i i |  i |  i i d |  i i i |  i i ƒ f ƒ D] } t i | ƒ qKW|  i S(   sm   
      Unloads the addon if it is loaded
      Uninstalls the addon using the InstallInfo of the addon
      t   reverses   .cfgN(   R?   R3   R>   R   R   RW   R&   R<   t   _getAddonSetR5   t   unloadR.   R   R   R   R   RL   R   t   sortedR   t   TrueR/   t   rmdirRI   R   RT   (   R   RZ   RG   R   R   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyRX   Æ   s    '0 ( B c   	      C   s  t  i | ƒ } t | i ƒ  ƒ } x` t d „  | ƒ D]L } | i |  i | ƒ t i i	 |  i | ƒ p t i
 |  i | ƒ q4 q4 Wt i |  i i ƒ d } | i | ƒ | i | d ƒ x† t d „  | ƒ D]r } | i |  i | ƒ | i d ƒ o | i |  i | d ƒ n t i |  i | ƒ } | i | i | ƒ ƒ qÎ W| i |  i i ƒ |  i i i |  i i | ƒ | i ƒ  d S(   sV    Extracts the zip file "addon_file" while updating InstallInfo instance "installinfo" c         S   s   |  i  d  ƒ S(   R-   (   R*   (   R+   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR,   å   s    s   /__init__.pyt   cc         S   s   |  i  d  ƒ S(   R-   (   R*   (   R+   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR,   ñ   s    s   .pyN(   t   zipfilet   ZipFileR`   t   namelistR.   R   t   gamepathR   R   R   R   R5   R6   R3   R<   R   R*   t   write_bytest   readR
   R;   R>   R)   R   R#   (	   R   R9   RZ   t	   addon_zipt   ziplistR   t	   init_pathRG   t   newfile(    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyRS   ß   s(      c         C   s\   t  t i ƒ  ƒ } xC t i i ƒ  D]2 } | i | i | i i d ƒ  i d d ƒ ƒ q" W| S(   s)    Returns a set of all ESS and ESP addons t   .R-   (	   R   R5   t   createscriptlistt   addonst   getAddonListR   R   R1   R0   (   R   t
   addon_listR3   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR^   ÿ   s
     0N(   R   R   R   RT   RR   RW   RP   RQ   t   strR5   t	   ServerVarRg   R6   RI   R   RH   RJ   RO   t   FalseR?   RV   R\   RX   RS   R^   (    (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR@   t   s"   					 c         C   sG   | o t  |  | ƒ n t i |  | ƒ } | d j o d n
 t | ƒ S(   sÄ   
   Returns an AddonInstaller instance for the given basename. When "addon_file"
   is provided it will be the zip file installed, otherwise esamlib will provide
   the zip file from the ESAM.
   N(   R7   t   esamlibt   getAddonR?   R@   (   R   R9   t   logR3   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   getInstaller  s    )c         C   s   t  |  t | d ƒ | ƒ S(   s6    Returns an AddonInstaller instance for a zip on disk t   rb(   Ry   R    (   R   R   Rx   (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   getInstallerFromPath  s    c             s{   t  i d ƒ d ‰  t i i ˆ  ƒ p t i ˆ  ƒ n x= t ‡  f d †  t i ˆ  ƒ ƒ D] }  t  i i	 d |  ƒ qY Wd S(   s9    Loads all installed addons marked for automatic loading RB   R-   c            s$   |  i  d  ƒ o t i i ˆ  |  ƒ S(   s   .cfg(   R*   R   R   R   (   R+   (   RI   (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyR,   !  s    s+   es_xmexec ../addons/eventscripts/_autoload/N(
   R5   R6   R   R   R   R   R.   R/   t   servert   queuecmd(   RG   (    (   RI   sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pyt   _executeAutoLoad  s    " (   R!   R5   R   R   Rd   t   psycot   fullt   objectR    R   R>   R7   R@   Rv   R?   t   dbglogRy   R{   R~   (    (    (    sQ   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/installlib.pys   <module>   s    
%&	•		#