Ticket #333: buildbot-0.7.8-FtpTar.patch

File buildbot-0.7.8-FtpTar.patch, 8.4 kB (added by dtrosset, 5 months ago)

FtpTar? source step patch

  • old-buildbot/buildbot/slave/commands.py

    old new  
    22 
    33import os, re, signal, shutil, types, time 
    44from stat import ST_CTIME, ST_MTIME, ST_SIZE 
     5from ftplib import FTP 
    56 
    67from zope.interface import implements 
    78from twisted.internet.protocol import ProcessProtocol 
     
    16031604 
    16041605registerSlaveCommand("svn", SVN, command_version) 
    16051606 
     1607class FtpTar(SourceBase): 
     1608    """FTP and untar operation. In addition to the arguments 
     1609    handled by SourceBase, this command reads the following keys: 
     1610 
     1611    ['ftphost'] (required): the FTP hostname 
     1612    ['ftpfile'] (required): the FTP file to download 
     1613    ['ftpuser'] (required): the FTP username 
     1614    ['ftppass'] (required): the FTP password 
     1615    ['striplevel'] (optional): the argument given to 'tar --strip %d' 
     1616    """ 
     1617 
     1618    header = "ftptar operation" 
     1619 
     1620    def setup(self, args): 
     1621        SourceBase.setup(self, args) 
     1622        self.tarexe = getCommand("tar") 
     1623        self.ftphost = args['ftphost'] 
     1624        self.ftpfile = args['ftpfile'] 
     1625        self.ftpuser = args['ftpuser'] 
     1626        self.ftppass = args['ftppass'] 
     1627        self.striplevel = args['striplevel'] 
     1628        self.sourcedata = "%s\n" % self.ftpfile 
     1629 
     1630    def sourcedirIsUpdateable(self): 
     1631        return False 
     1632 
     1633    def doVCFull(self): 
     1634        # Delete and create ftp download directory 
     1635        dd = os.path.join(self.builder.basedir, 'ftp') 
     1636        if os.path.isdir(dd): 
     1637            rmdirRecursive(dd) 
     1638        os.mkdir(dd) 
     1639        # Download the file 
     1640        ftp = FTP(self.ftphost) 
     1641        if self.ftpuser and self.ftppass: 
     1642            ftp.login(self.ftpuser, self.ftppass) 
     1643        f = os.path.join(dd, os.path.basename(self.ftpfile)) 
     1644        ftp.retrbinary('RETR '+self.ftpfile, open(f, 'wb').write) 
     1645        ftp.quit() 
     1646        # Create build directory 
     1647        db = os.path.join(self.builder.basedir, self.srcdir) 
     1648        os.mkdir(db) 
     1649        # Untar source in build directory 
     1650        striplevel = '%s' % (self.striplevel or 1) 
     1651        command = [self.tarexe, 'axvf', f, '--strip', striplevel] 
     1652        c = ShellCommand(self.builder, command, db, 
     1653                         sendRC=False, timeout=self.timeout, 
     1654                         keepStdout=True) 
     1655        self.command = c 
     1656        return c.start() 
     1657 
     1658    def parseGotRevision(self): 
     1659        return None 
     1660 
     1661 
     1662registerSlaveCommand("ftptar", FtpTar, command_version) 
     1663 
    16061664class Darcs(SourceBase): 
    16071665    """Darcs-specific VC operation. In addition to the arguments 
    16081666    handled by SourceBase, this command reads the following keys: 
  • old-buildbot/buildbot/steps/source.py

    old new  
    473473        self.startCommand(cmd, warnings) 
    474474 
    475475 
     476class FtpTar(Source): 
     477    """I perform FTP download and decompression of a tar source archive file. 
     478    """ 
     479 
     480    name = 'ftptar' 
     481 
     482    def __init__(self, ftphost=None, ftpuser=None, ftppass=None, ftpfile=None, 
     483                 striplevel=None, directory=None, **kwargs): 
     484        """ 
     485        @type  ftphost: string 
     486        @param ftphost: hostname of the FTP server to connect to. 
     487 
     488        @type  ftpfile: string 
     489        @param ftpfile: full path to the file to retreive from FTP server. On 
     490                        slave, only the last path component of this path will 
     491                        be used. 
     492 
     493        @type  ftpuser: string 
     494        @param ftpuser: username to use for logging on the FTP server. 
     495 
     496        @type  ftphost: string 
     497        @param ftphost: password to use for logging on the FTP server. 
     498 
     499        @type  striplevel: integer 
     500        @param striplevel: Number of directories that must be removed from 
     501                           the filenames extracted form the archive. It 
     502                           defaults to 1, usually stripping the name-X.y.z/ 
     503                           part of the files extracted, thus providing a 
     504                           Makefile directly in the build directory. 
     505 
     506        """ 
     507 
     508        if not kwargs.has_key('workdir') and directory is not None: 
     509            # deal with old configs 
     510            warn("Please use workdir=, not directory=", DeprecationWarning) 
     511            kwargs['workdir'] = directory 
     512 
     513        self.ftphost = ftphost 
     514        self.ftpfile = ftpfile 
     515        self.ftpuser = ftpuser 
     516        self.ftppass = ftppass 
     517        self.striplevel = striplevel 
     518 
     519        Source.__init__(self, **kwargs) 
     520        self.addFactoryArguments(ftphost=ftphost, 
     521                                 ftpfile=ftpfile, 
     522                                 ftpuser=ftpuser, 
     523                                 ftppass=ftppass, 
     524                                 striplevel=striplevel, 
     525                                 directory=directory, 
     526                                 ) 
     527 
     528        if not ftpfile or not ftphost: 
     529            raise ValueError("you must specify ftphost and ftpfile") 
     530 
     531 
     532    def computeSourceRevision(self, changes): 
     533        return None  
     534 
     535    def startVC(self, branch, revision, patch): 
     536 
     537        warnings = [] 
     538 
     539        if self.args['mode'] != "update": 
     540            warnings.append("WARNING: FtpTar slave can only do full retreival" 
     541                                ", do not specify mode other than update") 
     542 
     543        self.args['ftphost'] = self.ftphost 
     544        self.args['ftpfile'] = self.ftpfile 
     545        self.args['ftpuser'] = self.ftpuser 
     546        self.args['ftppass'] = self.ftppass 
     547        self.args['striplevel'] = self.striplevel 
     548        self.args['revision'] = revision 
     549        self.args['patch'] = patch 
     550 
     551        revstuff = [] 
     552        if branch is not None and branch != self.branch: 
     553            revstuff.append("[branch]") 
     554        if revision is not None: 
     555            revstuff.append("r%s" % revision) 
     556        if patch is not None: 
     557            revstuff.append("[patch]") 
     558        self.description.extend(revstuff) 
     559        self.descriptionDone.extend(revstuff) 
     560 
     561        cmd = LoggedRemoteCommand("ftptar", self.args) 
     562        self.startCommand(cmd, warnings) 
     563 
     564 
    476565class Darcs(Source): 
    477566    """Check out a source tree from a Darcs repository at 'repourl'. 
    478567 
  • old-buildbot/docs/buildbot.texinfo

    old new  
    207207* Bzr::                          
    208208* P4::                           
    209209* Git::                          
     210* FtpTar::                          
    210211 
    211212Simple ShellCommand Subclasses 
    212213 
     
    43884389* Bzr::                          
    43894390* P4::                           
    43904391* Git::                          
     4392* FtpTar:: 
    43914393@end menu 
    43924394 
    43934395@node CVS, SVN, Source Checkout, Source Checkout 
     
    47634765@end table 
    47644766 
    47654767 
    4766 @node Git,  , P4, Source Checkout 
     4768@node Git, FtpTar, P4, Source Checkout 
    47674769@subsubsection Git 
    47684770 
    47694771@cindex Git Checkout 
     
    47894791@end table 
    47904792 
    47914793 
     4794@node FtpTar,  , Git, Source Checkout 
     4795@subsubsection FtpTar 
     4796@cindex CVS Checkout 
     4797@bsindex buildbot.steps.source.FtpTar 
     4798 
     4799 
     4800The @code{FtpTar} build step performs a download of a specified file from 
     4801an FTP server (usually a source archive), and untar it into a build 
     4802directory, just as it could have bee got from another VCS operation. 
     4803 
     4804The FtpTar step does not use the mode argument. It should be left to the 
     4805default update mode, despite it generates a new source tree at each build. 
     4806 
     4807The FtpTar step takes the following arguments: 
     4808 
     4809@table @code 
     4810@item ftphost 
     4811(required): The hostname of the FTP server to connect to. 
     4812 
     4813@item ftpfile 
     4814(required): The full path to the file to dowload from the FTP server. The FTP 
     4815download is done using image (binary) mode. 
     4816 
     4817@item ftpuser 
     4818(optional): The username to use for logging on the FTP server. 
     4819 
     4820@item ftppass 
     4821(optional): The password to use for logging on the FTP server. 
     4822 
     4823@item striplevel 
     4824(optional): The number of directory names to remove from the path of the 
     4825files extracted form the archive. It defaults to 1, which usually strips the 
     4826name-X.y.z/ part of the files extracted, providing a Makefile directly in 
     4827the build directory. 
     4828 
     4829@end table 
     4830 
     4831 
     4832 
    47924833@node ShellCommand, Simple ShellCommand Subclasses, Source Checkout, Build Steps 
    47934834@subsection ShellCommand 
    47944835