#!/usr/bin/env ruby # # Copyright (c) Perforce Software, Inc., 2014. All rights reserved # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE # SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. # # Triggers: # ForceClientOptions form-in client "ForceRmdir.rb %formfile% # [allwrite | noallwrite] [clobber | noclobber] [compress | nocompress] # [locked | unlocked] [modtime | nomodtime] [rmdir | normdir]" # # # Examines the "Options:" line of the client form file, and forces the values # of the options specified in the trigger form to the specified value. # Unmentioned options are left alone. if ARGV.length < 1 || !(File.file?(ARGV[0])) puts '%formfile% not given.' exit 1 end # New options can be parsed by adding another element to "opts_to_check". # Follow the same format as the other entries. opts_to_check = [ [/\A(no)?allwrite\z/, false], [/\A(no)?clobber\z/, false], [/\A(no)?compress\z/, false], [/\A(un)?locked\z/, false], [/\A(no)?modtime\z/, false], [/\A(no)?rmdir\z/, false] ] def get_opt(opt, opts_to_check) opts_to_check.each do |check| return check if (check[0] =~ opt) end return nil end def known_opt?(opt, opts_to_check) known_option = get_opt(opt, opts_to_check) return (nil != known_option) end def duplicate_opt?(opt, opts_to_check) known_option = get_opt(opt, opts_to_check) if (nil != known_option) return (false != known_option[1]) else return false end end # Parse the command line arguments for i in 1..ARGV.length-1 do opt = ARGV[i] if (known_opt?(opt, opts_to_check)) if (duplicate_opt?(opt, opts_to_check)) puts "Conflicting option: #{opt}" exit 1 else known_option = get_opt(opt, opts_to_check) known_option[1] = opt end else puts "Unknown option: #{opt}" exit 1 end end formfile = ARGV[0] form_string = "" form = File.open(formfile, 'r') form.each do |line| if /^Client:.*p4sandbox-.*$/ =~ line exit 0 elsif /^Options:.*?/ =~ line client_choices = line.gsub(/Options:\s+(.*)/, '\1').strip.split(/\s+/) options_line = line.gsub(/(Options:\s+).*/, '\1').chomp # Parse the "Options" line of the client form and create new "Options" line client_choices.each do |opt| if (known_opt?(opt, opts_to_check) && duplicate_opt?(opt, opts_to_check)) known_opt = get_opt(opt, opts_to_check) options_line << "#{known_opt[1]} " else options_line << "#{opt} " end end options_line = options_line.strip << "\n" form_string << (options_line) else form_string << (line) end end form.close form = File.open(formfile, 'w') form.write(form_string) form.close exit 0
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 10137 | jim_brower | Added BSD license to several projects. | ||
#2 | 9836 | jim_brower |
Made significant changes to ForceClientOptions. It now relies less on magic numbers, and should be able to handle the inclusion of future options without exploding. It's also much longer now, for better or for worse. |
||
#1 | 9829 | jim_brower |
Added trigger to let you force any client options you want. Not exactly proud of the implementation, but it seems to work. |