<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>File: autointeg.rb</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript"> // <![CDATA[ function popupCode( url ) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } function toggleCode( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // Make codeblocks hidden by default document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) // ]]> </script> </head> <body> <div id="fileHeader"> <h1>autointeg.rb</h1> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Path:</strong></td> <td>autointeg.rb </td> </tr> <tr class="top-aligned-row"> <td><strong>Last Update:</strong></td> <td>Fri Nov 12 13:00:07 GMT 2004</td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> <div id="description"> <h2>Introduction</h2> <pre> This script keeps a slave branch synchronised with a master branch based on the contents of a branch view. This could mean a single file, or an entire tree - it's up to you. There are two ways to limit the scope of the script: 1. Use a limited mapping in the trigger specification 2. Use a limited mapping in the branch specification As you can see, the methods are similar. </pre> <h2>Requirements</h2> <pre> Ruby http://www.ruby-lang.org P4Ruby http://public.perforce.com/guest/tony_smith/perforce/API/Ruby/index.html Rubymail http://raa.ruby-lang.org/project/rubymail/ </pre> <h2>Trigger Specification</h2> <pre> An suitable trigger specification might look like this: autointeg commit //depot/master/... "t/autointeg.rb -b ms -c %changelist%" This would cause all changes to files under //depot/master/... that are mapped by the branch specification 'ms' (master-slave) to be propagated immediately to the slave copy. </pre> </div> <div id="requires-list"> <h2 class="section-bar">Required files</h2> <div class="name-list"> <a href="../classes/P4.html">P4</a> getoptlong net/smtp rmail/message </div> </div> <div id="method-list"> <h2 class="section-bar">Methods</h2> <div class="name-list"> <a href="#M000002">admin_report</a> <a href="#M000001">croaksyntax</a> </div> </div> <div id="constants-list"> <h2 class="section-bar">Constants</h2> <div class="name-list"> <table summary="Constants"> <tr class="top-aligned-row context-row"> <td class="context-item-name">ADMIN_EMAIL</td> <td>=</td> <td class="context-item-value">"perforce@localhost"</td> </tr> <tr class="top-aligned-row context-row"> <td> </td> <td colspan="2" class="context-item-desc"> Email address of the Perforce administrator - notifications will be sent to this user if EMAIL_REPORTS is true </td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">EMAIL_REPORTS</td> <td>=</td> <td class="context-item-value">false</td> </tr> <tr class="top-aligned-row context-row"> <td> </td> <td colspan="2" class="context-item-desc"> If true, reports of the integrations performed will be emailed to the address above. Default: false. </td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">SMTP_SERVER</td> <td>=</td> <td class="context-item-value">"localhost"</td> </tr> <tr class="top-aligned-row context-row"> <td> </td> <td colspan="2" class="context-item-desc"> The name of your SMTP server. The script uses SMTP to send notifications by email if EMAIL_REPORTS is true. </td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">FROM_ADDRESS</td> <td>=</td> <td class="context-item-value">"perforce@localhost"</td> </tr> <tr class="top-aligned-row context-row"> <td> </td> <td colspan="2" class="context-item-desc"> The email address messages from this script should appear to come from </td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">MSG_SUBJECT</td> <td>=</td> <td class="context-item-value">"Automatic integration report"</td> </tr> <tr class="top-aligned-row context-row"> <td> </td> <td colspan="2" class="context-item-desc"> The subject line for the messages </td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">DEBUG</td> <td>=</td> <td class="context-item-value">false</td> </tr> <tr class="top-aligned-row context-row"> <td> </td> <td colspan="2" class="context-item-desc"> Causes the text of the email that would be sent to be dumped to stderr - which in the case of a trigger means it goes to the client. </td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">P4USER</td> <td>=</td> <td class="context-item-value">nil</td> </tr> <tr class="top-aligned-row context-row"> <td> </td> <td colspan="2" class="context-item-desc"> Perforce environment. Unless these values are explicitly specified here, all the Perforce settings will be taken from the calling environment. This means you can use it with P4CONFIG files, and with ‘p4 login’ tickets if you want to. If you use tickets, make sure the script user is in a group with a really, really long ticket timeout. </td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">P4PORT</td> <td>=</td> <td class="context-item-value">nil</td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">P4CLIENT</td> <td>=</td> <td class="context-item-value">nil</td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">P4PASSWD</td> <td>=</td> <td class="context-item-value">nil</td> </tr> </table> </div> </div> <div id="class-list"> <h2 class="section-bar">Classes and Modules</h2> Class <a href="../classes/IntegMgr.html" class="link">IntegMgr</a><br /> </div> </div> <!-- if includes --> <!-- if method_list --> <div id="methods"> <h2 class="section-bar">Public Instance methods</h2> <div id="method-M000002" class="method-detail"> <a name="M000002"></a> <div class="method-heading"> <a href="#M000002" class="method-signature"> <span class="method-name">admin_report</span><span class="method-args">( &block )</span> </a> </div> <div class="method-description"> <p> Send a report by email to the admin </p> <p><a class="source-toggle" href="#" onclick="toggleCode('M000002-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000002-source"> <pre> <span class="ruby-comment cmt"># File autointeg.rb, line 175</span> 175: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">admin_report</span>( <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> ) 176: <span class="ruby-identifier">msg</span> = <span class="ruby-constant">RMail</span><span class="ruby-operator">::</span><span class="ruby-constant">Message</span>.<span class="ruby-identifier">new</span> 177: <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">header</span>.<span class="ruby-identifier">to</span> = <span class="ruby-constant">ADMIN_EMAIL</span> 178: <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">header</span>.<span class="ruby-identifier">from</span> = <span class="ruby-constant">FROM_ADDRESS</span> 179: <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">header</span>.<span class="ruby-identifier">subject</span> = <span class="ruby-constant">MSG_SUBJECT</span> 180: <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>() 181: 182: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">DEBUG</span> 183: <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span>( <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">to_s</span> ) 184: <span class="ruby-keyword kw">end</span> 185: 186: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">EMAIL_REPORTS</span> 187: <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SMTP</span>.<span class="ruby-identifier">start</span>( <span class="ruby-constant">SMTP_SERVER</span> ) <span class="ruby-keyword kw">do</span> 188: <span class="ruby-operator">|</span><span class="ruby-identifier">smtp</span><span class="ruby-operator">|</span> 189: <span class="ruby-identifier">smtp</span>.<span class="ruby-identifier">sendmail</span>( <span class="ruby-identifier">msg</span>, <span class="ruby-constant">FROM_ADDRESS</span>, <span class="ruby-constant">ADMIN_EMAIL</span> ) 190: <span class="ruby-keyword kw">end</span> 191: <span class="ruby-keyword kw">end</span> 192: <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> <div id="method-M000001" class="method-detail"> <a name="M000001"></a> <div class="method-heading"> <a href="#M000001" class="method-signature"> <span class="method-name">croaksyntax</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Blurt out our syntax </p> <p><a class="source-toggle" href="#" onclick="toggleCode('M000001-source');return false;">[Source]</a></p> <div class="method-source-code" id="M000001-source"> <pre> <span class="ruby-comment cmt"># File autointeg.rb, line 162</span> 162: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">croaksyntax</span>() 163: <span class="ruby-identifier">puts</span> <span class="ruby-value str">"\nUsage: autointeg.rb -b <branchspec> -c <changelist>\n\n"</span> 164: <span class="ruby-identifier">exit</span> <span class="ruby-value">0</span> 165: <span class="ruby-keyword kw">end</span> </pre> </div> </div> </div> </div> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> </div> </body> </html>
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 4654 | Tony Smith |
Add an example spec trigger to show how you might restrict the default view for all new clients to a pre-defined set of mappings. |
||
#1 | 4640 | Tony Smith |
Add a sample post-commit trigger that can be used to keep a master and slave branch in sync. |