<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tony&#039;s Blog &#187; buildbot</title>
	<atom:link href="http://stolennotebook.com/anthony/category/buildbot/feed/" rel="self" type="application/rss+xml" />
	<link>http://stolennotebook.com/anthony</link>
	<description>Just another Stolen Notebook weblog</description>
	<lastBuildDate>Tue, 07 Sep 2010 16:24:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Getting File Changes From Buildbot</title>
		<link>http://stolennotebook.com/anthony/2007/01/19/18/</link>
		<comments>http://stolennotebook.com/anthony/2007/01/19/18/#comments</comments>
		<pubDate>Sat, 20 Jan 2007 03:27:17 +0000</pubDate>
		<dc:creator>tonymagro</dc:creator>
				<category><![CDATA[buildbot]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.stolennotebook.com/anthony/2007/01/19/18/</guid>
		<description><![CDATA[During a Buildbot build step you might need to have a list of files which have changed as a result of a commit to your repository. A quick way to get this information during a build step is to subclass the build step class of your choice and overload its start() function. A build step&#8217;s [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>During a Buildbot build step you might need to have a list of files which have changed as a  result of a commit to your repository. A quick way to get this information during a build step is to subclass the build step class of your choice and overload its start() function.</p>
<p>A build step&#8217;s start() function is responsible for telling the slave to start executing the command. Each step class has a member variable called &#8220;build&#8221; of type &#8220;buildbot.process.base.Build&#8221; which it inherits from its main parent class &#8220;buildbot.process.buildstep.BuildStep&#8221;. Here is a quick example of getting file change information during a ShellCommand step in your master.cfg file:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;color: #111;"><span style="color: #ff7700;font-weight:bold;color: #B83A24;">from</span> twisted.<span style="color: black;color: #517656">python</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> log
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">from</span> buildbot.<span style="color: black;color: #517656">steps</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> shell
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">from</span> buildbot.<span style="color: black;color: #517656">process</span>.<span style="color: black;color: #517656">buildstep</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> RemoteShellCommand
&nbsp;
<span style="color: #808080; font-style: italic;color: #CDC;"># Executes a remote command with changed files appended onto the end</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">class</span> ShellCommandChangeList<span style="color: black;color: #729AE3;">&#40;</span>shell.<span style="color: black;color: #517656">ShellCommand</span><span style="color: black;color: #729AE3;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> start<span style="color: black;color: #729AE3;">&#40;</span><span style="color: #008000;color: #B83A24;">self</span><span style="color: black;color: #729AE3;">&#41;</span>:
    <span style="color: #808080; font-style: italic;color: #CDC;"># Substitute build properties into command</span>
    command = <span style="color: #008000;color: #B83A24;">self</span>._interpolateProperties<span style="color: black;color: #729AE3;">&#40;</span><span style="color: #008000;color: #B83A24;">self</span>.<span style="color: black;color: #517656">command</span><span style="color: black;color: #729AE3;">&#41;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;"># fail assert if command is not of correct type</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">assert</span> <span style="color: #008000;color: #B83A24;">isinstance</span><span style="color: black;color: #729AE3;">&#40;</span>command, <span style="color: black;color: #729AE3;">&#40;</span><span style="color: #008000;color: #B83A24;">list</span>, <span style="color: #008000;color: #B83A24;">tuple</span>, <span style="color: #008000;color: #B83A24;">str</span><span style="color: black;color: #729AE3;">&#41;</span><span style="color: black;color: #729AE3;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># Get changed file list from the build which invoked this step</span>
    files = <span style="color: #008000;color: #B83A24;">self</span>.<span style="color: black;color: #517656">build</span>.<span style="color: black;color: #517656">allFiles</span><span style="color: black;color: #729AE3;">&#40;</span><span style="color: black;color: #729AE3;">&#41;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;"># Log the changed files to twistd.log</span>
    log.<span style="color: black;color: #517656">msg</span><span style="color: black;color: #729AE3;">&#40;</span><span style="color: #483d8b;color: #666666;">&quot;Build Files: %s&quot;</span> <span style="color: #66cc66;color: #729AE3;">%</span> files<span style="color: black;color: #729AE3;">&#41;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;"># Now we can do whatever we want with the list of changed files.</span>
    <span style="color: #808080; font-style: italic;color: #CDC;"># I will just append them to the end of the command.</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># Convert file list so it can be appended to the command's type</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> <span style="color: #008000;color: #B83A24;">isinstance</span><span style="color: black;color: #729AE3;">&#40;</span>command, <span style="color: #008000;color: #B83A24;">str</span><span style="color: black;color: #729AE3;">&#41;</span>:
        files = <span style="color: #483d8b;color: #666666;">&quot; &quot;</span>.<span style="color: black;color: #517656">join</span><span style="color: black;color: #729AE3;">&#40;</span>files<span style="color: black;color: #729AE3;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">elif</span> <span style="color: #008000;color: #B83A24;">isinstance</span><span style="color: black;color: #729AE3;">&#40;</span>command, <span style="color: #008000;color: #B83A24;">tuple</span><span style="color: black;color: #729AE3;">&#41;</span>:
        files = <span style="color: #008000;color: #B83A24;">tuple</span><span style="color: black;color: #729AE3;">&#40;</span>files<span style="color: black;color: #729AE3;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># append files to end of command</span>
    command += files
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># We have created the final command string</span>
    <span style="color: #808080; font-style: italic;color: #CDC;"># so we can fill out the arguments for a RemoteShellCommand</span>
    <span style="color: #808080; font-style: italic;color: #CDC;"># using our new command string</span>
    kwargs = <span style="color: #008000;color: #B83A24;">self</span>.<span style="color: black;color: #517656">remote_kwargs</span>
    kwargs<span style="color: black;color: #729AE3;">&#91;</span><span style="color: #483d8b;color: #666666;">'command'</span><span style="color: black;color: #729AE3;">&#93;</span> = command
    kwargs<span style="color: black;color: #729AE3;">&#91;</span><span style="color: #483d8b;color: #666666;">'logfiles'</span><span style="color: black;color: #729AE3;">&#93;</span> = <span style="color: #008000;color: #B83A24;">self</span>.<span style="color: black;color: #517656">logfiles</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># Create the RemoteShellCommand and start it</span>
    <span style="color: #dc143c;color: #8FB394;">cmd</span> = RemoteShellCommand<span style="color: black;color: #729AE3;">&#40;</span><span style="color: #66cc66;color: #729AE3;">**</span>kwargs<span style="color: black;color: #729AE3;">&#41;</span>
    <span style="color: #008000;color: #B83A24;">self</span>.<span style="color: black;color: #517656">setupEnvironment</span><span style="color: black;color: #729AE3;">&#40;</span><span style="color: #dc143c;color: #8FB394;">cmd</span><span style="color: black;color: #729AE3;">&#41;</span>
    <span style="color: #008000;color: #B83A24;">self</span>.<span style="color: black;color: #517656">checkForOldSlaveAndLogfiles</span><span style="color: black;color: #729AE3;">&#40;</span><span style="color: black;color: #729AE3;">&#41;</span>
    <span style="color: #008000;color: #B83A24;">self</span>.<span style="color: black;color: #517656">startCommand</span><span style="color: black;color: #729AE3;">&#40;</span><span style="color: #dc143c;color: #8FB394;">cmd</span><span style="color: black;color: #729AE3;">&#41;</span></pre></div></div>

<p>You can use the new ShellCommandChangeList class in the same way you use the ShellCommand class. The only difference being the ShellCommandChangeList class will append a list of changed files to the end of the step&#8217;s shell command. We use a similar class and method at Stolen Notebook to build large source asset files (models, levels, art, etc.) automatically with buildbot when they are checked into our repository.</p>
<p>Here is a short contrived example of using the new ShellCommandChangeList build step with a BuildFactory to call a remote command for a fictional program named `checksum`. Let&#8217;s say that `checksum` is a program which takes filenames as input, computes the checksum of those files and prints those checksums to standard out.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;color: #111;"><span style="color: #ff7700;font-weight:bold;color: #B83A24;">from</span> buildbot.<span style="color: black;color: #517656">steps</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> source, shell
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">from</span> buildbot.<span style="color: black;color: #517656">process</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> factory
&nbsp;
f = factory.<span style="color: black;color: #517656">BuildFactory</span><span style="color: black;color: #729AE3;">&#40;</span><span style="color: black;color: #729AE3;">&#41;</span>
f.<span style="color: black;color: #517656">addStep</span><span style="color: black;color: #729AE3;">&#40;</span>source.<span style="color: black;color: #517656">SVN</span>, svnurl=<span style="color: #483d8b;color: #666666;">&quot;http://svn.example.org/Trunk/&quot;</span><span style="color: black;color: #729AE3;">&#41;</span>
f.<span style="color: black;color: #517656">addStep</span><span style="color: black;color: #729AE3;">&#40;</span>ShellCommandChangeList, command=<span style="color: black;color: #729AE3;">&#91;</span><span style="color: #483d8b;color: #666666;">&quot;checksum&quot;</span><span style="color: black;color: #729AE3;">&#93;</span><span style="color: black;color: #729AE3;">&#41;</span></pre></div></div>

<p>Lets say two files named main.cpp and main.h are changed in the src directory of our svnurl and submitted to the repository which triggers this build. The normal ShellCommand step would just call &#8220;checksum&#8221; remotely. The ShellCommandChangeList step on the other hand would call &#8220;checksum src/main.cpp src/main.h&#8221;</p>
<p>You should note that the way your VC system works and how your repository is set up in terms of file location and branches may affect how the file change paths are presented to you. You can easily see the list of file changes by using log.msg in your start() function to print them to the twistd.log file.</p>
]]></content:encoded>
			<wfw:commentRss>http://stolennotebook.com/anthony/2007/01/19/18/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
