开发者

Transfer to New Owner of all streams in a ClearCase VOB / Possible script?

One administrator is leaving the project (he is NOT Vob owner)

In his name:

  • he is owner of a lot of projects, streams and other objects
  • he is the "lock" owner of streams where each time different people are excluded on.

A new administrator is entering the 开发者_运维技巧project.

I wonder if a script exists that lets me chown all existing objects and which replaces the "lock" owner on streams.

That would save some hours manually writing down the excluded users on a stream, unlocking and locking again for the new administrator.


That the real pain point with the lock mechanism: if you unlock (which you need to do if you want to perform a cleartool protect -chown), you are loosing the list of users you excluded from a given lock.

A starting point to script that kind of operation is this IBM document "How to list locked VOBs":

  • Windows: for /F %v in ('cleartool lsvob -short') do cleartool lslock vob:%v
  • Unix: for i incleartool lsvob -short -host ; do cleartool lslock vob:$i; done

Leave me as a comment the Os on which you will perform those operations, and I will complete this answer with a script.


For instance, a quick DOS script chown_locked.cmd would be:

@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
doskey ct=cleartool $*

set ucmObject=%1 & REM #project:aProject@\aPVob or stream:aStream@\aPVob
set anOldUser=%2 & REM #previous owner of the streams
set anOldUser=%anOldUser:~0,-1%

set lsstreamCmd=ct lsstream -in %ucmObject% -fmt "%%Xn %%[locked]p %%u\n"
for /F "tokens=1-3" %%a in ( ' %lsstreamCmd% ') do (
    rem echo '%%a'
    rem echo '%%b'
    rem echo '%%c'
    if "%%b" EQU "locked" (
        if "%%c" EQU "%anOldUser%" (
            call:chown %%a %USERNAME%
        ) else (
            echo.ignore locked %%a because not owned by %anOldUser%, but by '%%c'
        )
    ) else (
        echo.ignore unlocked %%a
    )
)

goto end

:chown ucmObject -- chown on a ucm object
::                  if lock, will restore the nusers lock exception list
::                  -- streamName [in] name of the UCM object
::                  -- newOwner   [in] name of new owner                           
SETLOCAL ENABLEDELAYEDEXPANSION
set ucmObject=%~1
set newOwner=%~2
set cmd=ct lslock %ucmObject%
for /F "tokens=4*" %%a in ( ' %cmd% ^| find "Locked except for users:" ') do set lslock=%%b
set lslock=%lslock:~0,-1%
rem echo lslock '%lslock%'
if "%lslock%" NEQ "~0,-1" goto lslock
echo.chown locked '%ucmObject%%' for '%newOwner%'
ct protect -chown %newOwner%2 %ucmObject% & goto endchown
:lslock
set lslock2=%lslock: =,%
rem echo lslock2 '%lslock2%'
echo.chown locked '%ucmObject%' for '%newOwner%' while retaining '%lslock2%'
ct unlock %ucmObject%
ct protect -chown %newOwner% %ucmObject%
ct lock -nusers %lslock2% %ucmObject%
:endchown
( ENDLOCAL
)
EXIT /b
:end
( ENDLOCAL
)

Call it on a project, or a stream (with sub-streams) within a project, like so:

chown_locked.cmd project:myProject@\aPVobName aPreviousOwner
chown_locked.cmd stream:aStream@\aPVobName aPreviousOwner

It will protect any sub-stream to the current user if said sub-streams are:

  • locked
  • locked with the right owner (the previous one who has left)

If a sub-stream is locked with a -nusers list of excluded users (excluded from the lock), this list is saved before the unlock, and restore when locking the stream again.

Of course, it will only work if the current user is ClearCase administrator (i.e. is in the same group than the ClearCase_albd user): only this king of user can do a chown on a ClearCase object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