³ò
ÚÞ4Hc           @   sÛ  d  Z  d d k l Z l Z l Z l Z d d k l Z l Z d d k l	 Z	 l
 Z
 d d k l Z e d Z d d g Z x6 e D]. Z e e ƒ o e e d	 j o
 e Z q q Wy
 e Z Wn e d
 e e ƒ ƒ ‚ n Xe Z e e d d ƒ d ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  e! d j o~d d k" l# Z# e$ e# ƒ d j o d GHe ƒ  q×e# d d j p" e# d d j p e# d d j o e ƒ  q×e# d d j o e$ e# ƒ d j o	 d  GHq×e# d d j o% e$ e# ƒ d! j o e e# d ƒ q×e# d d" j o= e$ e# ƒ d# j  o e ƒ  qÓe d$ e# d d% e# d! ƒ q×e# d d& j o3 e$ e# ƒ d! j  o e ƒ  qÓe d' e# d ƒ q×d( Ge# d GHe ƒ  n d) S(*   sh  babtools_gentoo: Some tools for working with Gentoo.
 

Usage: 
 - babtools_gentoo.py cmd [OPTIONS]
   
   for default usage, or 
   
 - babtools_gentoo.py --help
   
   for getting help
 

Avaible commands: 
 - ebuild_to_local CP
   
   CP (cathegory/package) in the simple form dev-lang/python or similar. CPVs (cathegory/package-version) aren't supported, yet. 
    
 - ebuild_download_to_local CP URL
  
   Download an ebuild from bugs.gentoo.org to the local portage tree.    
   
 - emerge_from_pypi PACKAGE
  
   Create an ebuild from a project in PyPI, put it into package.keywords and install it. 
   Honors package.keywords directories. 
   It only puts the directly named PACKAGE into package.keywords as dev-python/PACKAGE
   but doesn't put the dependencies into package.keywords. 
 

Examples: 
 - sudo babtools_gentoo.py ebuild_to_local dev-lang/python
   
   copy dev-lang/python into the local overlay
   
 - sudo babtools_gentoo.py ebuild_download_to_local games-rpg/vegastrike http://bugs.gentoo.org/attachment.cgi?id=151789
   
   Download the ebuild for games-rpg/vegastrike from bugs.gentoo.org and digest it. 
  
 - sudo babtools_gentoo.py emerge_from_pypi magma
   
   Create an ebuild for "magma" from the PyPI and emerge it. 


