autointeg.rb

Path: autointeg.rb
Last Update: Fri Nov 19 09:48:32 GMT 2004

Introduction

     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.

Requirements

     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/

Trigger Specification

     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.

Required files

P4   getoptlong   net/smtp   rmail/message  

Methods

Constants

ADMIN_EMAIL = "perforce@localhost"
  Email address of the Perforce administrator - notifications will be sent to this user if EMAIL_REPORTS is true
EMAIL_REPORTS = false
  If true, reports of the integrations performed will be emailed to the address above. Default: false.
SMTP_SERVER = "localhost"
  The name of your SMTP server. The script uses SMTP to send notifications by email if EMAIL_REPORTS is true.
FROM_ADDRESS = "perforce@localhost"
  The email address messages from this script should appear to come from
MSG_SUBJECT = "Automatic integration report"
  The subject line for the messages
DEBUG = false
  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.
P4USER = nil
  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.
P4PORT = nil
P4CLIENT = nil
P4PASSWD = nil

Classes and Modules

Class IntegMgr

Public Instance methods

Send a report by email to the admin

[Source]

     # File autointeg.rb, line 175
175: def admin_report( &block )
176:     msg = RMail::Message.new
177:     msg.header.to       = ADMIN_EMAIL
178:     msg.header.from     = FROM_ADDRESS
179:     msg.header.subject  = MSG_SUBJECT
180:     msg.body = block.call()
181: 
182:     if DEBUG
183:         $stderr.puts( msg.to_s )
184:     end
185: 
186:     if EMAIL_REPORTS
187:         Net::SMTP.start( SMTP_SERVER ) do
188:             |smtp|
189:             smtp.sendmail( msg, FROM_ADDRESS, ADMIN_EMAIL )
190:         end
191:     end
192: end

Blurt out our syntax

[Source]

     # File autointeg.rb, line 162
162: def croaksyntax()
163:     puts "\nUsage: autointeg.rb -b <branchspec> -c <changelist>\n\n"
164:     exit 0
165: end

[Validate]