## p4revert-client ## aaron bockelie <# .SYNOPSIS Unlocks and reverts all files for a given client. .DESCRIPTION Reverting all files for a given client can be tedious. This function assists the task by automating the unlock and revert task. After the task is complete, a record of the reverted files is returned in a record object. You must have Perforce super permissions in order for this function to operate correctly. .EXAMPLE This example reverts all files on the clientspec 'voltron2', which belongs to a user called p4infosysadmin [PS] C:\Users\aaronadmin>p4revert-client voltron2 revertcomplete client notreverted reverted -------------- ------ ----------- -------- True voltron2 {@{depotFile=//depot/servi... The returned object contains the following objects: revertcomplete: a boolean value returning the status of the command. This is false if there are any files not reverted client: the name of the client operated against. notreverted: an array of depot files that could not be reverted. reverted: an array of depot files that were successfully reverted. .PARAMETER clientname The client you wish to revert and unlock all files on. .FUNCTIONALITY This function simplifies the administrative overhead of reverting any and all files for a given client. #> Function p4revert-client {param([Parameter(Mandatory = $true)]$clientname)#begin function p4remove-object $servercheck = p4get-server $unlockstatus = $null $revertstatus = $null $errorprefs = $erroractionpreference #store original error action preference. $UserElevatedPrivs = $false $ErrorActionPreference = "Continue" if ($servercheck.pingsuccess.equals($true)) { $clientOpenFilesCount = $null $clientopenfiles = $null $client = $null $client = p4get-client $clientname if ($client -ne $null) { $authgroup = p4get-authgroups #grab the auth groups for this depot if ($authgroup.count) { $authgroup = $authgroup[0].name #the first auth group in the array is always the parent authgroup } else { $authgroup = $authgroup.name } $groupobject = p4get-group $authgroup #get the details of the authgroup (memberships, owners, subgroups etc) if ($groupobject | %{$_.users -notcontains $client.owner}) { p4tempauth -grant -username $client.owner -authgroup $authgroup -justification ("Automated attempt to revert a clientspec for user " +$client.owner) $UserElevatedPrivs = $true } $clientopenfiles = p4get "opened -C" $client.client if ($clientopenfiles -ne $null) { p4 login $client.owner >$null | out-null $activity = "Unlocking checked out files on client " + $client.client foreach ($file in $clientopenfiles) #unlock files { p4 unlock -f $file.depotfile 2>$unlockstatus | out-null } $activity = "Reverting checked out files on client " + $client.client $i=1 #set counter $clientOpenFilesCount = $clientopenfiles.count foreach ($file in $clientopenfiles) #revert files { if ((($clientOpenFilesCount) -eq ($null)) -or (($clientOpenFilesCount) -eq (0))) #if there is only one file, so we don't divide by zero. { $percentcomplete = 1 } else { $percentcomplete = (($i/$clientOpenFilesCount)*100) } write-progress -id 100 -activity ("Reverting files on clientspec " + $client.client) -status ("Reverting file(s) " + $file.depotFile.tostring()) -percentcomplete $percentcomplete p4 shelve -d -f $file.depotfile.tostring() 2>$shelvestatus | out-null if ($client.host) { p4 -c $client.client -H $client.Host -u $client.Owner revert -k $file.depotfile.tostring() >$revertstatus | out-null } else { p4 -c $client.client -H $env:computername -u $client.Owner revert -k $file.depotfile.tostring() >$revertstatus | out-null } } } $cantrevertfiles = p4get "opened -C" $client.client if ($cantrevertfiles -ne $null) { $revertstatus = $false $message = "Unable to revert all files in client `'" + $client.client + "`'" write-warning $message } else { $revertstatus = $true } } } if ($userelevatedprivs = $true) { p4tempauth -revoke -username $client.owner -authgroup $authgroup -justification ("Concluding attempt to revert a clientspec for user " +$client.owner) $UserElevatedPrivs = $false } write-progress -id 100 -completed -activity "Complete." -status "Complete." return new-object psobject -property @{"client" = $client.client;"reverted" = $clientopenfiles;"notreverted" = $cantrevertfiles;"revertcomplete" = $revertstatus} $erroractionpreference = $errorprefs }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 8410 | Aaron Bockelie |
Root checkin, Perforce Powershell wrapper. Still lots of work to be done, namely documentation and deployment tools, for instance, get-help needs work on the majority of these tools. Additionally, the /lib structure needs a little bit of condensation, probably into major groups (depot, userspec, clientspec, group management, and so on) that way function family can exist under each resource. |