
ryMc           @   s  d  Z  d d l Z d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l	 Z	 d d l
 m Z m Z m Z d d l m Z d d l m Z d d l m Z y d d	 l m Z Wn e k
 r n Xd
 Z d   Z d e f d     YZ d   Z e d  Z e d  Z d e f d     YZ  d   Z! d   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  e f d!     YZ* d" e' f d#     YZ+ d$ e f d%     YZ, d&   Z- d' e f d(     YZ. d) e f d*     YZ/ d+ e f d,     YZ0 d-   Z1 d. e f d/     YZ2 d0 e f d1     YZ3 d2 e f d3     YZ4 d S(4   sL  
Twisted's automated release system.

This module is only for use within Twisted's release system. If you are anyone
else, do not use it. The interface and behaviour will change without notice.

Only Linux is supported by this code.  It should not be used by any tools
which must run on multiple platforms (eg the setup.py script).
iN(   t   date(   t   mkdtemp(   t   PIPEt   STDOUTt   Popen(   t   Version(   t   FilePath(   t   twisted_subprojects(   t   lorei  c         C   sz   t  |  d t d t } | j j   } | j   } | d k  rU t d | |   n! | d k rv t | d |   n  | S(   s;  
    Execute a vector of arguments.

    @type args: C{list} of C{str}
    @param args: A list of arguments, the first of which will be used as the
        executable to run.

    @rtype: C{str}
    @return: All of the standard output.

    @raise CommandFailed: when the program exited with a non-0 exit code.
    t   stdoutt   stderri    N(   R   R   R   R	   t   readt   waitt   CommandFailedt   None(   t   argst   processR	   t   exitCode(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt
   runCommand(   s    R   c           B   s   e  Z d  Z d   Z RS(   sY  
    Raised when a child process exits unsuccessfully.

    @type exitStatus: C{int}
    @ivar exitStatus: The exit status for the child process.

    @type exitSignal: C{int}
    @ivar exitSignal: The exit signal for the child process.

    @type output: C{str}
    @ivar output: The bytes read from stdout and stderr of the child process.
    c         C   s5   t  j |  | | |  | |  _ | |  _ | |  _ d  S(   N(   t	   Exceptiont   __init__t
   exitStatust
   exitSignalt   output(   t   selfR   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR   L   s    		(   t   __name__t
   __module__t   __doc__R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR   ?   s   c         C   s$   t  | i | j   |  j   6 d S(   s]   
    Replace the C{old} version number with the C{new} one in the given
    C{filename}.
    N(   t   replaceInFilet   base(   t   oldt   newt   filename(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   _changeVersionInFileT   s    c         C   sc   | d k r t j   } n  | j t } | |  j k r@ d } n |  j d } t |  j | | d  S(   s   
    Calculate the version number for a new release of Twisted based on
    the previous version number.

    @param version: The previous version number.
    @param now: (optional) The current date.
    i    i   N(	   R   R    t   todayt   yeart   VERSION_OFFSETt   majort   minorR   t   package(   t   versiont   nowR%   R&   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   getNextVersion]   s    
	c         C   sL  | s t  j   j d  } n  x't |   D]} | j j   d k rO d } n d | j j   } | j   } t | | j | j	 | j
 d | j } | j rt   } | j |  j d  | j |  | | |  | j | j j d  j d  | j |  | | |  n  | d k r7t | | |  j d  j  n  | j |  q+ Wd S(	   sk  
    Change the version of all projects (including core and all subprojects).

    If the current version of a project is pre-release, then also change the
    versions in the current NEWS entries for that project.

    @type root: L{FilePath}
    @param root: The root of the Twisted source tree.
    @type versionTemplate: L{Version}
    @param versionTemplate: The version of all projects.  The name will be
        replaced for each respective project.
    @type today: C{str}
    @param today: A YYYY-MM-DD formatted string. If not provided, defaults to
        the current day, according to the system clock.
    s   %Y-%m-%dt   twisteds   twisted.t
   prereleaset   NEWSt   topfilest   READMEN(   R    R"   t   strftimet   findTwistedProjectst	   directoryt   basenamet
   getVersionR   R%   R&   t   microR,   t   NewsBuildert   _changeNewsVersiont   childt   _getNewsNameR!   t   patht   updateVersion(   t   roott   versionTemplateR"   t   projectt   packageNamet
   oldVersiont
   newVersiont   builder(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   changeAllProjectVersionsq   s.    			
t   Projectc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s>  
    A representation of a project that has a version.

    @ivar directory: A L{twisted.python.filepath.FilePath} pointing to the base
        directory of a Twisted-style Python package. The package should contain
        a C{_version.py} file and a C{topfiles} directory that contains a
        C{README} file.
    c         C   s   | |  _  d  S(   N(   R2   (   R   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR      s    c         C   s   d |  j  j |  j f S(   Ns   %s(%r)(   t	   __class__R   R2   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   __repr__   s    c         C   s*   i  } t  |  j j d  j |  | d S(   sz   
        @return: A L{Version} specifying the version number of the project
        based on live python modules.
        s   _version.pyR(   (   t   execfileR2   R8   R:   (   R   t	   namespace(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR4      s    c         C   sT   |  j    } t |  j j d  j |  t | | |  j j d  j d  j  d S(   sz   
        Replace the existing version numbers in _version.py and README files
        with the specified version.
        s   _version.pyR.   R/   N(   R4   t   replaceProjectVersionR2   R8   R:   R!   (   R   R(   R@   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR;      s    (   R   R   R   R   RF   R4   R;   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRD      s
   			
c         C   sU   g  } xH |  j    D]: } | j   d k r | j   } | j t |   q q W| S(   s   
    Find all Twisted-style projects beneath a base directory.

    @param baseDirectory: A L{twisted.python.filepath.FilePath} to look inside.
    @return: A list of L{Project}.
    R.   (   t   walkR3   t   parentt   appendRD   (   t   baseDirectoryt   projectst   filePatht   projectDirectory(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR1      s    c         C   s:   x3 t  |   D]% } | j t | j   d |  q Wd S(   sR  
    Update the version information for Twisted and all subprojects to the
    date-based version number.

    @param baseDirectory: Where to look for Twisted. If None, the function
        infers the information from C{twisted.__file__}.
    @param now: The current date (as L{datetime.date}). If None, it defaults
        to today.
    R)   N(   R1   R;   R*   R4   (   RM   R)   R>   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   updateTwistedVersionInformation   s    
c         C   sQ   |  j  d k	 r" d |  j  f } n d } d |  j |  j |  j |  j | f } | S(   sh   
    Generate the data to be placed into a _version.py file.

    @param version: A version object.
    s   , prerelease=%rt    s   # This is an auto-generated file. Do not edit it.
from twisted.python import versions
version = versions.Version(%r, %s, %s, %s%s)
N(   R,   R   R'   R%   R&   R5   (   R(   R,   t   data(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   generateVersionFileData   s
    %c         C   s0   t  |  d  } | j t |   | j   d S(   s  
    Write version specification code into the given filename, which
    sets the version to the given version number.

    @param filename: A filename which is most likely a "_version.py"
        under some Twisted project.
    @param newversion: A version object.
    t   wN(   t   opent   writeRT   t   close(   R    t
   newversiont   f(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRI      s    c         C   s   t  j |  |  d  t |  d  } | j   } | j   x, | j   D] \ } } | j | |  } qG Wt |  d d  } | j |  | j   t  j |  d |   t  j |  d  d S(   sP   
    I replace the text `oldstr' with `newstr' in `filename' using science.
    s   .baks   .newRU   N(	   t   ost   renameRV   R   RX   t   itemst   replaceRW   t   unlink(   R    t   oldToNewRZ   t   dt   kt   v(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s    

t   NoDocumentsFoundc           B   s   e  Z d  Z RS(   s3   
    Raised when no input documents are found.
    (   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRd   !  s   t   LoreBuilderMixinc           B   s   e  Z d  Z d   Z RS(   s4   
    Base class for builders which invoke lore.
    c         C   s1   t  j   } | j d g |  t  j |  d S(   s   
        Run lore with the given arguments.

        @param arguments: A C{list} of C{str} giving command line arguments to
            lore which should be used.
        s   --nullN(   R   t   Optionst   parseOptionst   runGivenOptions(   R   t	   argumentst   options(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR   ,  s    (   R   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRe   (  s   t
   DocBuilderc           B   s&   e  Z d  Z d e d  Z d   Z RS(   s3   
    Generate HTML documentation for projects.
    c      	   C   s   |  j  | |  } | j d  } g  | D] }	 |	 j ^ q( }
 |
 sY t d | f   n  | d	 k	 rx d d | g } n g  } | j d d | j f d d d d | f d | g |
  |  j |  | r x | D] } | j   q Wn  d	 S(
   s)  
        Build the documentation in C{docDir} with Lore.

        Input files ending in .xhtml will be considered. Output will written as
        .html files.

        @param version: the version of the documentation to pass to lore.
        @type version: C{str}

        @param resourceDir: The directory which contains the toplevel index and
            stylesheet file for this section of documentation.
        @type resourceDir: L{twisted.python.filepath.FilePath}

        @param docDir: The directory of the documentation.
        @type docDir: L{twisted.python.filepath.FilePath}

        @param template: The template used to generate the documentation.
        @type template: L{twisted.python.filepath.FilePath}

        @type apiBaseURL: C{str} or C{NoneType}
        @param apiBaseURL: A format string which will be interpolated with the
            fully-qualified Python name for each API link.  For example, to
            generate the Twisted 8.0.0 documentation, pass
            C{"http://twistedmatrix.com/documents/8.0.0/api/%s.html"}.

        @param deleteInput: If True, the input documents will be deleted after
            their output is generated.
        @type deleteInput: C{bool}

        @raise NoDocumentsFound: When there are no .xhtml files in the given
            C{docDir}.
        s   *.xhtmls   No input documents found in %ss   --configs   baseurl=s   template=%ss	   ext=.htmls
   version=%ss	   --linkrelN(   t
   getLinkrelt   globChildrenR:   Rd   R   t   extendR   t   remove(   R   R(   t   resourceDirt   docDirt   templatet
   apiBaseURLt   deleteInputt   linkrelt
   inputFilest   xt	   filenamesRi   t	   inputFile(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   build>  s     "c         C   s.   | | k r& d j  t | |   d Sd Sd S(   s  
        Calculate a value appropriate for Lore's --linkrel option.

        Lore's --linkrel option defines how to 'find' documents that are
        linked to from TEMPLATE files (NOT document bodies). That is, it's a
        prefix for links ('a' and 'link') in the template.

        @param resourceDir: The directory which contains the toplevel index and
            stylesheet file for this section of documentation.
        @type resourceDir: L{twisted.python.filepath.FilePath}

        @param docDir: The directory containing documents that must link to
            C{resourceDir}.
        @type docDir: L{twisted.python.filepath.FilePath}
        t   /RR   N(   t   joint   filePathDelta(   R   Rp   Rq   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRl   s  s    N(   R   R   R   R   t   FalseRz   Rl   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRk   9  s   4t
   ManBuilderc           B   s   e  Z d  Z d   Z RS(   s?   
    Generate man pages of the different existing scripts.
    c         C   st   | j  d  } g  | D] } | j ^ q } | sG t d | f   n  d d d d d d g | } |  j |  d	 S(
   s  
        Generate Lore input files from the man pages in C{manDir}.

        Input files ending in .1 will be considered. Output will written as
        -man.xhtml files.

        @param manDir: The directory of the man pages.
        @type manDir: L{twisted.python.filepath.FilePath}

        @raise NoDocumentsFound: When there are no .1 files in the given
            C{manDir}.
        s   *.1s   No manual pages found in %ss   --inputt   mans   --outputR   s   --configs   ext=-man.xhtmlN(   Rm   R:   Rd   R   (   R   t   manDirRv   Rw   Rx   Ri   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRz     s    (   R   R   R   Rz   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s   t
   APIBuilderc           B   s   e  Z d  Z d   Z RS(   s   
    Generate API documentation from source files using
    U{pydoctor<http://codespeak.net/~mwh/pydoctor/>}.  This requires
    pydoctor to be installed and usable (which means you won't be able to
    use it with Python 2.3).
    c         C   s`   d d l  m } | d | d | d d d | j   j d | d	 | j d
 | j d d d g  d S(   sh  
        Call pydoctor's entry point with options which will generate HTML
        documentation for the specified package's API.

        @type projectName: C{str}
        @param projectName: The name of the package for which to generate
            documentation.

        @type projectURL: C{str}
        @param projectURL: The location (probably an HTTP URL) of the project
            on the web.

        @type sourceURL: C{str}
        @param sourceURL: The location (probably an HTTP URL) of the root of
            the source browser for the project.

        @type packagePath: L{FilePath}
        @param packagePath: The path to the top-level of the package named by
            C{projectName}.

        @type outputPath: L{FilePath}
        @param outputPath: An existing directory to which the generated API
            documentation will be written.
        i(   t   mains   --project-names   --project-urls   --system-classs#   pydoctor.twistedmodel.TwistedSystems   --project-base-dirs   --html-viewsource-bases   --add-packages   --html-outputs   --html-write-function-pagess   --quiets   --make-htmlN(   t   pydoctor.driverR   RK   R:   (   R   t   projectNamet
   projectURLt	   sourceURLt   packagePatht
   outputPathR   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRz     s    		(   R   R   R   Rz   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s   t   BookBuilderc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sQ  
    Generate the LaTeX and PDF documentation.

    The book is built by assembling a number of LaTeX documents.  Only the
    overall document which describes how to assemble the documents is stored
    in LaTeX in the source.  The rest of the documentation is generated from
    Lore input files.  These are primarily XHTML files (of the particular
    Lore subset), but man pages are stored in GROFF format.  BookBuilder
    expects all of its input to be Lore XHTML format, so L{ManBuilder}
    should be invoked first if the man pages are to be included in the
    result (this is determined by the book LaTeX definition file).
    Therefore, a sample usage of BookBuilder may look something like this::

        man = ManBuilder()
        man.build(FilePath("doc/core/man"))
        book = BookBuilder()
        book.build(
            FilePath('doc/core/howto'),
            [FilePath('doc/core/howto'), FilePath('doc/core/howto/tutorial'),
             FilePath('doc/core/man'), FilePath('doc/core/specifications')],
            FilePath('doc/core/howto/book.tex'), FilePath('/tmp/book.pdf'))
    c         C   s
   t  |  S(   s   
        Execute a command in a child process and return the output.

        @type command: C{str}
        @param command: The shell command to run.

        @raise CommandFailed: If the child process exits with an error.
        (   R   (   R   t   command(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   run  s    	c         C   se   | j    s% t d | j f   n  |  j d d d d g g  | j d  D] } | j ^ qJ  d S(   sW  
        Build LaTeX files for lore input files in the given directory.

        Input files ending in .xhtml will be considered. Output will written as
        .tex files.

        @type howtoDir: L{FilePath}
        @param howtoDir: A directory containing lore input files.

        @raise ValueError: If C{howtoDir} does not exist.
        s   %r does not exist.s   --outputt   latexs   --configt   sections   *.xhtmlN(   t   existst
   ValueErrorR:   R   Rm   (   R   t   howtoDirR8   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   buildTeX  s    	c         C   s  | j    j d  s$ t d   n  t t    } yt j   } z t j | j  d d d | j | j g } x! t	 d  D] } |  j
 |  q~ W| j    d  } | j | d  }	 | j | d	  }
 | j | d
  } |  j
 d d |
 j d d d |	 j g  |  j
 d |
 j | j g  | j |  | j   Wd t j |  XWn, | j | j   j | j        n Xd S(   s  
        Build a PDF from the given a LaTeX book document.

        @type bookPath: L{FilePath}
        @param bookPath: The location of a LaTeX document defining a book.

        @type inputDirectory: L{FilePath}
        @param inputDirectory: The directory which the inputs of the book are
            relative to.

        @type outputPath: L{FilePath}
        @param outputPath: The location to which to write the resulting book.
        s   .texs    Book filename must end with .texR   s   -interaction=nonstopmodes   -output-directory=i   is   .dvis   .pss   .pdft   dvipss   -os   -tt   letters   -Ppdft   ps2pdf13N(   R3   t   endswithR   R   R   R[   t   getcwdt   chdirR:   t   rangeR   R8   t   moveToRo   RK   (   R   t   bookPatht   inputDirectoryR   t   workPatht   startDirt   texToDVIt   it   bookBaseWithoutExtensiont   dviPatht   psPatht   pdfPath(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   buildPDF  s4    
"c         C   s   x | D] } |  j  |  q W|  j | | |  xT | D]L } xC | j   D]5 } | j   d d k rK | | k rK | j   qK qK Wq8 Wd S(   s  
        Build a PDF book from the given TeX book definition and directories
        containing lore inputs.

        @type baseDirectory: L{FilePath}
        @param baseDirectory: The directory which the inputs of the book are
            relative to.

        @type inputDirectories: C{list} of L{FilePath}
        @param inputDirectories: The paths which contain lore inputs to be
            converted to LaTeX.

        @type bookPath: L{FilePath}
        @param bookPath: The location of a LaTeX document defining a book.

        @type outputPath: L{FilePath}
        @param outputPath: The location to which to write the resulting book.
        i   s   .texN(   R   R   t   childrent   splitextRo   (   R   RM   t   inputDirectoriesR   R   t   inputDirR   R8   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRz   @  s    "(   R   R   R   R   R   R   Rz   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s
   			4R6   c           B   s   e  Z d  Z d Z d Z d Z d Z d Z i d e 6d e 6d e 6d	 e 6d
 e 6Z d Z	 d Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sh  
    Generate the new section of a NEWS file.

    The C{_FEATURE}, C{_BUGFIX}, C{_DOC}, C{_REMOVAL}, and C{_MISC}
    attributes of this class are symbolic names for the news entry types
    which are supported.  Conveniently, they each also take on the value of
    the file name extension which indicates a news entry of that type.

    @cvar _headings: A C{dict} mapping one of the news entry types to the
        heading to write out for that type of news entry.

    @cvar _NO_CHANGES: A C{str} giving the text which appears when there are
        no significant changes in a release.

    @cvar _TICKET_HINT: A C{str} giving the text which appears at the top of
        each news file and which should be kept at the top, not shifted down
        with all the other content.  Put another way, this is the text after
        which the new news text is inserted.
    s   .features   .bugfixs   .docs   .removals   .misct   Featurest   Bugfixess   Improved Documentations   Deprecations and Removalst   Others8   No significant changes have been made for this release.
sh   Ticket numbers in this file can be looked up by visiting
http://twistedmatrix.com/trac/ticket/<number>

c         C   s   t  j   j d  S(   sG   
        Return today's date as a string in YYYY-MM-DD format.
        s   %Y-%m-%d(   R    R"   R0   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   _today  s    c         C   s   g  } xo | j    D]a } t j j | j    \ } } | | k r | j t |  d j | j   j	    f  q q W| j
   | S(   s&  
        Load all the feature ticket summaries.

        @param path: A L{FilePath} the direct children of which to search
            for news entries.

        @param ticketType: The type of news entries to search for.  One of
            L{NewsBuilder._FEATURE}, L{NewsBuilder._BUGFIX},
            L{NewsBuilder._REMOVAL}, or L{NewsBuilder._MISC}.

        @return: A C{list} of two-tuples.  The first element is the ticket
            number as an C{int}.  The second element of each tuple is the
            description of the feature.
        t    (   R   R[   R:   R   R3   RL   t   intR|   t
   getContentt
   splitlinest   sort(   R   R:   t
   ticketTypet   resultsR8   R   t   ext(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   _findChanges  s    	&
c         C   s   | d d t  |  d S(   s   
        Format a header for a NEWS file.

        A header is a title with '=' signs underlining it.

        @param header: The header string to format.
        @type header: C{str}
        @return: A C{str} containing C{header}.
        s   
t   =s   

(   t   len(   R   t   header(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   _formatHeader  s    
c         C   s   | j  |  j |   d S(   s   
        Write a version header to the given file.

        @param fileObj: A file-like object to which to write the header.
        @param header: The header to write to the file.
        @type header: C{str}
        N(   RW   R   (   R   t   fileObjR   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   _writeHeader  s    c   
      C   s+  | s
 d Si  } x- | D]% \ } } | j  | g   j |  q Wx | D] } | | j   qG W| j   } | j d d    | j | d d t |  d  xv | D]n \ } } d j g  | D] } d t |  ^ q  } d | | f }	 t j	 |	 d	 d
 }	 | j |	 d  q W| j d  d S(   sy  
        Write out one section (features, bug fixes, etc) to the given file.

        @param fileObj: A file-like object to which to write the news section.

        @param header: The header for the section to write.
        @type header: C{str}

        @param tickets: A C{list} of ticket information of the sort returned
            by L{NewsBuilder._findChanges}.
        Nt   keyc         S   s   |  \ } } | d S(   Ni    (    (   t   .0t   descrt   tickets(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   <lambda>  s    s   
t   -s   , t   #s
    - %s (%s)t   subsequent_indents      (
   t
   setdefaultRL   R   R]   RW   R   R|   t   strt   textwrapt   fill(
   R   R   R   R   t   reverset   tickett   descriptiont   relatedTicketst
   ticketListt   entry(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   _writeSection  s"    #&c         C   s   | s
 d S| j  | d d t |  d  g  } x+ | D]# \ } } | j d t |   q: Wd d j |  } t j | d d } | j  | d	  d S(
   sr  
        Write out a miscellaneous-changes section to the given file.

        @param fileObj: A file-like object to which to write the news section.

        @param header: The header for the section to write.
        @type header: C{str}

        @param tickets: A C{list} of ticket information of the sort returned
            by L{NewsBuilder._findChanges}.
        Ns   
R   R   s    - s   , R   s      s   

(   RW   R   RL   R   R|   R   R   (   R   R   R   R   t   formattedTicketsR   t   ignoredR   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt
   _writeMisc  s    #c   
      C   s  g  } xT |  j  |  j |  j |  j f D]4 } |  j | |  } | r% | j | | f  q% q% W|  j | |  j  } | j   } | j d  j	 d  }	 | j
 |  j  r |	 j |  j  | t |  j  } n  |  j |	 |  | rxS | D]+ \ } } |  j |	 |  j j |  |  q Wn |	 j |  j  |	 j d  |  j |	 |  j j |  j  |  |	 j d  |	 j |  |	 j   | j d  j |  d S(   s  
        Load all of the change information from the given directory and write
        it out to the given output file.

        @param path: A directory (probably a I{topfiles} directory) containing
            change information in the form of <ticket>.<change type> files.
        @type path: L{FilePath}

        @param output: The NEWS file to which the results will be prepended.
        @type output: L{FilePath}

        @param header: The top-level header to use when writing the news.
        @type header: L{str}
        s   NEWS.newRU   s   
N(   t   _FEATUREt   _BUGFIXt   _DOCt   _REMOVALR   RL   t   _MISCR   t   siblingRV   t
   startswitht   _TICKET_HINTRW   R   R   R   t	   _headingst   gett   _NO_CHANGESR   RX   R   (
   R   R:   R   R   t   changest   partR   t   misct   oldNewst   newNews(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRz     s,    %&"
c         C   s.   | j  j   j   } | d k r* d } n  | S(   s   
        Return the name of C{project} that should appear in NEWS.

        @param project: A L{Project}
        @return: The name of C{project}.
        t   Twistedt   Core(   R2   R3   t   title(   R   R>   t   name(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR9   #  s    	c   	      c   s   t  |  } | j d d    | j   x t t g D]| } xs | D]k } | j j d  } | rs | j d  } n | j d  } |  j |  } | j   } | | | | f VqC Wq6 Wd S(   s  
        Iterate through the Twisted projects in C{baseDirectory}, yielding
        everything we need to know to build news for them.

        Yields C{topfiles}, C{news}, C{name}, C{version} for each sub-project
        in reverse-alphabetical order. C{topfile} is the L{FilePath} for the
        topfiles directory, C{news} is the L{FilePath} for the NEWS file,
        C{name} is the nice name of the project (as should appear in the NEWS
        file), C{version} is the current version string for that project.

        @param baseDirectory: A L{FilePath} representing the root directory
            beneath which to find Twisted projects for which to generate
            news (see L{findTwistedProjects}).
        @type baseDirectory: L{FilePath}
        R   c         S   s
   |  j  j S(   N(   R2   R:   (   t   proj(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR   C  s    R.   R-   N(	   R1   R   R   R~   t   TrueR2   R8   R9   R4   (	   R   RM   RN   t   aggregateNewsR>   R.   t   newsR   R(   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   _iterProjects0  s    
c         C   s\   |  j    } xI |  j |  D]8 \ } } } } |  j | | d | | j   | f  q Wd S(   s  
        Find all of the Twisted subprojects beneath C{baseDirectory} and update
        their news files from the ticket change description files in their
        I{topfiles} directories and update the news file in C{baseDirectory}
        with all of the news.

        @param baseDirectory: A L{FilePath} representing the root directory
            beneath which to find Twisted projects for which to generate
            news (see L{findTwistedProjects}).
        s   Twisted %s %s (%s)N(   R   R   Rz   R   (   R   RM   R"   R.   R   R   R(   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   buildAllT  s
    "c         C   s   |  j  d | | j   | f  } t j d t j |  t j | j    f  } | j   } | j |  }	 |	 r |	 j   }
 t | j	 i | |
 6 n  d S(   sB  
        Change all references to the current version number in a NEWS file to
        refer to C{newVersion} instead.

        @param news: The NEWS file to change.
        @type news: L{FilePath}
        @param name: The name of the project to change.
        @type name: C{str}
        @param oldVersion: The old version of the project.
        @type oldVersion: L{Version}
        @param newVersion: The new version of the project.
        @type newVersion: L{Version}
        @param today: A YYYY-MM-DD string representing today's date.
        @type today: C{str}
        s   Twisted %s %s (%s)s)   Twisted %s %s \(\d{4}-\d\d-\d\d\)\n=+\n\nN(
   R   R   t   ret   compilet   escapeR   t   searcht   groupR   R:   (   R   R   R   R@   RA   R"   t	   newHeadert   expectedHeaderRegexR   t   matcht	   oldHeader(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR7   f  s    (c         C   s=   t  |  d k r" t j d  n  |  j t | d   d S(   s  
        Build all news files.

        @param args: The command line arguments to process.  This must contain
            one string, the path to the base of the Twisted checkout for which
            to build the news.
        @type args: C{list} of C{str}
        i   s;   Must specify one argument: the path to the Twisted checkouti    N(   R   t   syst   exitR   R   (   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s    	(   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   Rz   R9   R   R   R7   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR6   ]  s4   
					!		*		$		c         C   s   d } |  j  j t j  } | j  j t j  } x7 t | |  D]& \ } } | | k re | d 7} q@ Pq@ Wd g t |  | } | | | S(   s4  
    Return a list of strings that represent C{destination} as a path relative
    to C{origin}.

    It is assumed that both paths represent directories, not files. That is to
    say, the delta of L{twisted.python.filepath.FilePath} /foo/bar to
    L{twisted.python.filepath.FilePath} /foo/baz will be C{../baz},
    not C{baz}.

    @type origin: L{twisted.python.filepath.FilePath}
    @param origin: The origin of the relative path.

    @type destination: L{twisted.python.filepath.FilePath}
    @param destination: The destination of the relative path.
    i    i   s   ..(   R:   t   splitR[   t   sept   zipR   (   t   origint   destinationt   commonItemst   path1t   path2t   elem1t   elem2R:   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR}     s    t   DistributionBuilderc           B   sW   e  Z d  Z d d l m Z d	 d  Z d   Z d   Z	 d   Z
 d   Z d   Z RS(
   s{   
    A builder of Twisted distributions.

    This knows how to build tarballs for Twisted and all of its subprojects.
    i(   R   c         C   s7   | |  _  | |  _ | |  _ t   |  _ t   |  _ d S(   s  
        Create a distribution builder.

        @param rootDirectory: root of a Twisted export which will populate
            subsequent tarballs.
        @type rootDirectory: L{FilePath}.

        @param outputDirectory: The directory in which to create the tarballs.
        @type outputDirectory: L{FilePath}

        @type apiBaseURL: C{str} or C{NoneType}
        @param apiBaseURL: A format string which will be interpolated with the
            fully-qualified Python name for each API link.  For example, to
            generate the Twisted 8.0.0 documentation, pass
            C{"http://twistedmatrix.com/documents/8.0.0/api/%s.html"}.
        N(   t   rootDirectoryt   outputDirectoryRs   R   t
   manBuilderRk   t
   docBuilder(   R   R  R  Rs   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s
    			c         C   s   |  j  j d  j d  j d  j d  } | j   d k rR |  j j |  n  | j   r y& |  j j | | | | |  j t  Wq t	 k
 r q Xn  d S(   s!  
        Generate documentation in the given path, building man pages first if
        necessary and swallowing errors (so that directories without lore
        documentation in them are ignored).

        @param path: The path containing documentation to build.
        @type path: L{FilePath}
        @param version: The version of the project to include in all generated
            pages.
        @type version: C{str}
        @param howtoPath: The "resource path" as L{DocBuilder} describes it.
        @type howtoPath: L{FilePath}
        t   doct   coret   howtos   template.tplR   N(
   R  R8   R3   R  Rz   t   isdirR  Rs   R   Rd   (   R   R:   R(   t	   howtoPatht   templatePath(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   _buildDocInDir  s    c            sO  d | f     f d   } |  j  j   d  } t j j | j d  } |  j j d  } | j   r xY | j   D]H } | j   ru x3 | j	   D]" } |  j
 | | | j d   q Wqu qu Wn  xW |  j j d  j   D]= } | j   d k r | j | j | d | j     q q Wx |  j j d	  j   D]y }	 |	 j   d
 k rx^ |	 j   D]+ }
 | j |
 j | d	 d
 |
 j     q\Wq7| j |	 j | d	 |	 j     q7WxB |  j j d  j   D]( } | j | j | d | j     qWxE |  j j   D]4 } | j   s	| j | j | | j     q	q	W| j   | S(   s  
        Build the main Twisted distribution in C{Twisted-<version>.tar.bz2}.

        bin/admin is excluded.

        @type version: C{str}
        @param version: The version of Twisted to build.

        @return: The tarball file.
        @rtype: L{FilePath}.
        s
   Twisted-%sc             s   d j    f |   S(   NR{   (   R|   (   R   (   t   releaseName(    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s    s   .tar.bz2s   w:bz2R  R	  t   bint   adminR+   t   plugins(   R  R8   t   tarfilet   TarFileRV   R:   R  R
  R   RJ   R  R3   t   addRX   (   R   R(   t	   buildPatht
   outputFilet   tarballt   docPatht   subProjectDirR8   t   binthingt	   submodulet   pluginRq   t   toplevel(    (   R  s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   buildTwisted  s:    &&
c            s  d | f   |  j  j   d  }   f d   } |  j d | |  } xQ |  j j d  j   D]7 } | j   s` | j | j | d | j     q` q` Wx |  j j d  j   D] } | j   d k r<x | j   D]\ } xS |  j	 D]# } | j   d | f k r Pq q W| j | j | d d | j     q Wq | j   |  j	 d	 g k r | j | j | d | j     q q W| j |  j j d  j d	  j    | j
   | S(
   sT  
        Build a core distribution in C{TwistedCore-<version>.tar.bz2}.

        This is very similar to L{buildSubProject}, but core tarballs and the
        input are laid out slightly differently.

         - scripts are in the top level of the C{bin} directory.
         - code is included directly from the C{twisted} directory, excluding
           subprojects.
         - all plugins except the subproject plugins are included.

        @type version: C{str}
        @param version: The version of Twisted to build.

        @return: The tarball file.
        @rtype: L{FilePath}.
        s   TwistedCore-%ss   .tar.bz2c             s   d j    f |   S(   NR{   (   R|   (   R   (   R  (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR   3  s    R  R  R+   R  s   twisted_%s.pyR.   (   R  R8   t   _createBasicSubprojectTarballR  R   R
  R  R:   R3   t   subprojectsRX   (   R   R(   R  R  R  R:   R  t
   subproject(    (   R  s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt	   buildCore  s.    )	)!
c            s  d | j    | f   |  j j   d  }   f d   } |  j j d  j |  } |  j | | |  } | j | j d  j    xN | j   D]@ } | j   } | d k r | j | j | d | |   q q W|  j j d  j d  }	 d | f }
 |	 j |
  } | j	   r=| j | j | d d |
   n  |  j j d  j |  } | j
   r| j | j | d   n  | j   | S(	   sm  
        Build a subproject distribution in
        C{Twisted<Projectname>-<version>.tar.bz2}.

        @type projectName: C{str}
        @param projectName: The lowercase name of the subproject to build.
        @type version: C{str}
        @param version: The version of Twisted to build.

        @return: The tarball file.
        @rtype: L{FilePath}.
        s   Twisted%s-%ss   .tar.bz2c             s   d j    f |   S(   NR{   (   R|   (   R   (   R  (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR   `  s    R+   R.   R  s   twisted_%s.pyR  (   t
   capitalizeR  R8   R  R  R  R:   R   R3   R   R
  RX   (   R   R   R(   R  R  R  R  R8   R   t
   pluginsDirt   pluginFileNamet
   pluginFilet   binPath(    (   R  s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   buildSubProjectQ  s0    	
c            s   d | j    | f     f d   } t j j | j d  } | j |  j j d  j | d   |  j j d  j |  } | j   r x0 | j	   D]" } |  j
 | | | j d   q W| j | j | d   n  | S(   s  
        Helper method to create and fill a tarball with things common between
        subprojects and core.

        @param projectName: The subproject's name.
        @type projectName: C{str}
        @param version: The version of the release.
        @type version: C{str}
        @param outputFile: The location of the tar file to create.
        @type outputFile: L{FilePath}
        s   Twisted%s-%sc             s   d j    f |   S(   NR{   (   R|   (   R   (   R  (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s    s   w:bz2t   LICENSER  R	  (   R#  R  R  RV   R:   R  R  R8   R
  RJ   R  (   R   R   R(   R  R  R  R  R8   (    (   R  s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR    s     N(   R   R   R   t   twisted.python.distR   R   R   R   R  R  R"  R(  R  (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR    s   		7	2	0t   UncleanWorkingDirectoryc           B   s   e  Z d  Z RS(   sJ   
    Raised when the working directory of an SVN checkout is unclean.
    (   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR+    s   t   NotWorkingDirectoryc           B   s   e  Z d  Z RS(   sQ   
    Raised when a directory does not appear to be an SVN working directory.
    (   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR,    s   c   
      C   se  |  j  d  j   s. t d |  j f   n  t d d |  j g  j   re t d |  j f   n  t t    } | j  d  } t d d |  j | j g  | j  d  } t	 |  j
   } | j   } d | } | j   s | j   n  t | | d	 | } | j |  x6 t D]. }	 | j  |	  j   r| j |	 |  qqW| j |  | j   d
 S(   ss  
    Build complete tarballs (including documentation) for Twisted and all
    subprojects.

    This should be called after the version numbers have been updated and
    NEWS files created.

    @type checkout: L{FilePath}
    @param checkout: The SVN working copy from which a pristine source tree
        will be exported.
    @type destination: L{FilePath}
    @param destination: The directory in which tarballs will be placed.

    @raise UncleanWorkingDirectory: if there are modifications to the
        working directory of C{checkout}.
    @raise NotWorkingDirectory: if the checkout path is not an SVN checkout.
    s   .svns2   %s does not appear to be an SVN working directory.t   svnt   sts8   There are local modifications to the SVN checkout in %s.t   exportR+   s2   http://twistedmatrix.com/documents/%s/api/%%s.htmlRs   N(   R8   R   R,  R:   R   t   stripR+  R   R   RD   R4   R   t   createDirectoryR  R"  R   R(  R  Ro   (
   t   checkoutR   R   R/  t   twistedPathR(   t   versionStringRs   t   dbR!  (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   buildAllTarballs  s2    t   ChangeVersionsScriptc           B   s#   e  Z d  Z e e  Z d   Z RS(   s<   
    A thing for changing version numbers. See L{main}.
    c   
      C   s6  d } t  |  d k r( t j d  n  | d } y | j d  \ } } } Wn t k
 rm t |   n Xd | k r | j d  \ } } n | } d	 } yC t |  } t |  } t |  } | d	 k	 r t |  } n  Wn t k
 r t |   n Xt d | | | d | }	 |  j	 t
 d  |	  d	 S(
   s  
        Given a list of command-line arguments, change all the Twisted versions
        in the current directory.

        @type args: list of str
        @param args: List of command line arguments.  This should only
            contain the version number.
        s6   Version should be in a form kind of like '1.2.3[pre4]'i   s4   Must specify exactly one argument to change-versionsi    t   .t   pret   WhateverR,   N(   R   R   R   R   R   t
   SystemExitR   R   R   RC   R   (
   R   R   t   version_formatR(   R%   R&   t   micro_and_preR5   R9  t   version_template(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s.    

(   R   R   R   t   staticmethodRC   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR7    s   t   BuildTarballsScriptc           B   s#   e  Z d  Z e e  Z d   Z RS(   s=   
    A thing for building release tarballs. See L{main}.
    c         C   sJ   t  |  d k r" t j d  n  |  j t | d  t | d   d S(   s   
        Build all release tarballs.

        @type args: list of str
        @param args: The command line arguments to process.  This must contain
            two strings: the checkout directory and the destination directory.
        i   sA   Must specify two arguments: Twisted checkout and destination pathi    i   N(   R   R   R   R6  R   (   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR     s    (   R   R   R   R?  R6  R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR@    s   t   BuildAPIDocsScriptc           B   s    e  Z d  Z d   Z d   Z RS(   s>   
    A thing for building API documentation. See L{main}.
    c         C   sc   t  | j d   j   } | j   } d | f } t   } | j d d | | j d  |  d S(   s  
        Build the API documentation of Twisted, with our project policy.

        @param projectRoot: A L{FilePath} representing the root of the Twisted
            checkout.
        @param output: A L{FilePath} pointing to the desired output directory.
        R+   s>   http://twistedmatrix.com/trac/browser/tags/releases/twisted-%sR   s   http://twistedmatrix.com/N(   RD   R8   R4   R   R   Rz   (   R   t   projectRootR   R(   R4  R   t
   apiBuilder(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   buildAPIDocs"  s    
	c         C   sJ   t  |  d k r" t j d  n  |  j t | d  t | d   d S(   s  
        Build API documentation.

        @type args: list of str
        @param args: The command line arguments to process.  This must contain
            two strings: the path to the root of the Twisted checkout, and a
            path to an output directory.
        i   sA   Must specify two arguments: Twisted checkout and destination pathi    i   N(   R   R   R   RD  R   (   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyR   7  s    	(   R   R   R   RD  R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyRA    s   	(5   R   R   t   datetimeR    R   R   R[   t   tempfileR   R  t
   subprocessR   R   R   t   twisted.python.versionsR   t   twisted.python.filepathR   R*  R   t   twisted.lore.scriptsR   t   ImportErrorR$   R   R   R   R!   R   R*   RC   t   objectRD   R1   RQ   RT   RI   R   Rd   Re   Rk   R   R   R   R6   R}   R  R+  R,  R6  R7  R@  RA  (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/_release.pyt   <module>   sV   			2+					Q. 5		1+