# Task: compare client specs to users, and flag the # client specs owned by users that don't exist anymore. # # num of calls to 'p4': 2 # status: tested on Darwin Mac OS X using "p4 -R" # # room for optimization/improvement: add getopts call # # Copyright 2004 Perforce Corporation, Inc. All rights reserved. require "readp4marshal" require 'getoptlong' debugOption = false defaultPort = nil defaultUser = nil options = GetoptLong.new( [ '--debug', '-d', GetoptLong::OPTIONAL_ARGUMENT], [ '--user', '-u', GetoptLong::REQUIRED_ARGUMENT], [ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT] ) options.each do |opt, arg| case opt when "--debug" debugOption = true when "--user" defaultUser = arg when "--port" defaultPort = arg end end p4 = P4Marshal.new("p4port" => defaultPort, "p4port" => defaultPort) #----------------------------------------------------------- # first call to P4: 'p4 users' #----------------------------------------------------------- userHash = {} p4.run("users").each do |u| userName = u['User'] userHash[userName] = u end #----------------------------------------------------------- # second call to P4: 'p4 clients' #----------------------------------------------------------- puts "List of clients:" p4.run("clients").each do |c| clientName,clientOwner = c['client'], c['Owner'] if userHash[clientOwner] != nil puts "#{clientName} owned by #{clientOwner} OK" else puts "#{clientName} owned by #{clientOwner} ** unknown user **" end end