<s> """<STR_LIT>""" <EOL> import textwrap <EOL> from datetime import date <EOL> import re <EOL> import sys <EOL> import os <EOL> from tempfile import mkdtemp <EOL> import tarfile <EOL> from subprocess import PIPE , STDOUT , Popen <EOL> from twisted . python . versions import Version <EOL> from twisted . python . filepath import FilePath <EOL> from twisted . python . dist import twisted_subprojects <EOL> try : <EOL> from twisted . lore . scripts import lore <EOL> except ImportError : <EOL> pass <EOL> VERSION_OFFSET = <NUM_LIT> <EOL> PROJECT_BLACKLIST = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def runCommand ( args ) : <EOL> """<STR_LIT>""" <EOL> process = Popen ( args , stdout = PIPE , stderr = STDOUT ) <EOL> stdout = process . stdout . read ( ) <EOL> exitCode = process . wait ( ) <EOL> if exitCode < <NUM_LIT:0> : <EOL> raise CommandFailed ( None , - exitCode , stdout ) <EOL> elif exitCode > <NUM_LIT:0> : <EOL> raise CommandFailed ( exitCode , None , stdout ) <EOL> return stdout <EOL> class CommandFailed ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , exitStatus , exitSignal , output ) : <EOL> Exception . __init__ ( self , exitStatus , exitSignal , output ) <EOL> self . exitStatus = exitStatus <EOL> self . exitSignal = exitSignal <EOL> self . output = output <EOL> def _changeVersionInFile ( old , new , filename ) : <EOL> """<STR_LIT>""" <EOL> replaceInFile ( filename , { old . base ( ) : new . base ( ) } ) <EOL> def getNextVersion ( version , now = None ) : <EOL> """<STR_LIT>""" <EOL> if now is None : <EOL> now = date . today ( ) <EOL> major = now . year - VERSION_OFFSET <EOL> if major != version . major : <EOL> minor = <NUM_LIT:0> <EOL> else : <EOL> minor = version . minor + <NUM_LIT:1> <EOL> return Version ( version . package , major , minor , <NUM_LIT:0> ) <EOL> def changeAllProjectVersions ( root , versionTemplate , today = None ) : <EOL> """<STR_LIT>""" <EOL> if not today : <EOL> today = date . today ( ) . strftime ( '<STR_LIT>' ) <EOL> for project in findTwistedProjects ( root ) : <EOL> if project . directory . basename ( ) == "<STR_LIT>" : <EOL> packageName = "<STR_LIT>" <EOL> else : <EOL> packageName = "<STR_LIT>" + project . directory . basename ( ) <EOL> oldVersion = project . getVersion ( ) <EOL> newVersion = Version ( packageName , versionTemplate . major , <EOL> versionTemplate . minor , versionTemplate . micro , <EOL> prerelease = versionTemplate . prerelease ) <EOL> if oldVersion . prerelease : <EOL> builder = NewsBuilder ( ) <EOL> builder . _changeNewsVersion ( <EOL> root . child ( "<STR_LIT>" ) , builder . _getNewsName ( project ) , <EOL> oldVersion , newVersion , today ) <EOL> builder . _changeNewsVersion ( <EOL> project . directory . child ( "<STR_LIT>" ) . child ( "<STR_LIT>" ) , <EOL> builder . _getNewsName ( project ) , oldVersion , newVersion , <EOL> today ) <EOL> if packageName == "<STR_LIT>" : <EOL> _changeVersionInFile ( <EOL> oldVersion , newVersion , root . child ( '<STR_LIT>' ) . path ) <EOL> project . updateVersion ( newVersion ) <EOL> class Project ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , directory ) : <EOL> self . directory = directory <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , self . directory ) <EOL> def getVersion ( self ) : <EOL> """<STR_LIT>""" <EOL> namespace = { } <EOL> execfile ( self . directory . child ( "<STR_LIT>" ) . path , namespace ) <EOL> return namespace [ "<STR_LIT:version>" ] <EOL> def updateVersion ( self , version ) : <EOL> """<STR_LIT>""" <EOL> oldVersion = self . getVersion ( ) <EOL> replaceProjectVersion ( self . directory . child ( "<STR_LIT>" ) . path , <EOL> version ) <EOL> _changeVersionInFile ( <EOL> oldVersion , version , <EOL> self . directory . child ( "<STR_LIT>" ) . child ( "<STR_LIT>" ) . path ) <EOL> def findTwistedProjects ( baseDirectory ) : <EOL> """<STR_LIT>""" <EOL> projects = [ ] <EOL> for filePath in baseDirectory . walk ( ) : <EOL> if filePath . basename ( ) == '<STR_LIT>' : <EOL> projectDirectory = filePath . parent ( ) <EOL> projects . append ( Project ( projectDirectory ) ) <EOL> return projects <EOL> def updateTwistedVersionInformation ( baseDirectory , now ) : <EOL> """<STR_LIT>""" <EOL> for project in findTwistedProjects ( baseDirectory ) : <EOL> project . updateVersion ( getNextVersion ( project . getVersion ( ) , now = now ) ) <EOL> def generateVersionFileData ( version ) : <EOL> """<STR_LIT>""" <EOL> if version . prerelease is not None : <EOL> prerelease = "<STR_LIT>" % ( version . prerelease , ) <EOL> else : <EOL> prerelease = "<STR_LIT>" <EOL> data = '''<STR_LIT>''' % ( version . package , version . major , version . minor , version . micro , prerelease ) <EOL> return data <EOL> def replaceProjectVersion ( filename , newversion ) : <EOL> """<STR_LIT>""" <EOL> f = open ( filename , '<STR_LIT:w>' ) <EOL> f . write ( generateVersionFileData ( newversion ) ) <EOL> f . close ( ) <EOL> def replaceInFile ( filename , oldToNew ) : <EOL> """<STR_LIT>""" <EOL> os . rename ( filename , filename + '<STR_LIT>' ) <EOL> f = open ( filename + '<STR_LIT>' ) <EOL> d = f . read ( ) <EOL> f . close ( ) <EOL> for k , v in oldToNew . items ( ) : <EOL> d = d . replace ( k , v ) <EOL> f = open ( filename + '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> f . write ( d ) <EOL> f . close ( ) <EOL> os . rename ( filename + '<STR_LIT>' , filename ) <EOL> os . unlink ( filename + '<STR_LIT>' ) <EOL> class NoDocumentsFound ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class LoreBuilderMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def lore ( self , arguments ) : <EOL> """<STR_LIT>""" <EOL> options = lore . Options ( ) <EOL> options . parseOptions ( [ "<STR_LIT>" ] + arguments ) <EOL> lore . runGivenOptions ( options ) <EOL> class DocBuilder ( LoreBuilderMixin ) : <EOL> """<STR_LIT>""" <EOL> def build ( self , version , resourceDir , docDir , template , apiBaseURL = None , <EOL> deleteInput = False ) : <EOL> """<STR_LIT>""" <EOL> linkrel = self . getLinkrel ( resourceDir , docDir ) <EOL> inputFiles = docDir . globChildren ( "<STR_LIT>" ) <EOL> filenames = [ x . path for x in inputFiles ] <EOL> if not filenames : <EOL> raise NoDocumentsFound ( "<STR_LIT>" % ( docDir , ) ) <EOL> if apiBaseURL is not None : <EOL> arguments = [ "<STR_LIT>" , "<STR_LIT>" + apiBaseURL ] <EOL> else : <EOL> arguments = [ ] <EOL> arguments . extend ( [ "<STR_LIT>" , "<STR_LIT>" % ( template . path , ) , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" % ( version , ) , <EOL> "<STR_LIT>" , linkrel ] + filenames ) <EOL> self . lore ( arguments ) <EOL> if deleteInput : <EOL> for inputFile in inputFiles : <EOL> inputFile . remove ( ) <EOL> def getLinkrel ( self , resourceDir , docDir ) : <EOL> """<STR_LIT>""" <EOL> if resourceDir != docDir : <EOL> return '<STR_LIT:/>' . join ( filePathDelta ( docDir , resourceDir ) ) + "<STR_LIT:/>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> class ManBuilder ( LoreBuilderMixin ) : <EOL> """<STR_LIT>""" <EOL> def build ( self , manDir ) : <EOL> """<STR_LIT>""" <EOL> inputFiles = manDir . globChildren ( "<STR_LIT>" ) <EOL> filenames = [ x . path for x in inputFiles ] <EOL> if not filenames : <EOL> raise NoDocumentsFound ( "<STR_LIT>" % ( manDir , ) ) <EOL> arguments = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] + filenames <EOL> self . lore ( arguments ) <EOL> class APIBuilder ( object ) : <EOL> """<STR_LIT>""" <EOL> def build ( self , projectName , projectURL , sourceURL , packagePath , <EOL> outputPath ) : <EOL> """<STR_LIT>""" <EOL> from pydoctor . driver import main <EOL> main ( <EOL> [ "<STR_LIT>" , projectName , <EOL> "<STR_LIT>" , projectURL , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , packagePath . parent ( ) . path , <EOL> "<STR_LIT>" , sourceURL , <EOL> "<STR_LIT>" , packagePath . path , <EOL> "<STR_LIT>" , outputPath . path , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> class BookBuilder ( LoreBuilderMixin ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command ) : <EOL> """<STR_LIT>""" <EOL> return runCommand ( command ) <EOL> def buildTeX ( self , howtoDir ) : <EOL> """<STR_LIT>""" <EOL> if not howtoDir . exists ( ) : <EOL> raise ValueError ( "<STR_LIT>" % ( howtoDir . path , ) ) <EOL> self . lore ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] + <EOL> [ child . path for child in howtoDir . globChildren ( "<STR_LIT>" ) ] ) <EOL> def buildPDF ( self , bookPath , inputDirectory , outputPath ) : <EOL> """<STR_LIT>""" <EOL> if not bookPath . basename ( ) . endswith ( "<STR_LIT>" ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> workPath = FilePath ( mkdtemp ( ) ) <EOL> try : <EOL> startDir = os . getcwd ( ) <EOL> try : <EOL> os . chdir ( inputDirectory . path ) <EOL> texToDVI = [ <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" + workPath . path , <EOL> bookPath . path ] <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> self . run ( texToDVI ) <EOL> bookBaseWithoutExtension = bookPath . basename ( ) [ : - <NUM_LIT:4> ] <EOL> dviPath = workPath . child ( bookBaseWithoutExtension + "<STR_LIT>" ) <EOL> psPath = workPath . child ( bookBaseWithoutExtension + "<STR_LIT>" ) <EOL> pdfPath = workPath . child ( bookBaseWithoutExtension + "<STR_LIT>" ) <EOL> self . run ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , psPath . path , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> dviPath . path ] ) <EOL> self . run ( [ "<STR_LIT>" , psPath . path , pdfPath . path ] ) <EOL> pdfPath . moveTo ( outputPath ) <EOL> workPath . remove ( ) <EOL> finally : <EOL> os . chdir ( startDir ) <EOL> except : <EOL> workPath . moveTo ( bookPath . parent ( ) . child ( workPath . basename ( ) ) ) <EOL> raise <EOL> def build ( self , baseDirectory , inputDirectories , bookPath , outputPath ) : <EOL> """<STR_LIT>""" <EOL> for inputDir in inputDirectories : <EOL> self . buildTeX ( inputDir ) <EOL> self . buildPDF ( bookPath , baseDirectory , outputPath ) <EOL> for inputDirectory in inputDirectories : <EOL> for child in inputDirectory . children ( ) : <EOL> if child . splitext ( ) [ <NUM_LIT:1> ] == "<STR_LIT>" and child != bookPath : <EOL> child . remove ( ) <EOL> class NewsBuilder ( object ) : <EOL> """<STR_LIT>""" <EOL> blacklist = PROJECT_BLACKLIST <EOL> _FEATURE = "<STR_LIT>" <EOL> _BUGFIX = "<STR_LIT>" <EOL> _DOC = "<STR_LIT>" <EOL> _REMOVAL = "<STR_LIT>" <EOL> _MISC = "<STR_LIT>" <EOL> _headings = { <EOL> _FEATURE : "<STR_LIT>" , <EOL> _BUGFIX : "<STR_LIT>" , <EOL> _DOC : "<STR_LIT>" , <EOL> _REMOVAL : "<STR_LIT>" , <EOL> _MISC : "<STR_LIT>" , <EOL> } <EOL> _NO_CHANGES = "<STR_LIT>" <EOL> _TICKET_HINT = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\n>' ) <EOL> def _today ( self ) : <EOL> """<STR_LIT>""" <EOL> return date . today ( ) . strftime ( '<STR_LIT>' ) <EOL> def _findChanges ( self , path , ticketType ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> for child in path . children ( ) : <EOL> base , ext = os . path . splitext ( child . basename ( ) ) <EOL> if ext == ticketType : <EOL> results . append ( ( <EOL> int ( base ) , <EOL> '<STR_LIT:U+0020>' . join ( child . getContent ( ) . splitlines ( ) ) ) ) <EOL> results . sort ( ) <EOL> return results <EOL> def _formatHeader ( self , header ) : <EOL> """<STR_LIT>""" <EOL> return header + '<STR_LIT:\n>' + '<STR_LIT:=>' * len ( header ) + '<STR_LIT>' <EOL> def _writeHeader ( self , fileObj , header ) : <EOL> """<STR_LIT>""" <EOL> fileObj . write ( self . _formatHeader ( header ) ) <EOL> def _writeSection ( self , fileObj , header , tickets ) : <EOL> """<STR_LIT>""" <EOL> if not tickets : <EOL> return <EOL> reverse = { } <EOL> for ( ticket , description ) in tickets : <EOL> reverse . setdefault ( description , [ ] ) . append ( ticket ) <EOL> for description in reverse : <EOL> reverse [ description ] . sort ( ) <EOL> reverse = reverse . items ( ) <EOL> reverse . sort ( key = lambda ( descr , tickets ) : tickets [ <NUM_LIT:0> ] ) <EOL> fileObj . write ( header + '<STR_LIT:\n>' + '<STR_LIT:->' * len ( header ) + '<STR_LIT:\n>' ) <EOL> for ( description , relatedTickets ) in reverse : <EOL> ticketList = '<STR_LIT:U+002CU+0020>' . join ( [ <EOL> '<STR_LIT:#>' + str ( ticket ) for ticket in relatedTickets ] ) <EOL> entry = '<STR_LIT>' % ( description , ticketList ) <EOL> entry = textwrap . fill ( entry , subsequent_indent = '<STR_LIT:U+0020>' ) <EOL> fileObj . write ( entry + '<STR_LIT:\n>' ) <EOL> fileObj . write ( '<STR_LIT:\n>' ) <EOL> def _writeMisc ( self , fileObj , header , tickets ) : <EOL> """<STR_LIT>""" <EOL> if not tickets : <EOL> return <EOL> fileObj . write ( header + '<STR_LIT:\n>' + '<STR_LIT:->' * len ( header ) + '<STR_LIT:\n>' ) <EOL> formattedTickets = [ ] <EOL> for ( ticket , ignored ) in tickets : <EOL> formattedTickets . append ( '<STR_LIT:#>' + str ( ticket ) ) <EOL> entry = '<STR_LIT>' + '<STR_LIT:U+002CU+0020>' . join ( formattedTickets ) <EOL> entry = textwrap . fill ( entry , subsequent_indent = '<STR_LIT:U+0020>' ) <EOL> fileObj . write ( entry + '<STR_LIT>' ) <EOL> def build ( self , path , output , header ) : <EOL> """<STR_LIT>""" <EOL> changes = [ ] <EOL> for part in ( self . _FEATURE , self . _BUGFIX , self . _DOC , self . _REMOVAL ) : <EOL> tickets = self . _findChanges ( path , part ) <EOL> if tickets : <EOL> changes . append ( ( part , tickets ) ) <EOL> misc = self . _findChanges ( path , self . _MISC ) <EOL> oldNews = output . getContent ( ) <EOL> newNews = output . sibling ( '<STR_LIT>' ) . open ( '<STR_LIT:w>' ) <EOL> if oldNews . startswith ( self . _TICKET_HINT ) : <EOL> newNews . write ( self . _TICKET_HINT ) <EOL> oldNews = oldNews [ len ( self . _TICKET_HINT ) : ] <EOL> self . _writeHeader ( newNews , header ) <EOL> if changes : <EOL> for ( part , tickets ) in changes : <EOL> self . _writeSection ( newNews , self . _headings . get ( part ) , tickets ) <EOL> else : <EOL> newNews . write ( self . _NO_CHANGES ) <EOL> newNews . write ( '<STR_LIT:\n>' ) <EOL> self . _writeMisc ( newNews , self . _headings . get ( self . _MISC ) , misc ) <EOL> newNews . write ( '<STR_LIT:\n>' ) <EOL> newNews . write ( oldNews ) <EOL> newNews . close ( ) <EOL> output . sibling ( '<STR_LIT>' ) . moveTo ( output ) <EOL> def _getNewsName ( self , project ) : <EOL> """<STR_LIT>""" <EOL> name = project . directory . basename ( ) . title ( ) <EOL> if name == '<STR_LIT>' : <EOL> name = '<STR_LIT>' <EOL> return name <EOL> def _iterProjects ( self , baseDirectory ) : <EOL> """<STR_LIT>""" <EOL> projects = findTwistedProjects ( baseDirectory ) <EOL> projects . sort ( key = lambda proj : proj . directory . path ) <EOL> projects . reverse ( ) <EOL> for aggregateNews in [ False , True ] : <EOL> for project in projects : <EOL> if project . directory . basename ( ) in self . blacklist : <EOL> continue <EOL> topfiles = project . directory . child ( "<STR_LIT>" ) <EOL> if aggregateNews : <EOL> news = baseDirectory . child ( "<STR_LIT>" ) <EOL> else : <EOL> news = topfiles . child ( "<STR_LIT>" ) <EOL> name = self . _getNewsName ( project ) <EOL> version = project . getVersion ( ) <EOL> yield topfiles , news , name , version <EOL> def buildAll ( self , baseDirectory ) : <EOL> """<STR_LIT>""" <EOL> today = self . _today ( ) <EOL> for topfiles , news , name , version in self . _iterProjects ( baseDirectory ) : <EOL> self . build ( <EOL> topfiles , news , <EOL> "<STR_LIT>" % ( name , version . base ( ) , today ) ) <EOL> def _changeNewsVersion ( self , news , name , oldVersion , newVersion , today ) : <EOL> """<STR_LIT>""" <EOL> newHeader = self . _formatHeader ( <EOL> "<STR_LIT>" % ( name , newVersion . base ( ) , today ) ) <EOL> expectedHeaderRegex = re . compile ( <EOL> r"<STR_LIT>" % ( <EOL> re . escape ( name ) , re . escape ( oldVersion . base ( ) ) ) ) <EOL> oldNews = news . getContent ( ) <EOL> match = expectedHeaderRegex . search ( oldNews ) <EOL> if match : <EOL> oldHeader = match . group ( ) <EOL> replaceInFile ( news . path , { oldHeader : newHeader } ) <EOL> def main ( self , args ) : <EOL> """<STR_LIT>""" <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> self . buildAll ( FilePath ( args [ <NUM_LIT:0> ] ) ) <EOL> def filePathDelta ( origin , destination ) : <EOL> """<STR_LIT>""" <EOL> commonItems = <NUM_LIT:0> <EOL> path1 = origin . path . split ( os . sep ) <EOL> path2 = destination . path . split ( os . sep ) <EOL> for elem1 , elem2 in zip ( path1 , path2 ) : <EOL> if elem1 == elem2 : <EOL> commonItems += <NUM_LIT:1> <EOL> else : <EOL> break <EOL> path = [ "<STR_LIT:..>" ] * ( len ( path1 ) - commonItems ) <EOL> return path + path2 [ commonItems : ] <EOL> class DistributionBuilder ( object ) : <EOL> """<STR_LIT>""" <EOL> from twisted . python . dist import twisted_subprojects as subprojects <EOL> blacklist = PROJECT_BLACKLIST <EOL> def __init__ ( self , rootDirectory , outputDirectory , apiBaseURL = None ) : <EOL> """<STR_LIT>""" <EOL> self . rootDirectory = rootDirectory <EOL> self . outputDirectory = outputDirectory <EOL> self . apiBaseURL = apiBaseURL <EOL> self . manBuilder = ManBuilder ( ) <EOL> self . docBuilder = DocBuilder ( ) <EOL> def _buildDocInDir ( self , path , version , howtoPath ) : <EOL> """<STR_LIT>""" <EOL> templatePath = self . rootDirectory . child ( "<STR_LIT>" ) . child ( "<STR_LIT>" <EOL> ) . child ( "<STR_LIT>" ) . child ( "<STR_LIT>" ) <EOL> if path . basename ( ) == "<STR_LIT>" : <EOL> self . manBuilder . build ( path ) <EOL> if path . isdir ( ) : <EOL> try : <EOL> self . docBuilder . build ( version , howtoPath , path , <EOL> templatePath , self . apiBaseURL , True ) <EOL> except NoDocumentsFound : <EOL> pass <EOL> def buildTwisted ( self , version ) : <EOL> """<STR_LIT>""" <EOL> releaseName = "<STR_LIT>" % ( version , ) <EOL> buildPath = lambda * args : '<STR_LIT:/>' . join ( ( releaseName , ) + args ) <EOL> outputFile = self . outputDirectory . child ( releaseName + "<STR_LIT>" ) <EOL> tarball = tarfile . TarFile . open ( outputFile . path , '<STR_LIT>' ) <EOL> docPath = self . rootDirectory . child ( "<STR_LIT>" ) <EOL> if docPath . isdir ( ) : <EOL> for subProjectDir in docPath . children ( ) : <EOL> if ( subProjectDir . isdir ( ) <EOL> and subProjectDir . basename ( ) not in self . blacklist ) : <EOL> for child in subProjectDir . walk ( ) : <EOL> self . _buildDocInDir ( child , version , <EOL> subProjectDir . child ( "<STR_LIT>" ) ) <EOL> for binthing in self . rootDirectory . child ( "<STR_LIT>" ) . children ( ) : <EOL> if binthing . basename ( ) not in self . blacklist + [ "<STR_LIT>" ] : <EOL> tarball . add ( binthing . path , <EOL> buildPath ( "<STR_LIT>" , binthing . basename ( ) ) ) <EOL> bad_plugins = [ "<STR_LIT>" % ( blacklisted , ) <EOL> for blacklisted in self . blacklist ] <EOL> for submodule in self . rootDirectory . child ( "<STR_LIT>" ) . children ( ) : <EOL> if submodule . basename ( ) == "<STR_LIT>" : <EOL> for plugin in submodule . children ( ) : <EOL> if plugin . basename ( ) not in bad_plugins : <EOL> tarball . add ( plugin . path , buildPath ( "<STR_LIT>" , "<STR_LIT>" , <EOL> plugin . basename ( ) ) ) <EOL> elif submodule . basename ( ) not in self . blacklist : <EOL> tarball . add ( submodule . path , buildPath ( "<STR_LIT>" , <EOL> submodule . basename ( ) ) ) <EOL> for docDir in self . rootDirectory . child ( "<STR_LIT>" ) . children ( ) : <EOL> if docDir . basename ( ) not in self . blacklist : <EOL> tarball . add ( docDir . path , buildPath ( "<STR_LIT>" , docDir . basename ( ) ) ) <EOL> for toplevel in self . rootDirectory . children ( ) : <EOL> if not toplevel . isdir ( ) : <EOL> tarball . add ( toplevel . path , buildPath ( toplevel . basename ( ) ) ) <EOL> tarball . close ( ) <EOL> return outputFile <EOL> def buildCore ( self , version ) : <EOL> """<STR_LIT>""" <EOL> releaseName = "<STR_LIT>" % ( version , ) <EOL> outputFile = self . outputDirectory . child ( releaseName + "<STR_LIT>" ) <EOL> buildPath = lambda * args : '<STR_LIT:/>' . join ( ( releaseName , ) + args ) <EOL> tarball = self . _createBasicSubprojectTarball ( <EOL> "<STR_LIT>" , version , outputFile ) <EOL> for path in self . rootDirectory . child ( "<STR_LIT>" ) . children ( ) : <EOL> if not path . isdir ( ) : <EOL> tarball . add ( path . path , buildPath ( "<STR_LIT>" , path . basename ( ) ) ) <EOL> for path in self . rootDirectory . child ( "<STR_LIT>" ) . children ( ) : <EOL> if path . basename ( ) == "<STR_LIT>" : <EOL> for plugin in path . children ( ) : <EOL> for subproject in self . subprojects : <EOL> if plugin . basename ( ) == "<STR_LIT>" % ( subproject , ) : <EOL> break <EOL> else : <EOL> tarball . add ( plugin . path , <EOL> buildPath ( "<STR_LIT>" , "<STR_LIT>" , <EOL> plugin . basename ( ) ) ) <EOL> elif not path . basename ( ) in self . subprojects + [ "<STR_LIT>" ] : <EOL> tarball . add ( path . path , buildPath ( "<STR_LIT>" , path . basename ( ) ) ) <EOL> tarball . add ( self . rootDirectory . child ( "<STR_LIT>" ) . child ( "<STR_LIT>" ) . path , <EOL> releaseName ) <EOL> tarball . close ( ) <EOL> return outputFile <EOL> def buildSubProject ( self , projectName , version ) : <EOL> """<STR_LIT>""" <EOL> releaseName = "<STR_LIT>" % ( projectName . capitalize ( ) , version ) <EOL> outputFile = self . outputDirectory . child ( releaseName + "<STR_LIT>" ) <EOL> buildPath = lambda * args : '<STR_LIT:/>' . join ( ( releaseName , ) + args ) <EOL> subProjectDir = self . rootDirectory . child ( "<STR_LIT>" ) . child ( projectName ) <EOL> tarball = self . _createBasicSubprojectTarball ( projectName , version , <EOL> outputFile ) <EOL> tarball . add ( subProjectDir . child ( "<STR_LIT>" ) . path , releaseName ) <EOL> for child in subProjectDir . children ( ) : <EOL> name = child . basename ( ) <EOL> if name != "<STR_LIT>" : <EOL> tarball . add ( <EOL> child . path , <EOL> buildPath ( "<STR_LIT>" , projectName , name ) ) <EOL> pluginsDir = self . rootDirectory . child ( "<STR_LIT>" ) . child ( "<STR_LIT>" ) <EOL> pluginFileName = "<STR_LIT>" % ( projectName , ) <EOL> pluginFile = pluginsDir . child ( pluginFileName ) <EOL> if pluginFile . exists ( ) : <EOL> tarball . add ( pluginFile . path , <EOL> buildPath ( "<STR_LIT>" , "<STR_LIT>" , pluginFileName ) ) <EOL> binPath = self . rootDirectory . child ( "<STR_LIT>" ) . child ( projectName ) <EOL> if binPath . isdir ( ) : <EOL> tarball . add ( binPath . path , buildPath ( "<STR_LIT>" ) ) <EOL> tarball . close ( ) <EOL> return outputFile <EOL> def _createBasicSubprojectTarball ( self , projectName , version , outputFile ) : <EOL> """<STR_LIT>""" <EOL> releaseName = "<STR_LIT>" % ( projectName . capitalize ( ) , version ) <EOL> buildPath = lambda * args : '<STR_LIT:/>' . join ( ( releaseName , ) + args ) <EOL> tarball = tarfile . TarFile . open ( outputFile . path , '<STR_LIT>' ) <EOL> tarball . add ( self . rootDirectory . child ( "<STR_LIT>" ) . path , <EOL> buildPath ( "<STR_LIT>" ) ) <EOL> docPath = self . rootDirectory . child ( "<STR_LIT>" ) . child ( projectName ) <EOL> if docPath . isdir ( ) : <EOL> for child in docPath . walk ( ) : <EOL> self . _buildDocInDir ( child , version , docPath . child ( "<STR_LIT>" ) ) <EOL> tarball . add ( docPath . path , buildPath ( "<STR_LIT>" ) ) <EOL> return tarball <EOL> class UncleanWorkingDirectory ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class NotWorkingDirectory ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def buildAllTarballs ( checkout , destination ) : <EOL> """<STR_LIT>""" <EOL> if not checkout . child ( "<STR_LIT>" ) . exists ( ) : <EOL> raise NotWorkingDirectory ( <EOL> "<STR_LIT>" <EOL> % ( checkout . path , ) ) <EOL> if runCommand ( [ "<STR_LIT>" , "<STR_LIT>" , checkout . path ] ) . strip ( ) : <EOL> raise UncleanWorkingDirectory ( <EOL> "<STR_LIT>" <EOL> % ( checkout . path , ) ) <EOL> workPath = FilePath ( mkdtemp ( ) ) <EOL> export = workPath . child ( "<STR_LIT>" ) <EOL> runCommand ( [ "<STR_LIT>" , "<STR_LIT>" , checkout . path , export . path ] ) <EOL> twistedPath = export . child ( "<STR_LIT>" ) <EOL> version = Project ( twistedPath ) . getVersion ( ) <EOL> versionString = version . base ( ) <EOL> apiBaseURL = "<STR_LIT>" % ( <EOL> versionString ) <EOL> if not destination . exists ( ) : <EOL> destination . createDirectory ( ) <EOL> db = DistributionBuilder ( export , destination , apiBaseURL = apiBaseURL ) <EOL> db . buildCore ( versionString ) <EOL> for subproject in twisted_subprojects : <EOL> if ( subproject not in db . blacklist <EOL> and twistedPath . child ( subproject ) . exists ( ) ) : <EOL> db . buildSubProject ( subproject , versionString ) <EOL> db . buildTwisted ( versionString ) <EOL> workPath . remove ( ) <EOL> class ChangeVersionsScript ( object ) : <EOL> """<STR_LIT>""" <EOL> changeAllProjectVersions = staticmethod ( changeAllProjectVersions ) <EOL> def main ( self , args ) : <EOL> """<STR_LIT>""" <EOL> version_format = ( <EOL> "<STR_LIT>" ) <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> version = args [ <NUM_LIT:0> ] <EOL> try : <EOL> major , minor , micro_and_pre = version . split ( "<STR_LIT:.>" ) <EOL> except ValueError : <EOL> raise SystemExit ( version_format ) <EOL> if "<STR_LIT>" in micro_and_pre : <EOL> micro , pre = micro_and_pre . split ( "<STR_LIT>" ) <EOL> else : <EOL> micro = micro_and_pre <EOL> pre = None <EOL> try : <EOL> major = int ( major ) <EOL> minor = int ( minor ) <EOL> micro = int ( micro ) <EOL> if pre is not None : <EOL> pre = int ( pre ) <EOL> except ValueError : <EOL> raise SystemExit ( version_format ) <EOL> version_template = Version ( "<STR_LIT>" , <EOL> major , minor , micro , prerelease = pre ) <EOL> self . changeAllProjectVersions ( FilePath ( "<STR_LIT:.>" ) , version_template ) <EOL> class BuildTarballsScript ( object ) : <EOL> """<STR_LIT>""" <EOL> buildAllTarballs = staticmethod ( buildAllTarballs ) <EOL> def main ( self , args ) : <EOL> """<STR_LIT>""" <EOL> if len ( args ) != <NUM_LIT:2> : <EOL> sys . exit ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . buildAllTarballs ( FilePath ( args [ <NUM_LIT:0> ] ) , FilePath ( args [ <NUM_LIT:1> ] ) ) <EOL> class BuildAPIDocsScript ( object ) : <EOL> """<STR_LIT>""" <EOL> def buildAPIDocs ( self , projectRoot , output ) : <EOL> """<STR_LIT>""" <EOL> version = Project ( projectRoot . child ( "<STR_LIT>" ) ) . getVersion ( ) <EOL> versionString = version . base ( ) <EOL> sourceURL = ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( versionString , ) ) <EOL> apiBuilder = APIBuilder ( ) <EOL> apiBuilder . build ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> sourceURL , <EOL> projectRoot . child ( "<STR_LIT>" ) , <EOL> output ) <EOL> def main ( self , args ) : <EOL> """<STR_LIT>""" <EOL> if len ( args ) != <NUM_LIT:2> : <EOL> sys . exit ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . buildAPIDocs ( FilePath ( args [ <NUM_LIT:0> ] ) , FilePath ( args [ <NUM_LIT:1> ] ) ) </s>
