#!/usr/bin/ruby #-- #------------------------------------------------------------------------------- #++ # #= Introduction # #== Name: default_client.rb # #== Author: Robert Cowham # #== Description # # Example trigger to set some default client options # #== Requires # Ruby # P4Ruby # P4Triggers module # #== Example 'triggers' section: # # Restrict to only releases area of the repository # # Triggers: # default_client out client "ruby whatever/default_client.rb %formname% %formfile% " # default_client form-out client "ruby c:/perforce/scripts/default_client.rb %formname% %formfile% " # #== 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. # #-- #------------------------------------------------------------------------------- #++ $:.unshift( File.dirname( __FILE__ ) ) require "P4" require "P4Triggers" require 'pp' # # The trigger class itself. The main method in here is validate() which # is invoked from the super-class' parse_change() method. # class DefaultClient def initialize(formname, formfile) p4 = P4.new p4.tagged p4.connect clients = p4.run_clients @formname = nil # exit if client already exists return if clients.select{|c| c['client'] == formname}.size > 0 @form = P4Trigger::FormFile.new(formfile) @formname = formname end def process return if !@formname client = @form.load_hash client['Options'].sub!(/normdir/, "rmdir") client['Root'] = "C:\\work\\" + @formname @form.save_hash(client) end end #-- #------------------------------------------------------------------------------- # Start of main script execution #------------------------------------------------------------------------------- #++ trig = DefaultClient.new(ARGV[0], ARGV[1]) trig.process