#!/usr/bin/env ruby # # 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. |