# 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 P4Ruby API # # room for optimization/improvement: add getopts call # # Copyright 2004 Perforce Corporation, Inc. All rights reserved. require "P4" 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 = P4.new p4.port = defaultPort if defaultPort != nil p4.user = defaultUser if defaultUser != nil p4.tagged p4.parse_forms p4.connect begin #----------------------------------------------------------- # 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 rescue P4Exception p4.errors.each { |e| $stderr.puts( e ) } raise end p4.disconnect