# Task: output local pathnames of opened files # # num of calls to 'p4': 2 # status: tested on Win/NT using P4Ruby API, # 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" p4 = P4.new # p4.port = "localhost:1666" p4.user = "arthur" # p4.client = "dent.development" p4.tagged p4.parse_forms p4.connect begin #----------------------------------------------------------- # first call to P4: 'p4 client -o' #----------------------------------------------------------- cl_spec = p4.fetch_client cl_name = cl_spec['Client'] cl_root = cl_spec['Root'] #----------------------------------------------------------- # second call to P4: 'p4 opened' # # Loop through the output of 'p4 opened'. The tagged # output gives us a client-syntax version of the name # in the form "//clientName/rest-of-local-path", # so we substitute the client root dir before printing. #----------------------------------------------------------- p4.run_opened.each do |o| clientName = o['clientFile'] localName = clientName.sub("//#{cl_name}/", "#{cl_root}") puts localName end rescue P4Exception p4.errors.each { |e| $stderr.puts( e ) } raise end p4.disconnect