Topic
  • 6 replies
  • Latest Post - ‏2013-10-24T10:33:56Z by Meridian_
SystemAdmin
SystemAdmin
47290 Posts

Pinned topic Perl with CAL

‏2005-06-13T12:32:03Z |
Hi all,

Thanks to all for the gr8 info.

I want to use Perl with CAL (ClearCase Automation Library). I am writing a script to find the list of activities delivered to integration stream in a day & the change set and would like to use CAL for it. Please let me know if you have used CAL for UCM. I tried the help, it is little difficult to figure out.

It would be helpfull if you can get me some examples.

Thanks

Unni...
  • SystemAdmin
    SystemAdmin
    47290 Posts

    Re:Perl with CAL

    ‏2005-06-13T12:49:54Z  
    Hi Scorp,

    Here is an example of using CAL with perl. In this example.
    This example just displays informtion about all the branches sprouting
    from a version.
    Do let me know in case of more help.
    And one more thing CAL is not supported bu the Perl version shipped along
    with CC

    1. The syntax used here was compatible with ActiveState build 522.
    use Win32::OLE;
    1. Connect to the top-level ClearCase object
    my $cc = Win32::OLE->new('ClearCase.Application')
    or die "Could not create Application object\n";
    1. Loop over the branches sprouting from a version and display their
    2. paths using the default property of ICCBranch, and other information
    my $ver = $cc->Version("b:\\caroltest\\testelem.c@@\\main\\0")
    or die("Could not get version: ", Win32::OLE->LastError(), "\n");
    my $path = $ver->Path;
    my $subbranches = $ver->SubBranches;
    my $enum = Win32::OLE::Enum->new($subbranches);
    while (defined(my $branch = $enum->Next)) {
    print($branch->Path, " branch sprouting from ", $path, " has ",
    $branch->Versions->Count, " version(s); latest version is ",
    $branch->LatestVersion->VersionNumber, "\n");
    }

    Thanks & Regards
    Komal Joshi
    "@scorp" <disadmin@us.ibm.com>
    Sent by: owner-cciug@lists.us.ibm.com
    06/13/2005 06:02 PM
    Please respond to
    cciug
    To
    cciug@lists.us.ibm.com
    cc

    Subject
    cciug Perl with CAL
    Hi all,

    Thanks to all for the gr8 info.

    I want to use Perl with CAL (ClearCase Automation Library). I am writing a
    script to find the list of activities delivered to integration stream in a
    day & the change set and would like to use CAL for it. Please let me
    know if you have used CAL for UCM. I tried the help, it is little
    difficult to figure out.

    It would be helpfull if you can get me some examples.

    Thanks

    Unni...
    <============================================================
    To unsubscribe, send email to
    majordomo@lists.us.ibm.com and put these words in the
    message body: unsubscribe cciug
    ============================================================>

    http://att1.html
  • SystemAdmin
    SystemAdmin
    47290 Posts

    Re: Re:Perl with CAL

    ‏2005-06-14T03:40:10Z  
    Hi Scorp,

    Here is an example of using CAL with perl. In this example.
    This example just displays informtion about all the branches sprouting
    from a version.
    Do let me know in case of more help.
    And one more thing CAL is not supported bu the Perl version shipped along
    with CC

    1. The syntax used here was compatible with ActiveState build 522.
    use Win32::OLE;
    1. Connect to the top-level ClearCase object
    my $cc = Win32::OLE->new('ClearCase.Application')
    or die "Could not create Application object\n";
    1. Loop over the branches sprouting from a version and display their
    2. paths using the default property of ICCBranch, and other information
    my $ver = $cc->Version("b:\\caroltest\\testelem.c@@\\main\\0")
    or die("Could not get version: ", Win32::OLE->LastError(), "\n");
    my $path = $ver->Path;
    my $subbranches = $ver->SubBranches;
    my $enum = Win32::OLE::Enum->new($subbranches);
    while (defined(my $branch = $enum->Next)) {
    print($branch->Path, " branch sprouting from ", $path, " has ",
    $branch->Versions->Count, " version(s); latest version is ",
    $branch->LatestVersion->VersionNumber, "\n");
    }

    Thanks & Regards
    Komal Joshi
    "@scorp" <disadmin@us.ibm.com>
    Sent by: owner-cciug@lists.us.ibm.com
    06/13/2005 06:02 PM
    Please respond to
    cciug
    To
    cciug@lists.us.ibm.com
    cc

    Subject
    cciug Perl with CAL
    Hi all,

    Thanks to all for the gr8 info.

    I want to use Perl with CAL (ClearCase Automation Library). I am writing a
    script to find the list of activities delivered to integration stream in a
    day & the change set and would like to use CAL for it. Please let me
    know if you have used CAL for UCM. I tried the help, it is little
    difficult to figure out.

    It would be helpfull if you can get me some examples.

    Thanks

    Unni...
    <============================================================
    To unsubscribe, send email to
    majordomo@lists.us.ibm.com and put these words in the
    message body: unsubscribe cciug
    ============================================================>

    http://att1.html
    Hi komal,

    Thanks for the expl. But this is for base clearcase, how about for UCM? I am using ActivePerl for developing the application. Will that be a stumbling block.

    Regards,

    Unni
    @Scorp is my nickname)
  • SystemAdmin
    SystemAdmin
    47290 Posts

    Re:Re: Re:Perl with CAL

    ‏2005-06-14T05:28:10Z  
    Hi komal,

    Thanks for the expl. But this is for base clearcase, how about for UCM? I am using ActivePerl for developing the application. Will that be a stumbling block.

    Regards,

    Unni
    @Scorp is my nickname)
    Hi Scorp,

    Nops you can use CAL with base CC as well as UCM.
    You could use CAL with perl to extract information about the UCM activity.
    Here is an exmaple which could allow you to get start with Perl ,CAL and
    UCM. Do let me know in case you need some help.It would be a learning
    experience for me.
    _________________________________________________________________________
    #! perl
    #
    1. This script will query a ClearQuest database for all activities whose
    2. UCM project is the specified project and whose state is in
    3. the given statelist and for each of those, will extract
    4. it's change set. The result will be a report sent to
    5. standard out or to MS Excel depending on whether you specify
    6. the -excel option.
    #
    use Win32::OLE;
    use Getopt::Long;
    use Tk;

    #-------------------------------------------------------------------------------
    1. Some useful constants for the benefit of the CQ API
    #-------------------------------------------------------------------------------
    $AD_PRIVATE_SESSION = 2; # Only one client can access this
    session?s data
    $AD_BOOL_OP_AND = 1; # Boolean AND operator
    $AD_BOOL_OP_OR = 2; # Boolean OR operator

    $AD_COMP_OP_EQ = 1; # Equality operator
    $AD_COMP_OP_NEQ = 2; # Inequality operator

    $AD_SUCCESS = 1; # The next record in the request set was
    successfully obtained

    #-------------------------------------------------------------------------------
    1. Setting the $DEBUG variable will cause verbose printing
    2. of debugging messages
    #-------------------------------------------------------------------------------
    1. $DEBUG = 1;

    #-------------------------------------------------------------------------------
    1. Info for help messages
    #-------------------------------------------------------------------------------
    my ($NAME, $THISDIR) = ($0 =~ m#^(.*)[/|\]([^/|\]+)$#o) ? ($2, $1) :
    ($0, '.');

    $SYNOPSIS = "$NAME -help {-cqlogin clearquest_login_id}
    {-cqpasswd
    clearquest_password}
    {-cqdb
    clearquest_database_id}
    {-project
    project_name}
    {-statelist
    list_of_states}
    -excel
    {-cli
    ";

    $ARGUMENTS = "
    help Displays this message and exits.
    cqlogin A valid ClearQuest login ID
    cqpasswd The password associated with the given ClearQuest
    login ID
    cqdb The logical 5-character name of the
    ClearQuest database
    to log into.
    project The project on which to report
    statelist A list of states to refine the query
    (comma-separated, no
    spaces)
    excel Export report to Excel spreadsheet
    instead of printing it
    to the screen
    cli Don't put up the GUI asking for info.
    Take it from
    the command-line only
    ";

    $DESCRIPTION = "
    $NAME will query a ClearQuest database for all activities whose
    UCM project is the specified project and whose state is
    in
    the given statelist and for each of those, will extract
    it's change set. The result will be a report sent to
    standard out or to MS Excel depending on whether you
    specify
    the -excel option.
    ";

    #-------------------------------------------------------------------------------
    1. Parse out the command line
    #-------------------------------------------------------------------------------
    my ($return_status) = GetOptions("cqlogin=s", "cqpasswd=s", "cqdb=s",
    "project=s", "statelist=s", "excel",
    "cli",
    "help");

    #-------------------------------------------------------------------------------
    1. If the "-help" option is set, then print out a usage message
    2. and exit
    #-------------------------------------------------------------------------------
    usage(1) if ($opt_help);

    #-----------------------------------------------------
    1. Create ClearQuest session object
    #-----------------------------------------------------
    print "Creating ClearQuest Session\n" if $DEBUG;
    my ($CQsession) = Win32::OLE->new ("CLEARQUEST.SESSION") or
    die "Can't create ClearQuest session object via call to
    Win32::OLE->new(): $!";

    #-----------------------------------------------------
    1. Get the list of CQ databases to which we can try to log into
    #-----------------------------------------------------
    $AccDatabases = $CQsession->GetAccessibleDatabases("MASTR", "", "");

    #-----------------------------------------------------
    1. Now put those database names into a Perl list
    #-----------------------------------------------------
    $DBCount=@$AccDatabases;
    @dblist = ();
    for ($i=0; $i<$DBCount; $i++) {
    $aDatabase = $AccDatabases->$i;
    $DBName = $aDatabase->GetDatabaseName();
    @dblist = ($DBName, @dblist);
    print "DB Name is $DBName\n" if $DEBUG;
    }

    #-----------------------------------------------------
    1. Use a GUI interface to make things easier to run
    #-----------------------------------------------------
    if (! $opt_cli) {
    print "Painting GUI\n" if $DEBUG;

    $top = MainWindow->new();
    $top->configure("title"=>"ChangeSet Report");
    $top->raise();

    $LoginFrame = $top->Frame(-width=>'50', -relief=>'ridge',

    -borderwidth=>'3')-> pack(-expand=>'1',
    -fill=>'both');
    $LoginFrame->Label(-text=>"ClearQuest Login ID")->pack(
    -expand=>'1');
    $LoginBox =
    $LoginFrame->Entry(-textvariable=>\$opt_cqlogin,
    -width=>'25')->pack(
    -expand=>'1');
    $LoginFrame->Label(-text=>"ClearQuest Password")->pack(
    -expand=>'1');
    $PasswordBox =
    $LoginFrame->Entry(-textvariable=>\$opt_cqpasswd,
    -width=>'25',
    -show=>"*")->pack( -expand=>'1',);

    $LoginFrame->Label(-text=>"ClearQuest Database")->pack(
    -expand=>'1');
    $DbBox = $LoginFrame->Optionmenu( -options => @dblist
    ,
    -textvariable=>\$opt_cqdb,
    -width=>'7')->pack(
    -expand=>'1');

    $QueryFrame = $top->Frame(-width=>'40', -label=>"UCM
    Query Info",
    -relief=>'ridge', -borderwidth=>'3')->
    pack(-expand=>'1', -fill=>'both');
    $QueryFrame->Label(-text=>"UCM Project")->pack(
    -expand=>'1');
    $ProjectBox =
    $QueryFrame->Entry(-textvariable=>\$opt_project,
    -width=>'25')->pack(-expand=>'1');;
    $QueryFrame->Label(-text=>"ClearQuest State List")->pack(
    -expand=>'1');
    $StateBox =
    $QueryFrame->Entry(-textvariable=>\$opt_statelist,
    -width=>'35')->pack(-expand=>'1');

    $EndFrame = $top->Frame(-width=>'40')->pack(-pady=>'10');
    $ExcelButton = $EndFrame->Checkbutton(-text=> "Send
    Report to Excel", -variable=>\$opt_excel)->pack(-side=>'top');
    $OKButton = $EndFrame->Button(-text => "OK",
    -width=>'10',
    -command
    => sub { $top->destroy() })->pack(
    -expand=>1,-padx=>'10',-pady => '5', -side=>'left');
    ;
    $CancelButton = $EndFrame->Button(-text => "Cancel",
    -width=>'10',
    -command
    => sub { exit })->pack(-expand=>1,
    -padx=>'10',-pady => '5', -side=>'right');
    MainLoop();
    }
    #-----------------------------------------------------
    1. If we are using the command line, and the CQ Db wasn't
    2. specified, then issue a usage message and exit
    #-----------------------------------------------------
    if ($opt_cli) {
    usage(2) if ( ! "$opt_cqdb" );
    }

    #-----------------------------------------------------
    1. General testing for required values
    #-----------------------------------------------------
    usage(2) if ( @ARGV or ! $return_status );
    usage(2) if ( ! "$opt_cqlogin" );
    usage(2) if ( ! "$opt_cqpasswd" );
    usage(2) if ( ! "$opt_project" );
    usage(2) if ( ! "$opt_statelist" );

    $loginid = $opt_cqlogin;
    $password = $opt_cqpasswd;
    $database = $opt_cqdb;
    $ucm_project = $opt_project;

    #-----------------------------------------------------
    1. Remove whitespace from the statelist
    #-----------------------------------------------------
    ($statelist = $opt_statelist) =~ s/ //g;

    print "DEBUG: CQ Login is $loginid\n" if $DEBUG;
    print "DEBUG: CQ Password is $password\n" if $DEBUG;
    print "DEBUG: CQ Database is $database\n" if $DEBUG;
    print "DEBUG: CQ Project is $ucm_project\n" if $DEBUG;
    print "DEBUG: CQ State List is $statelist\n" if $DEBUG;

    #-----------------------------------------------------
    1. Parse out the list of states from the statelist
    #-----------------------------------------------------

    @states = split /,/,$statelist;

    #-----------------------------------------------------
    1. Log into ClearQuest
    #-----------------------------------------------------

    print "Logging onto ClearQuest Session\n" if $DEBUG;
    $CQsession->UserLogon("$loginid", "$password", "$database",
    $AD_PRIVATE_SESSION, "");

    #----------------------------------------------------
    1. Get a ClearQuest Query Def object
    2. We will query on All UCM Activities
    #----------------------------------------------------
    print "Building ClearQuest Query\n" if $DEBUG;
    my ($QueryDef) = $CQsession->BuildQuery("All_UCM_Activities");

    #----------------------------------------------------
    1. Specify fields to get as a result of the ClearQuest
    2. Query
    #
    1. This will be the column numbers in this order,
    2. starting at 1, not 0.
    #----------------------------------------------------

    $QueryDef->BuildField("id");
    $QueryDef->BuildField("State");
    $QueryDef->BuildField("headline");
    $QueryDef->BuildField("Owner");
    #----------------------------------------------------
    1. The ucm_vob_object field in CQ holds a CC internal
    2. identifier for the UCM activity associated with the
    3. CQ record
    #----------------------------------------------------
    $QueryDef->BuildField("ucm_vob_object");

    #--------------------------------------------------------
    1. Specify the ClearQuest Query filter tree
    2. ucm_project = specified project
    3. list of states = specified list of states
    #--------------------------------------------------------
    my ($FilterNode1) = $QueryDef->BuildFilterOperator($AD_BOOL_OP_AND);
    $FilterNode1->BuildFilter("ucm_project", $AD_COMP_OP_EQ, "$ucm_project");
    my ($FilterNode2) = $FilterNode1->BuildFilterOperator($AD_BOOL_OP_OR);
    foreach $st (@states) {
    $FilterNode2->BuildFilter("State", $AD_COMP_OP_EQ,
    "$st");
    print "DEBUG: CQ State is $st\n" if $DEBUG;
    }

    #------------------------------------------------------------
    1. Create the ClearQuest result set and execute
    #------------------------------------------------------------
    print "Executing ClearQuest Query\n" if $DEBUG;
    my ($ResultSet) = $CQsession->BuildResultSet($QueryDef);
    $ResultSet->Execute();

    #------------------------------------------------------------
    1. Where do we send the results...
    2. To Excel or to standard out?
    #------------------------------------------------------------
    if ("$opt_excel" ne "1") {
    print("\nResult set of query for record type ",
    $ResultSet->LookupPrimaryEntityDefName(),"\n\n");
    } else {
    $Excel = Win32::OLE->new("Excel.Application") or
    die "Can't create Excel application object via call to
    Win32::OLE->new(): $!";

    #------------------------------------------------------------
    1. Make Excel visible, add a workbook and then populate the
    2. column headers for this report
    #------------------------------------------------------------
    $Excel->{visible} = 1;
    $Excel->Workbooks->Add();
    $Excel->Range("A1")->{Value} = "ID";
    $Excel->Range("B1")->{Value} = "State";
    $Excel->Range("C1")->{Value} = "Owner";
    $Excel->Range("D1")->{Value} = "Headline";
    $Excel->Range("E1")->{Value} = "Change Set";
    }

    #----------------------------------------------------------------
    1. loop through the CQ Query results. Use an initial MoveNext to
    2. get first record
    #----------------------------------------------------------------
    print "Looping through query results\n" if $DEBUG;
    $xlix = 1;
    $records = 0;
    $status = $ResultSet->MoveNext();
    while ( $status == $AD_SUCCESS ) {
    $records++;
    $xlix++;

    print "Processing query result $records\n" if $DEBUG;

    #----------------------------------------------------------------
    1. Get the field values from the returned query result
    #----------------------------------------------------------------
    $id = $ResultSet->GetColumnValue(1);
    $state = $ResultSet->GetColumnValue(2);
    $headline = $ResultSet->GetColumnValue(3);
    $owner = $ResultSet->GetColumnValue(4);
    #----------------------------------------------------------------
    1. Stuff them into Excel or print them to standard out
    #----------------------------------------------------------------
    if ("$opt_excel" eq "1") {
    $Excel->Range("A$xlix")->{Value} = $id;
    $Excel->Range("B$xlix")->{Value} = $state;
    $Excel->Range("C$xlix")->{Value} = $owner;
    $Excel->Range("D$xlix")->{Value} = $headline;
    } else {
    write();
    }
    #----------------------------------------------------------------
    1. Get the CC activity ID from the CQ "ucm_vob_object" field
    #----------------------------------------------------------------
    $activity_id = $ResultSet->GetColumnValue(5);
    #----------------------------------------------------------------
    1. If the activity ID from CQ is null, then say that we have no
    2. change set info
    #----------------------------------------------------------------
    if (! $activity_id ) {
    if ("$opt_excel" ne "1") {
    print " Change Set Info:\n";
    print " ----------------\n";
    print " No ClearCase Activity info
    yet\n";
    }
    } else {
    #----------------------------------------------------------------
    1. If the CC activity ID is not null, then we need to use CAL
    2. to extract the changeset info from the CC activity object
    #----------------------------------------------------------------
    print "Instantiating CAL\n" if $DEBUG;
    my ($CCApp) = Win32::OLE->new
    ("ClearCase.Application") or
    die "Can't create ClearCase
    application object via call to Win32::OLE->new(): $!";
    print "Processing Activity info\n" if
    $DEBUG;
    #----------------------------------------------------------------
    1. Get an activity object from CAL
    #----------------------------------------------------------------
    $myactivity =
    $CCApp->Activity($activity_id);
    if (! $myactivity ) {
    print "Can not resolve
    activity info in ClearCase\n";
    } else {
    $view = $myactivity->NameResolverView;

    #----------------------------------------------------------------
    1. Get the activity's change set, which is a CCVersions collection.
    2. Use the activity's "nameresolver view" for name resolution.
    #----------------------------------------------------------------
    $ChangeSet =
    $myactivity->ChangeSet($view, "False");
    $CS_Entries = $ChangeSet->Count;

    #----------------------------------------------------------------
    1. Loop through the CCVersions collection, collecting the names of
    2. the versions for printing.
    #----------------------------------------------------------------
    print "Getting ChangeSet info\n" if
    $DEBUG;
    $CS_Index = 1;
    while ($CS_Index <= $CS_Entries) {
    print "Processing ChangeSet entry
    $CS_Index\n" if $DEBUG;
    $Version =
    $ChangeSet->Item($CS_Index);
    $VersionPN =
    $Version->ExtendedPath;
    if ("$CS_Index" eq "1") {
    $cs_list = $VersionPN;
    } else {
    $cs_list = $cs_list . "\n" .
    $VersionPN;
    }
    $CS_Index++;
    }

    print "Printing ChangeSet\n" if
    $DEBUG;
    if ("$opt_excel" eq "1") {
    $Excel->Range("E$xlix")->{Value} =
    "$cs_list";
    } else {
    print "Change Set Info:\n";
    print "----------------\n";
    print "$cs_list\n";
    print "\n";
    }
    }
    }
    $status = $ResultSet->MoveNext();
    }
    if ("$opt_excel" ne "1") {
    print("\n$records activities were found\n");
    print "Press any key to exit\n";
    $ans=<STDIN>;;
    }
    exit(0);

    #---------------------------------------------------------
    1. print out help if needed
    #---------------------------------------------------------
    sub usage {
    my ($level) = @_;

    $level = 2 unless ( $level =~ /^\d+$/o );

    print "\nUsage: ${SYNOPSIS}\n";
    print "\nArguments:${ARGUMENTS}${DESCRIPTION}\n" unless ( $level > 1 );
    exit($level);
    }

    format STDOUT_TOP =
    ID State Owner Headline





    .

    format STDOUT =
    @<<<<<<<<<<<< @<<<<<<<<< @<<<<<<<<<
    ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $id, $state, $owner $headline
    ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $headline
    .

    _________________________________________________________________________
    More information can be obtained from this location(I am also a novice
    user of CAL)

    http://www-106.ibm.com/developerworks/rational/library/content/RationalEdge/nov01/changeset_report.txt
    Thanks & Regards
    Komal Joshi
    "@scorp" <disadmin@us.ibm.com>
    Sent by: owner-cciug@lists.us.ibm.com
    06/14/2005 09:10 AM
    Please respond to
    cciug
    To
    cciug@lists.us.ibm.com
    cc

    Subject
    cciug Re: Re:Perl with CAL
    Hi komal,

    Thanks for the expl. But this is for base clearcase, how about for UCM? I
    am using ActivePerl for developing the application. Will that be a
    stumbling block.

    Regards,

    Unni
    @Scorp is my nickname)
    <============================================================
    To unsubscribe, send email to
    majordomo@lists.us.ibm.com and put these words in the
    message body: unsubscribe cciug
    ============================================================>

    http://att1.html
  • SystemAdmin
    SystemAdmin
    47290 Posts

    Re: Perl with CAL

    ‏2005-06-14T07:30:50Z  
    Hiya,
    As an exmaple here's a little sub that, given a UCM stream ($streamvar)will return a view attached to it for the current user:

    sub getusrview {
    my $cc = Win32::OLE->new('ClearCase.Application')
    or die "Could not create Application object\n";

    my $streamobj = $cc->Stream("stream:$streamvar")
    or die "Could not create stream object\n";
    my $user = $ENV{'USERNAME'};

    #find views owned by user in stream
    my $views = $streamobj->Views("DOMAIN\\$user")
    or die ("$0 ",__LINE__,":OLE Error: ",Win32::OLE->LastError(), "\n");

    #return first "good" view which means a view for which we
    1. can retrieve it's tag without falling over
    my $index =1;
    while ( $index <= $views->Count) {
    my $tag = $views->Item($index)->Tagname;

    if(Win32::OLE->LastError() != 0) {
    Win32::OLE->LastError(0);
    $index++;
    next;
    }
    return ($tag);
    $index++;
    }
    }

    So using the above as a kind of base, once you get the streamobj you're after, you might do something like:

    my $activities = $streamobj->Activities;
    #loop through ativities and filter out ones that have
    #"Integration activity created by deliver on 14/06/2005"
    1. in their comments
    my $index =1;
    while ( $index <= $activities->Count) {
    if (($activities->Item($index)->Comment) =~ /Integration activity created by deliver on 14\/06\/2005/) {
    #this is an activity delivered to this stream on 14/06/05, do something with it
    ;
    }
    $index++;
    }
    The CAL.chm is woefully lacking when it comes to Perl examples, but you can usually get an idea of how to get stuff from the VB examples. I also found that the Object Browser in the VB IDE is an invaluable source of properties, methods, what they return etc.

    Hope that helps; if you want to do more fancy processing with the dates from the creation record, yell coz you will need to do some fancy footwork with Win32::OLE::Variant ...

    Of course, you could always avoid all the above and just use the cleartool object to run a "lsact -fmt <fmt>" to get what you need:-)

    As for ActivePerl the above works with:
    ccperl -V
    revision 5 version 6 subversion 1
    ...
    Locally applied patches:
    ActivePerl Build 629
    Cheers
  • SystemAdmin
    SystemAdmin
    47290 Posts

    Re: Perl with CAL

    ‏2005-06-24T06:24:32Z  
    Hiya,
    As an exmaple here's a little sub that, given a UCM stream ($streamvar)will return a view attached to it for the current user:

    sub getusrview {
    my $cc = Win32::OLE->new('ClearCase.Application')
    or die "Could not create Application object\n";

    my $streamobj = $cc->Stream("stream:$streamvar")
    or die "Could not create stream object\n";
    my $user = $ENV{'USERNAME'};

    #find views owned by user in stream
    my $views = $streamobj->Views("DOMAIN\\$user")
    or die ("$0 ",__LINE__,":OLE Error: ",Win32::OLE->LastError(), "\n");

    #return first "good" view which means a view for which we
    1. can retrieve it's tag without falling over
    my $index =1;
    while ( $index <= $views->Count) {
    my $tag = $views->Item($index)->Tagname;

    if(Win32::OLE->LastError() != 0) {
    Win32::OLE->LastError(0);
    $index++;
    next;
    }
    return ($tag);
    $index++;
    }
    }

    So using the above as a kind of base, once you get the streamobj you're after, you might do something like:

    my $activities = $streamobj->Activities;
    #loop through ativities and filter out ones that have
    #"Integration activity created by deliver on 14/06/2005"
    1. in their comments
    my $index =1;
    while ( $index <= $activities->Count) {
    if (($activities->Item($index)->Comment) =~ /Integration activity created by deliver on 14\/06\/2005/) {
    #this is an activity delivered to this stream on 14/06/05, do something with it
    ;
    }
    $index++;
    }
    The CAL.chm is woefully lacking when it comes to Perl examples, but you can usually get an idea of how to get stuff from the VB examples. I also found that the Object Browser in the VB IDE is an invaluable source of properties, methods, what they return etc.

    Hope that helps; if you want to do more fancy processing with the dates from the creation record, yell coz you will need to do some fancy footwork with Win32::OLE::Variant ...

    Of course, you could always avoid all the above and just use the cleartool object to run a "lsact -fmt <fmt>" to get what you need:-)

    As for ActivePerl the above works with:
    ccperl -V
    revision 5 version 6 subversion 1
    ...
    Locally applied patches:
    ActivePerl Build 629
    Cheers
    Hi chonk,
    Thanks for the script. I tried it but it was giving errors.

    Will it be possible to for you to send me a simple perl script.
    Input I will pass will be name of the stream (not user)and it should just show me the activities. Which will help me understand better.

    sorry for If i hav troubled you.

    Thanks,

    Unni
  • Meridian_
    Meridian_
    1 Post

    Ответ: Re: Perl with CAL

    ‏2013-10-24T10:33:56Z  
    Hi chonk,
    Thanks for the script. I tried it but it was giving errors.

    Will it be possible to for you to send me a simple perl script.
    Input I will pass will be name of the stream (not user)and it should just show me the activities. Which will help me understand better.

    sorry for If i hav troubled you.

    Thanks,

    Unni

    Hi!

    how can i get the property Kind (file or directory) element ?

      my $kind = $ver->Kind;  this is not return value