ó
æ0ÌRc           @   s  d  Z  d d l m Z m Z m Z m Z d d l m Z m Z d d l	 m	 Z	 d d l
 Z y d d l m Z Wn e k
 r‡ d Z n Xd d l Z d Z d	 „  Z d
 „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sH   handles command line and config file option parsing for the gbp commandsiÿÿÿÿ(   t   OptionParsert   OptionGroupt   Optiont   OptionValueError(   t   SafeConfigParsert   NoSectionError(   t   copyN(   t   gbp_versions   [Unknown version]sé   
Repository does not have branch '%s' for upstream sources. If there is none see
file:///usr/share/doc/git-buildpackage/manual-html/gbp.import.html#GBP.IMPORT.CONVERT
on howto create it otherwise use --upstream-branch to specify it.
c         C   s"   t  j j | ƒ } t  j j | ƒ S(   N(   t   ost   patht
   expandvarst
   expanduser(   t   optiont   optt   value(    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   expand_path#   s    c         C   sH   y t  j j | ƒ } Wn' t k
 r? t d | | f ƒ ‚ n X| Sd  S(   Ns   option %s: invalid value: %r(   t   gbpt   tristatet   Tristatet	   TypeErrorR   (   R   R   R   t   val(    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   check_tristate'   s    t	   GbpOptionc           B   s8   e  Z e j d Z e e j ƒ Z e e d  <e e d <RS(   R	   R   (   s   paths   tristate(   t   __name__t
   __module__R   t   TYPESR   t   TYPE_CHECKERR   R   (    (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyR   0   s   
t   GbpOptionParserc           B   s   e  Z d  Z iA d d 6d d 6d d 6d d 6d d	 6d d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6g  d 6d  d! 6d" d# 6d$ d% 6d d& 6d d' 6d d( 6d d) 6d d* 6d d+ 6d, d- 6d d. 6d/ d0 6d d1 6d d2 6d3 d4 6d5 d6 6d7 d8 6d d9 6d d: 6d d; 6d d< 6d= d> 6d d? 6d d@ 6d3 dA 6d dB 6d dC 6dD dE 6d dF 6d3 dG 6d dH 6d dI 6d dJ 6d dK 6d dL 6d dM 6dN dO 6d dP 6d dQ 6d dR 6d dS 6d dT 6d dU 6d dV 6Z i0 dW d 6dX d 6dY d 6dZ d 6d[ d 6d\ d 6d] d 6d^ d 6d_ d 6d` d 6da d	 6db d
 6dc d 6dd d1 6de d. 6df d+ 6dg d) 6dh d* 6di d' 6dj d8 6dk d9 6dl d: 6dm d; 6dn d> 6do d? 6dp d< 6dq d@ 6dr dA 6ds dB 6dt dE 6du dF 6dv dG 6dw dH 6dx dI 6dy dJ 6dz dK 6d{ dL 6d| dM 6d} d 6d~ d 6d dO 6d€ dP 6d dQ 6d‚ dR 6dƒ dS 6d„ dT 6d… dU 6d† dV 6Z d‡ dˆ d‰ dŠ d‹ g Z e dŒ „  ƒ Z d „  Z d d” g  dŽ „ Z
 d „  Z d „  Z d‘ „  Z d” d’ „ Z d“ „  Z RS(•   sS  
    Handles commandline options and parsing of config files
    @ivar command: the gbp command we store the options for
    @type command: string
    @ivar prefix: prefix to prepend to all commandline options
    @type prefix: string
    @ivar config: current configuration parameters
    @type config: dict
    @cvar defaults: defaults value of an option if not in the config file or
    given on the command line
    @type defaults: dict
    @cvar help: help messages
    @type help: dict
    @cvar def_config_files: list of default config files we parse
    @type def_config_files: list
    t   masters   debian-brancht   upstreams   upstream-brancht   TAGs   upstream-treet   Falses   pristine-tars   pristine-tar-commits   filter-pristine-tars	   sign-tagss   force-creates   no-create-origt    t   keyidt   posttagt	   postbuildt   prebuildt
   postexportt
   postimportt   Truet   hookss   debian/%(version)ss
   debian-tags   upstream/%(version)ss   upstream-tags%   Imported Upstream version %(version)ss
   import-msgs(   Update changelog for %(version)s releases
   commit-msgt   filters   snapshot + 1s   snapshot-numbers   --no-mergess   git-logt   HEADt   exports
   export-dirt   overlays   tarball-dirs
   ignore-news   ignore-brancht   metas	   Closes|LPs   meta-closest   fullt   0s	   id-lengths
   git-authors   ignore-regext   autot   compressiont   9s   compression-levels1   ssh://git.debian.org/git/collab-maint/%(pkg)s.gits   remote-url-patternt
   multimaints   multimaint-merget   pbuildert   qemubuildert   sidt   distt   archt   interactivet   colors   color-schemet   customizationst   releases   spawn-editors   patch-numberst   notifyt   merget   tracks   author-is-committers   author-date-is-committer-dates   create-missing-branchest
   submodulesi   s   time-machines   pbuilder-autoconfs   pbuilder-optionss   template-dirs   remote-configs   allow-unauthenticateds   symlink-origt   purgesO   Branch the Debian package is being developed on, default is '%(debian-branch)s's1   Upstream branch, default is '%(upstream-branch)s's[   Where to generate the upstream tarball from (tag or branch), default is '%(upstream-tree)s's:   Format string for debian tags, default is '%(debian-tag)s's>   Format string for upstream tags, default is '%(upstream-tag)s's0   Whether to sign tags, default is '%(sign-tags)s's3   GPG keyid to sign tags with, default is '%(keyid)s'sa   Format string for commit message used to commit the upstream tarball, default is '%(import-msg)s'sZ   Format string for commit messag used to commit, the changelog, default is '%(commit-msg)s'sF   Use pristine-tar to create orig tarball, default is '%(pristine-tar)s's}   When generating a tarball commit it to the pristine-tar branch '%(pristine-tar-commit)s' default is '%(pristine-tar-commit)s'sT   Filter pristine-tar when filter option is used, default is '%(filter-pristine-tar)s'sV   Files to filter out during import (can be given multiple times), default is %(filter)ssU   Use name and email from git-config for changelog trailer, default is '%(git-author)s'sU   Include the full commit message instead of only the first line, default is '%(full)s's9   Parse meta tags in commit messages, default is '%(meta)s'sM   Build with uncommited changes in the source tree, default is '%(ignore-new)s'sN   Build although debian-branch != current branch, default is '%(ignore-branch)s'sK   extract orig tarball when using export-dir option, default is '%(overlay)s'sM   Remote url pattern to create the repo at, default is '%(remote-url-pattern)s's6   Note multiple maintainers, default is '%(multimaint)s's>   Merge commits by maintainer, default is '%(multimaint-merge)s's;   Invoke git-pbuilder for building, default is '%(pbuilder)s'sJ   Build for this distribution when using git-pbuilder, default is '%(dist)s'sJ   Build for this architecture when using git-pbuilder, default is '%(arch)s'sO   Invoke git-pbuilder with qemubuilder for building, default is '%(qemubuilder)s's7   Run command interactively, default is '%(interactive)s's5   Whether to use colored output, default is '%(color)s'sÈ   Colors to use in output (when color is enabled), format is '<debug>:<info>:<warning>:<error>', e.g. 'cyan:34::'. Numerical values and color names are accepted, empty fields indicate using the default.sZ   Whether to spawn an editor after adding the changelog entry, default is '%(spawn-editor)s's;   Whether to number patch files, default is %(patch-numbers)ssO   Whether to send a desktop notification after the build, default is '%(notify)s'sN   After the import merge the result to the debian branch, default is '%(merge)s's;   Set up tracking for remote branches, default is '%(track)s'sX   Use the authors's name also as the comitter's name, default is '%(author-is-committer)s's]   Use the authors's date as the comitter's date, default is '%(author-date-is-committer-date)s'sO   Create missing branches automatically, default is '%(create-missing-branches)s'sQ   Transparently handle submodules in the upstream tree, default is '%(submodules)s's?   hook run after a successful import, default is '%(postimport)s's.   Enable running all hooks, default is %(hooks)ssu   don't try head commit only to apply the patch queue but look TIME_MACHINE commits back, default is '%(time-machine)d'sN   Wheter to configure pbuilder automatically, default is '%(pbuilder-autoconf)s's>   Options to pass to pbuilder, default is '%(pbuilder-options)s'sB   Template directory used by git init, default is '%(template-dir)s'sa   Remote defintion in gbp.conf used to create the remote repository, default is '%(remote-config)s'sS   Don't verify integrity of downloaded source, default is '%(allow-unauthenticated)s'sp   Whether to creat a symlink from the upstream tarball to the orig.tar.gz if needed, default is '%(symlink-orig)s's>   Purge exported package build directory. Default is '%(purge)s's   /etc/git-buildpackage/gbp.confs   ~/.gbp.confs	   .gbp.confs   debian/gbp.confs   .git/gbp.confc         C   sS   t  j j d ƒ } | r' | j d ƒ n |  j } g  | D] } t  j j | ƒ ^ q7 S(   s  
        Get list of config files from the I{GBP_CONF_FILES} environment
        variable.

        @return: list of config files we need to parse
        @rtype: C{list}

        >>> conf_backup = os.getenv('GBP_CONF_FILES')
        >>> if conf_backup is not None: del os.environ['GBP_CONF_FILES']
        >>> files = GbpOptionParser.get_config_files()

        # Remove the ~-expanded one
        >>> del files[1]
        >>> files
        ['/etc/git-buildpackage/gbp.conf', '.gbp.conf', 'debian/gbp.conf', '.git/gbp.conf']

        >>> os.environ['GBP_CONF_FILES'] = 'test1:test2'
        >>> GbpOptionParser.get_config_files()
        ['test1', 'test2']
        >>> del os.environ['GBP_CONF_FILES']
        >>> if conf_backup is not None: os.environ['GBP_CONF_FILES'] = conf_backup
        t   GBP_CONF_FILESt   :(   R   t   environt   gett   splitt   def_config_filesR	   R   (   t   klasst   envvart   filest   f(    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   get_config_files  s    c         C   s%  t  ƒ  } t |  j j ƒ |  _ | j |  j ƒ |  j j t | j ƒ  ƒ ƒ |  j j	 d ƒ sn |  j j	 d ƒ r¾ |  j } | j
 | ƒ r® |  j j t | j | d t ƒƒ ƒ n  |  j d } nj x^ d d g D]P } d | |  j f } | j
 | ƒ rË |  j j t | j | d t ƒƒ ƒ qË qË W|  j } | j
 | ƒ r_|  j j t | j | d t ƒƒ ƒ n  xX |  j D]M } | j
 | ƒ r¦|  j j t | j | d t ƒƒ ƒ qit d | ƒ ‚ qiW|  j d	 r|  j d	 j	 d
 ƒ rút |  j d	 ƒ |  j d	 <q!|  j d	 g |  j d	 <n g  |  j d	 <d S(   sc   
        Parse the possible config files and set appropriate values
        default values
        s   gbp-s   git-t   rawi   R   t   gits   %s-%ss&   Mandatory section [%s] does not exist.R)   t   [N(   R   t   dictt	   __class__t   defaultst   configt   readt   config_filest   updatet   commandt
   startswitht   has_sectiont   itemsR'   t   sectionsR   t   eval(   t   selft   parsert   oldcmdt   cmdt   prefixt   section(    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   _parse_config_files4  s6    		(,	((c      
   C   sm   | |  _  | |  _ | |  _ i  |  _ |  j ƒ  |  _ |  j ƒ  t j |  d t	 d | d d |  j  t
 f ƒd S(   s—  
        @param command: the command to build the config parser for
        @type command: C{str}
        @param prefix: A prefix to add to all command line options
        @type prefix: C{str}
        @param usage: a usage description
        @type usage: C{str}
        @param sections: additional (non optional) config file sections
            to parse
        @type sections: C{list} of C{str}
        t   option_classt   usaget   versions   %s %sN(   RW   R[   Ra   RS   RL   RU   Rc   R    t   __init__R   R   (   R]   RW   Ra   Re   R[   (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyRg   d  s    				
c         O   sA   t  } y | d d k r" t } n  Wn t k
 r< t  } n X| S(   s   is option_name a boolean optiont   actiont
   store_truet   store_false(   Ri   Rj   (   R   R'   t   KeyError(   R]   t   dummyt   unusedt   kwargst   ret(    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   _is_booleanz  s    
c         C   s°   | j  d ƒ r" | d } | } n | } d | } y |  j | } Wn t k
 rc |  j | } n X| j ƒ  d k r d } n' | j ƒ  d k rš d	 } n t d
 ƒ ‚ t | ƒ S(   sj   
        get default for boolean options
        this way we can handle no-foo=True and foo=False
        s   no-i   s   no-%st   truet   1R'   t   falseR/   R   s%   Boolean options must be True or False(   Rq   Rr   (   Rs   R/   (   RX   RS   Rk   t   lowert
   ValueErrorR\   (   R]   t   option_namet   post   negt   defaultR   (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   _get_bool_default„  s    
	
		c         K   s8   |  j  |  | |  r' |  j | ƒ } n |  j | } | S(   s   get the default value(   Rp   Rz   RS   (   R]   Rv   Rn   Ry   (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   get_default  s    c      
   K   s_   | s |  j  | } n  t j |  d |  j | f d | d |  j | |  d | |  j | d S(   s:  
        set a option for the command line parser, the default is read from the config file
        @param option_name: name of the option
        @type option_name: string
        @param dest: where to store this option
        @type dest: string
        @param help: help text
        @type help: string
        s   --%s%st   destRy   t   helpN(   R}   R    t
   add_optionRa   R{   RS   (   R]   Rv   R|   R}   Rn   (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   add_config_file_option¥  s
    
"c      	   C   sY   |  j  d | d | d d ƒ d |  j | f } |  j  d d | d | d | d d ƒ d  S(	   NRv   R|   Rh   Ri   s   negates '--%s%s's   no-%sR}   Rj   (   R   Ra   (   R]   Rv   R|   t   neg_help(    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   add_boolean_config_file_optionµ  s    N(   R   R   t   __doc__RR   R}   RG   t   classmethodRL   Rc   t   NoneRg   Rp   Rz   R{   R   R   (    (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyR   6   s   


		0	
		t   GbpOptionGroupc           B   s   e  Z d d  „ Z d „  Z RS(   c      
   K   sk   | s |  j  j | } n  t j |  d |  j  j | f d | d |  j  j | |  d | |  j  j | d S(   s:  
        set a option for the command line parser, the default is read from the config file
        @param option_name: name of the option
        @type option_name: string
        @param dest: where to store this option
        @type dest: string
        @param help: help text
        @type help: string
        s   --%s%sR|   Ry   R}   N(   R^   R}   R   R~   Ra   R{   RS   (   R]   Rv   R|   R}   Rn   (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyR   ¼  s
    
%c      	   C   s\   |  j  d | d | d d ƒ d |  j j | f } |  j  d d | d | d | d d ƒ d  S(	   NRv   R|   Rh   Ri   s   negates '--%s%s's   no-%sR}   Rj   (   R   R^   Ra   (   R]   Rv   R|   R€   (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyR   Ì  s    N(   R   R   R„   R   R   (    (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyR…   »  s   t   GbpOptionParserDebianc           B   s8   e  Z d  Z e e j ƒ Z e j i d d 6d d 6ƒ RS(   sR   
    Handles commandline options and parsing of config files for Debian tools
    s   debuild -i -It   builders	   /bin/truet   cleaner(   R   R   R‚   RP   R   RR   RV   (    (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyR†   Ò  s
   	(   R‚   t   optparseR    R   R   R   t   ConfigParserR   R   R   t   os.pathR   t   gbp.versionR   t   ImportErrort   gbp.tristateR   t   no_upstream_branch_msgR   R   R   R   R…   R†   (    (    (    s.   /usr/lib/python2.7/dist-packages/gbp/config.pyt   <module>   s"   "
			ÿ †