#!/usr/bin/ruby #-- #------------------------------------------------------------------------------- #++ # # = Introduction # # A script to identify your oldest and mouldiest Perforce clients. These # are the clients that are least recently used and are thus candidates for # deletion. # # = Usage # # oldclients.rb -m # # = License # # Copyright (c) 1997-2004, Perforce Software, Inc. 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. # #-- #------------------------------------------------------------------------------- #++ require "P4" require "getoptlong" # # Simple class to enable sorting of clients by access time instead of # by name # class Client def initialize( hash ) @attrs = hash end def <=>( other ) @attrs[ "Access" ].to_i <=> other.attrs[ "Access" ].to_i end def fmt sprintf( "Client: %-20s Owner: %-15s Accessed: %s", attrs[ "client" ], attrs[ "Owner" ], Time.at( attrs[ "Access" ].to_i ).strftime( "%Y/%m/%d" ) ) end protected attr_reader :attrs end #-- #------------------------------------------------------------------------------- # START OF MAIN SCRIPT #------------------------------------------------------------------------------- #++ # # By default show all clients # max = -1 opts = GetoptLong.new( [ "-m", GetoptLong::REQUIRED_ARGUMENT ] ) opts.each { |opt,arg| max = arg.to_i if( opt == "-m" ) } begin p4 = P4.new p4.exception_level = 1 p4.connect clients = p4.run_clients.collect do |c| Client.new( c ) end.sort clients[1..max].each do |c| puts( c.fmt() ) end rescue P4Exception $stderr.puts( "Errors during script execution:" ) p4.errors.each { |e| $stderr.puts( e ) } exit( 1 ) end