# 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
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 4312 | Jeff Bowles |
Adding a number of example scripts that show how to get to Perforce data for a variety of scripting languages and variety of simple tasks. Note that Perl/Python/Ruby (and variants) are included, but shell/batch/DCL/applescript are not. (Am trying to stick with somewhat-portable approaches, to make comparisons easier.) Each program is written in the following languages/configurations: 1. Perl, calling "p4 -Ztag" for data 2. Perl, calling Tony Smith's "P4Perl" module 3. Python, calling "p4 -G" for data 4. Ruby, calling "p4 -R" for data 5. Ruby, calling Tony Smith's "P4Ruby" module The programs do the following: a. compare client specs to users (find old clients) b. compare two labels c. determine which client specs use compression. d. determine which files need to be "p4 add'ed." e. output list of 'opened' files, using local pathnames. |