#!/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 "ostruct" require 'pp' # # The trigger class itself. # class DefaultClient def initialize(options = OpenStruct.new) @options = options @change = nil @p4 = P4.new @p4.user = @options.user || @p4.user? @p4.port = @options.port || @p4.port? @p4.client = @options.client || @p4.client? @p4.parse_forms @p4.connect if @options.verbose print "\nP4PORT = #{@p4.port?}\n" print "P4USER = #{@p4.user?}\n" print "P4CLIENT = #{@p4.client?}\n" end end def process(formname, formfile) 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 client = @form.load_hash client['Options'].sub!(/normdir/, "rmdir") client['Root'] = "C:\\work\\" + @formname client['View'] = ["//depot/main/... //#{@formname}/main/..."] @form.save_hash(client) end end #-- #------------------------------------------------------------------------------- # Start of main script execution #------------------------------------------------------------------------------- #++ trig = DefaultClient.new(P4TriggerOptions.new(ARGV)) trig.process(ARGV[0], ARGV[1])