1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Rational ClearCase

Discussion in 'T&T - Scripting' started by krischik, Feb 11, 2010.

  1. krischik

    Joined:
    Feb 20, 2009
    Messages:
    46
    Likes Received:
    1
    Over the time I wrote some helpful Scripts to use with Rational ClearCase which I like to share in this thread.
     
  2. krischik

    Joined:
    Feb 20, 2009
    Messages:
    46
    Likes Received:
    1
    Checkout_Files.cmd

    The first thing a ClearCase user notices on Windows is that ClearCase does not understand wild-cards. This is why I created the following Script:

    Code:
    @ECHO OFF
    
    IF NOT "%@Eval[2 + 2]%" == "4" (ECHO TCC/LE [http://www.jpsoft.com/] is needed to execute this script. & EXIT /B 1)
    
    SETLOCAL
        SET      in_Files=%@If[%@Len[%[1]] != 0,%[1],*]
        SET    in_Comment=%@If[%@Len[%[2]] != 0,%[2],"Check-out by Checkout_Files.cmd"]
    
        PUSHD "%@PATH[%@FULL[%[in_Files]]]"
            ECHO ^e[42mCheckout Files:   ^e[43m%[in_Files]^e[m
            DO I IN %@FILENAME[%[in_Files]]
                cleartool checkout -unreserved -ptime -comment %[in_Comment] "%[I]"
            ENDDO
        POPD
    ENDLOCAL
    
    Sure one can use %@Expand instead of a DO loop - but beware: The windows command-line buffer is rather short when compared to unix and you might quickly run out of space.

    Martin
     
  3. krischik

    Joined:
    Feb 20, 2009
    Messages:
    46
    Likes Received:
    1
    Checkout_Tree.cmd

    Wild-card matching is quite nice but often you might want to check out all files in a directory tree. This is what the next script does:

    Code:
    @ECHO OFF
    
    IF NOT "%@Eval[2 + 2]%" == "4" (ECHO TCC [http://www.jpsoft.com/] is needed to execute this script. & EXIT /B 1)
    
    SETLOCAL
        SET  in_Directory=%@If[%@Len[%[1]] != 0,%[1],.]
        SET    in_Comment=%@If[%@Len[%[2]] != 0,%[2],"Check-out by Checkout_Tree.cmd"]
    
        cleartool checkout -unreserved -ptime -comment %[in_Comment] "%[in_Directory]"
    
        PUSHD %[in_Directory]
            ECHO ^e[42mCheckout Tree:    ^e[43m%[in_Directory]^e[m
            DO Line IN /P cleartool ls -recurse -short -nxname -vob_only
                cleartool checkout -unreserved -ptime -comment %[in_Comment] "%[Line]"
            ENDDO
        POPD
    ENDLOCAL
    
     
  4. krischik

    Joined:
    Feb 20, 2009
    Messages:
    46
    Likes Received:
    1
    Checkin_Files.cmd

    The check-in in ClearCase is the greatest pain conceivable as ClearCase considered unchanged files an error. The following script will first compare the file with the last version and if the file has not changed perform an uncheckout instead of a checkin. This is the way it should have been all along:

    Code:
    @ECHO OFF
    
    IF NOT "%@Eval[2 + 2]%" == "4" (ECHO TCC/LE [http://www.jpsoft.com/] is needed to execute this script. & EXIT /B 1)
    
    SETLOCAL
        SET      in_Files=%@If[%@Len[%[1]] != 0,%[1],*]
        SET    in_Comment=%@If[%@Len[%[2]] != 0,%[2],"Check-in in by Checkin_Files.cmd"]
    
        PUSHD "%@PATH[%@FULL[%[in_Files]]]"
            ECHO ^e[42mCheckin Files:    ^e[43m%[in_Files]^e[m
            DO I IN %@FILENAME[%[in_Files]]
                IFF %@Exec[cleartool diff -predecessor "%[I]" 1>/dev/nul 2>/dev/nul] THEN
                    cleartool checkin -ptime -comment %[in_Comment] "%[I]"
                ELSE
                    cleartool uncheckout -rm "%[I]"
                ENDIFF
            ENDDO
        POPD
    ENDLOCAL
    
     
  5. krischik

    Joined:
    Feb 20, 2009
    Messages:
    46
    Likes Received:
    1
    Checkin_Tree.cmd

    If you check out directory trees then you want to check them in as well. This Script too uses uncheckout on files which have not changed - which gives a distinct advantage over the find checkout function of the ClearCase GUI.

    Code:
    @ECHO OFF
    
    IF NOT "%@Eval[2 + 2]%" == "4" (ECHO TCC/LE [http://www.jpsoft.com/] is needed to execute this script. & EXIT /B 1)
    
    SETLOCAL
        SET  in_Directory=%@If[%@Len[%[1]] != 0,%[1],.]
        SET    in_Comment=%@If[%@Len[%[2]] != 0,%[2],"Check-in in by Checkin_Tree.cmd"]
    
        PUSHD %[in_Directory]
            ECHO ^e[42mCheckin Tree:     ^e[43m%[in_Directory]^e[m
            DO Line IN /P cleartool lscheckout -recurse -short -me
                IFF %@Exec[cleartool diff -predecessor "%[Line]" 1>/dev/nul 2>/dev/nul] THEN
                    cleartool checkin -ptime -comment %[in_Comment] "%[Line]"
                ELSE
                    cleartool uncheckout -rm "%[Line]"
                ENDIFF
            ENDDO
        POPD
    ENDLOCAL
    
     
  6. krischik

    Joined:
    Feb 20, 2009
    Messages:
    46
    Likes Received:
    1
    Add_Tree.cmd

    The most painful missing function in ClearCase is the omission of a recursive mkelem. This makes the initial check-in of your new project a real pain. This is why I wrote the following script:

    Code:
    @ECHO OFF
    
    IF NOT "%@Eval[2 + 2]%" == "4" (ECHO TCC/LE [http://www.jpsoft.com/] is needed to execute this script. & EXIT /B 1)
    
    ON ERROR QUIT
    
    SETLOCAL
        ON BREAK GOTO Catch
        ON ERROR GOTO Catch
    
        SET  in_Directory=%@If[%@Len[%[1]] != 0,%[1],.]
        SET    in_Comment=%@If[%@Len[%[2]] != 0,%[2],"Added by Add_Tree.cmd"]
        SET      Basename=%@Name[%@Full[%[in_Directory]]]
    
        PUSHD %[in_Directory]\..
        ::
        :: Note: You cannot add the current directory!
        ::
        SET Info=%@ExecStr[cleartool ls -directory .]
    
        IFF %@Index[%[Info],CHECKEDOUT,0] == 0 THEN
            ECHO ^e[42mCheckout Directory: ^e[43m%[_CWD]^e[m
            cleartool checkout -comment %[in_Comment] "."
        ENDIFF    cleartool checkout -comment %[in_Comment] .
    
        SET Info=%@ExecStr[cleartool ls -directory "%[Basename]"]
    
        IFF %@Index[%[Info],Rule:,0] == 0 THEN
            ECHO ^e[42mAdding Directory:   ^e[43m%[_CWDS]%[Basename]^e[m
            cleartool mkelem -mkpath -comment %[in_Comment] "%[Basename]"
        ELSEIFF %@Index[%[Info],CHECKEDOUT,0] == 0 THEN
            ECHO ^e[42mCheckout Directory: ^e[43m%[_CWDS]%[Basename]^e[m
            cleartool checkout -comment %[in_Comment] "%[Basename]"
        ENDIFF
        POPD
        PUSHD %[in_Directory]
        DO I IN /S /A:+D *
            SET Info=%@ExecStr[cleartool ls -directory "%[I]"]
    
            IFF %@Index[%[Info],Rule:,0] == 0 THEN
            ECHO ^e[42mAdding Directory:   ^e[43m%[_CWDS]%[I]^e[m
            cleartool mkelem -mkpath -comment %[in_Comment] "%[I]"
            ELSEIFF %@Index[%[Info],CHECKEDOUT,0] == 0 THEN
            ECHO ^e[42mCheckout Directory: ^e[43m%[_CWDS]%[I]^e[m
            cleartool checkout -comment %[in_Comment] "%[I]"
            ENDIFF
        ENDDO
        DO I IN /S /A:-D *
            SET Info=%@ExecStr[cleartool ls "%[I]"]
    
            IFF %@Index[%[Info],Rule:,0] == 0 THEN
            ECHO ^e[46mAdding File:   ^e[43m%[_CWDS]%[I]^e[m
            cleartool mkelem -comment %[in_Comment] "%[I]"
            ENDIFF
        ENDDO
        POPD
    ENDLOCAL
    
    QUIT 0
    
    :Catch
        ECHO Ein Fehler ist aufgetreten. 
        ECHO    return code:  %[_?]
        ECHO    system error: %[_SYSERR]: %@ErrText[%_SYSERR]
    ENDLOCAL
    
    CANCEL 1
    
    As you can see it is rather complex and still it works only with dynamic views.
     

Share This Page