Posted on 2009-01-07 13:30:57-08 by roberthc
Best way to get task info
Hi What's the best way to find out all the relevant info for a task? The equivalent to
ccm task -show information task#1234 I have tried: $ccm->ccm("task", qw(-show information task#1234));
but it doesn't give me anything sensible (compared with same results on command line). Regards Robert
Direct Responses: 9669 | Write a response
Posted on 2009-01-07 14:24:00-08 by synergyuser in response to 9668
Re: Best way to get task info
I use the following for the task properties

$ccm->ccm('task', qw(-show info), "$taskID", qw(-u -f), "%task_synopsis@@%release@@%resolver@@%stat +us@@%create_time@@%completion_date@@"); my ($task_synopsis, $release, $resolver, $status, $creation_date, $completion_date) = split(/@@/, $ +ccm->{out});


...and the following for any associated objects

$ccm->ccm('task', qw(-show objects), "$taskID", qw(-u -f), "%name@@%version@@%status@@%release@@%cv +type@@%owner@@%objectname@@"); my (@objects) = split /^/m, $ccm->{out}; foreach (@objects) { my ($name, $version, $status, $release, $cvtype, $owner, $objectname) = split(/@@/, + $_, 8); my (undef, undef, $instance) = split(/:/, $objectname, 3); push @{$objectList->{data}}, [$name, $version, $instance, $status, $release, $cvtyp +e, $owner];


Regards,

Michael
Direct Responses: 9676 | Write a response
Posted on 2009-01-07 22:35:31-08 by roderich in response to 9669
Re: Best way to get task info
$ccm->ccm('task', qw(-show info), "$taskID", qw(-u -f), "%task_synopsis@@%release@@%resolver@@%status@@%create_time@@%completion_date@@"); my ($task_synopsis, $release, $resolver, $status, $creation_date, $completion_date) = split(/@@/, $ccm->{out});

That's god-awful. With VCS::CMSynergy you should almost never have to parse the output of Synergy CLI command yourself.

The first thing is to stop using strings to denote the various Synergy entities, e.g. tasks. Instead wrap it in a VCS::CMSynerg::Object ("object" for short). An object stringifies to its Synergy four-part name whenever the context requires a string, so you can simply print it or use it as an argument of a CLI command. But you can also call methods on it, see below.

How do you get an object? There are lots of ways. If you happen to know its four part name, say "foo.c~42:csrc:1" you can use
$obj = $ccm->object("foo.c~42:csrc:1")
or with the four parts separated
$obj = $ccm->object("foo.c", "42", "csrc", "1")
For certain classes, e.g. tasks, that Synergy usually doesn't denote with their full four-part name, there are special object constructors, e.g.
$task_obj = $ccm->task_object("456#mydb")
creates an object for a task using its task id. There's also the query_object() method that returns the result set of a "ccm query" as a list of objects.

What can you do with an object? The simple stuff is to retrieve the parts of its four-part name

$obj->name, $obj->cvtype, ...
Or retrieve its attributes
$obj->get_attribute("owner")
(this is equivalent to doing "ccm attr -show ..."). Or use it to enumerate other objects, e.g. let $task_obj be a "task" object
$objs = $task_obj->is_associated_cv_of
Now $objs is a (reference to a) list of objects that represent the Synergy objects associated with the task. This is actually just a handy shortcut for
$objs = $ccm->query_object("is_associated_cv_of('$task_obj')")
Note that by using object methods you can forget about Synergy session ($ccm), because an object carries a reference to the session that it was created in.

If you want to enumerate objects by queries and then inspect their attributes, but don't want to pay the (runtime) price for a gazillion "ccm attr -show ..." calls, use

use VCS::CMSynergy qw(:cached_attributes);
instead of plain
use VCS::CMsynergy;
Then the result of $obj->get_attribute(...) will be cached in $obj, so that a second call of $obj->get_attribute(...) (for the same attribute) will simply answer from the cache and not execute "ccm attr -show ..." a second time. If you use
$ccm->query_object("some query", qw(foo bar quux))
then the returned list of objects will have their caches (for the attributes "foo", "bar" and "quux") filled by the query (by means of an implicit "-format '%foo|%bar|%quux'") so that a later $obj->get_attribute("foo") for an $obj in the result will not execuute any CLI command at all. (But if the attribute you asked for hasn't been cached already, it will transparently do "ccm attr -show ...").

If you're really into it, use

use VCS::CMSynergy qw(:cached_attributes :tied_objects);
This will make an object also in a tied hash, so that you can get (and set) its Synergy attributes using hash notation
$obj->{foo}
and the value is taken from the cache if mpresent or retrieved on the fly (using "ccm attr -show").

Putting all this together the above example should read:

use VCS::CMSynergy qw(:cached_attributes :tied_objects); ... my $task = $ccm->task_object($taskID); # now simply use $task->{task_synopsis}, $task->{release} etc # without further ado my $assoc_objs = $task->is_associated_cv_of(qw(status release owner)); foreach my $obj (@$assoc_objs) { print "$obj $obj->{status} $obj->{release} $obj->{owner}\n"; }

If you have further questions, feel free to ask.

Cheers, Roderich

Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.