checktype.rb

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

Introduction

Name: checktype.rb

Author: Tony Smith <tony@perforce.com>

Description

     Example trigger to enforce a rule "files of suffix .x need
     to be added as type Z". (For example, ".jpg" files must
     always be "binary" and ".sh" files should always be "text".)

     This script is mostly a reimplentation of Jeff Bowles
     and Wed Peters' Perl binary.pl using P4Ruby but it uses
     a more generalised trigger execution framework to make
     it easier to concentrate on the nuts and bolts of what
     your trigger does.

Requires

     Ruby
     P4Ruby
     P4Triggers module

Example ‘triggers’ section:

     Note: since this is applicable to only filenames with certain suffixes,
     you might want to restrict the trigger to run when those files are
     submitted. So, if this is looking at .cpp/.h/.txt/.html lines, you might
     want to have it run only on those files.)

     Triggers:
       exampleB  //.../*.jpg  "ruby whatever/checktype.rb %changelist%"
       exampleB  //.../*.bmp  "ruby whatever/checktype.rb %changelist%"
       exampleB  //.../*.sh   "ruby whatever/checktype.rb %changelist%"

Note

     For triggers I recommend you use a P4CONFIG file rather than hard coding
     username/password in the script itself. This script assumes you've taken
     that advice.

Required files

P4   P4Triggers  

Constants

TYPEMAP = Hash.new
  These are the file extensions and the Perforce types we want to enforce. For each one we specify a regular expression for matching the valid filetypes for the extension and a corresponding textual description of the match (so we can tell the user what we’re looking for.

Classes and Modules

Class TypeTrigger

[Validate]