views:

483

answers:

1

Hi;

In ClearCase, you can list the content of a directory using "cleartool ls".

My question is how can I do the same thing using CAL (ClearCase Automation Layer). The reason I prefer the COM API is because I won't have to parse the output of "ls".

So far, I am able to get the VOB and the View successfully, but I didn't find any method for listing the content.

My code so far:

IClearCase cc = new ApplicationClass();
CCVOB vob = cc.get_VOB("\\VOB-name");
CCView view = cc.get_View("ViewTag");

Thank you for your help.

I wrote VonC's answer in C# for those interrested.

string[] files = Directory.GetFiles("View path here", "*.*", SearchOption.AllDirectories);
foreach (string file in files)
{
    try
    {
            CCVersion ver = cc.get_Version(file);
            Console.WriteLine(ver.Path);
    }
    catch(Exception) {/*the file is not versioned*/}
}
+1  A: 

May be this is a good start:

Set CC = Wscript.CreateObject("ClearCase.Application") 
Set DirVer = CC.Version(".") 
Set FSO = CreateObject("Scripting.FileSystemObject") 
Set Folder = FSO.GetFolder(DirVer.Path) 
Wscript.Echo "Files under source control: " 
For Each File in Folder.Files 
     On Error Resume Next 
     Set Ver = CC.Version(File.Name) 
     If Err.Number = 0 Then 
           Wscript.Echo Ver.ExtendedPath 
     End If 
Next

The idea being to use ICCVersion methods to try accessing the version of a file. If it does not return an error, it is indeed a versioned file.


Now I know the file is versioned, how can I remove it (rmname).

Do not use RemoveVersion():
Removes irretrievably the version (equivalent to cleartool rmver)
WARNING! This is a potentially destructive operation. Because CAL does not prompt the user for input under any circumstances, there is no confirmation step when RemoveVersion is invoked. Invoking RemoveVersion is equivalent to running cleartool rmver with the -force option.

Instead use the RemoveName from the ICCElement interface.

VonC
CC.Version(".") will only work if you set the current directory to the view path (through Environement.CurrentDirectory in C#). If it's the case, can't jou just remove the second line, and do "Set Folder = FSO.GetFolder("-- your view path here --")" ?In other word, the second line is necessary?Ty.
In the case you mention, this second line would be unnecessary indeed. But I have not fully tested yet.
VonC
Ok, ty again. If I dare to add another little question. Now I know the file is versioned, how can I remove it (rmname). There is RemoveVersion(...), but I am not sure it's the equivalent of rmname.
Warning: there are two "remove version" in ClearCase: rmver is the most dangerous one since it remove *definitively* the version from the VOB. Rmname just dereferences the version from the list of files referenced by its parent directory.
VonC
Use RemoveName from the ICCElement interface instead.
VonC
Thank you for the information. So, basicaly, using ICCElement, we can also check if a file is versioned? I've just tried it, and it throws a "Not a VOB object" if the item is not versioned.
Correct. Simply ICCElement gives other services about a versioned file: services common for any version (whereas ICCVersion gives access to the current visible version of the element)
VonC