Source URL (Mercurial): U{http://freehg.org/u/ArneBab/babtools_gentoo/}

PyPI URL: U{http://pypi.python.org/pypi/babtools_gentoo}
iÿÿÿÿ(   t   joint   isdirt   isfileR    (   t   makedirst   listdir(   t   copytreet   copy(   t   settingst   PORTDIRs   /usr/local/portages    /usr/portage/local/local-overlayt   PORTDIR_OVERLAYs   local overlay not found in s   /etct   portages   package.keywordsc         C   s›  t  t |  ƒ } t  t |  ƒ } t | ƒ o`t | ƒ od xA t | ƒ D]3 } t  | | ƒ } t | ƒ o t | | ƒ qE qE Wt o d G| Gd G| GHq‡q—t t  t |  i d ƒ d ƒ ƒ oC t	 | t  t |  i d ƒ d ƒ ƒ t o d G| Gd G| GHq‡q—t
 t  t t  t |  i d ƒ d ƒ ƒ ƒ t o, d Gt  t t  t |  i d ƒ d ƒ ƒ GHn t	 | | ƒ t o d G| Gd G| GHq—n t d	 ƒ ‚ d
 S(   sg   Copy the ebuild dir to the local overlay.
    
    TODO implement cleanly, no hardcoded paths and such.s   copied all contents ofs   over tot   /i    s
   copied dirs   created the cathegory dirs   and copied the dirt   tos5   package atom doesn't point to an existing ebuild dir.N(   R    t   PORTAGE_DIRt   PORTAGE_LOCALR   R   R   R   t   verboset   splitR   R   t	   Exception(   t   CPt
   EBUILD_DIRt   EBUILD_DIR_LOCALt   it   FILEPATH_TMP(    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pyt   copy_ebuild_to_local_overlayc   s,     ##),c         C   sç   t  t |  ƒ } d d k l } | | ƒ } | i i ƒ  d } } | i d ƒ d i ƒ  d d !} t |  ƒ t	 t  | | ƒ d ƒ } | i
 | i ƒ  ƒ | i ƒ  d d k l }	 |	 | ƒ d d k l }
 |
 d	 | d
 d t ƒd S(   sF   Download an ebuild from a given URL to the given CP in the local tree.iÿÿÿÿ(   t   urlopent   ;i   i   t   w(   t   chdir(   t   calls   ebuild s    digestt   shellN(   R    R   t   urllib2R   t   headerst   valuesR   t   stript   create_local_ebuild_dirt   opent   writet   readt   closet   osR   t
   subprocessR   t   True(   R   t   URLR   R   t   urlfilet   name_headert   namet   filenamet   diskfileR   R   (    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pyt    download_ebuild_to_local_overlay‘   s     


c         C   s.   t  t |  ƒ } t | ƒ p t | ƒ n d S(   sE   Create the ebuild dir in the local portage tree, if it doesn't exist.N(   R    R   R   R   (   R   R   (    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pyR"   ¹   s    c         C   sù   d } | d |  7} t  t ƒ ou t t t d ƒ d ƒ } |  | i ƒ  j o3 | i ƒ  t t t d ƒ d ƒ } | i | ƒ n
 |  d GH| i ƒ  n` t t d ƒ } |  | i ƒ  j o* | i ƒ  t t d ƒ } | i | ƒ n
 |  d GH| i ƒ  d S(   sQ   Add a cathegory/package to package.keywords. Honor package.keywords directories. s#   
# Package added by babtools_gentoos   
t   pythont   rt   as'    is already inside the package.keywordsN(   R   t   PACKAGE_KEYWORDSR#   R    R%   R&   R$   (   R   t   string_to_writet   python_keywords_filet   keywords_file(    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pyt   add_to_package_keywordsÃ   s"    
	
	c         C   s¥   d d k  l } d |  } t o d | d GHn | d |  d t ƒt o d | d	 GHn t | ƒ t o d
 | d GHn | d | d t ƒd | d GHd S(   sß   Create an ebuild directly from PyPI.
    
        - Create the ebuild with g-pypi
        - put it into package.keywords (if it's a dir, put it into the file python inside the dir)
        - emerge it via portage. 
        iÿÿÿÿ(   R   s   dev-python/s   Creating ebuild for s    via g-pypi.s
   g-pypi -o R   s	   
Putting s6    into the package.keywords, if it isn't already there.s   
Finally emerging t   .s   emerge s   
Finished installing N(   R(   R   R   R)   R8   (   t   PACKAGER   R   (    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pyt   emerge_from_pypiç   s    

c           C   s8   t  i d ƒ d GHd GHd GHt ƒ  d GHd GHt ƒ  d S(   s$   Display help and a list of commands.s   

i   t    N(   t   __doc__R   t   list_commandst   print_examples(    (    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pyt
   print_help  s    c           C   s   t  i d ƒ d GHd S(   s   List avaible commands.s   

i   N(   R=   R   (    (    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pyR>     s    c           C   s   t  i d ƒ d GHd S(   s   List avaible commands.s   

i   N(   R=   R   (    (    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pyR?     s    c          C   s   d d k  l }  |  ƒ  d  S(   Niÿÿÿÿ(   t   testmod(   t   doctestRA   (   RA   (    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pyt   _test   s    t   __main__(   t   argvi   s=   We need a command as argument, for example 'ebuild_to_local'.t   helps   --helps   -ht   ebuild_to_locali   sP   'ebuild_to_local' needs a valid package atom as argument (like dev-lang/python).i   t   ebuild_download_to_locali   R   R*   R;   R:   s   command not recognized:N(%   R=   t   os.pathR    R   R   R'   R   R   t   shutilR   R   R
   R   t   portage_settingsR   t   possible_local_overlaysR   t   local_overlayR   R   t   strR)   R   R4   R   R0   R"   R8   R;   R@   R>   R?   RC   t   __name__t   sysRE   t   len(    (    (    sR   /home/arne/Dokumente/eigenes/Programme/babtools/babtools_gentoo/babtools_gentoo.pys   <module>D   s\   "
 
	.	(	
	$	 				3$	$