
List All The Depot Objects
Posted by Bill Robinson
Now listallthethings turns to DepotObjects. If I want to list all the Depot Objects in a group, there's an existing command for that:
blcli_execute DepotObject listAllByGroup "/Workspace/MyDepotObjects"
And that lists all the Depot Objects in the (static) group. Similar to the List All The Jobs post, we have the same issue with Depot Objects - we need to know the type in order to determine the DBKey, DepotObjectId, etc.
So again we go look at the DepotObject.listAllByGroup in the Unreleased blcli commands and documentation and find:
Command Input Return value stored name DepotGroup.groupNameToId $qualifiedGroupName$ groupId DepotObject.findAllHeadersByGroup NAMED_OBJECT=groupId - SDepotObjectHeader.getName no input - Utility.setTargetObject no input - Utility.listPrint no input -
And we look in the SDepotObjectHeader namespace to see what's there. And we have the same set of examples from our other post:
blcli_execute SmartDepotGroup groupNameToId "/Workspace/All Depot Objects" # or DepotGroup.groupNameToId with a Static Depot Group blcli_storelocal depotGroupId blcli_execute DepotObject findAllHeadersByGroup ${jobGroupId} blcli_execute SDepotObjectHeader getDBKey blcli_execute Utility setTargetObject blcli_execute Utility listPrint blcli_storelocal depotObjectKeys
And as in the Server post we can use SDepotObjectHeader.getDepotObjectId to get the Job Id instead of the DBKey. and then as before we could iterate through the list of Depot Object Keys and do something like update a property value:
while read depotObjectKey do blcli_execute DepotObject setPropertyValue ${jobKey} APPLICATION_NAME Payroll done <<< "$(awk 'NF' <<< "${depotObjectKeys}")"
Or maybe I want to update the description on the object. Since I can't find a blcli command to do that directly, it looks like I need to use one of the primitives - DepotOjbect.setDescription to do it. That will involve loading the DepotObject object and then acting on it, and we can still use same list of Depot Object keys we get above:
while read depotObjectKey do blcli_execute DepotObject findByDBKey ${depotObjectKey} blcli_execute Utility storeTargetObject obj blcli_execute DepotObject setDescription "Payroll Application" blcli_execute DepotObject update NAMED_OBJECT=obj done <<< "$(awk 'NF' <<< "${depotObjectKeys}")"
Sometimes though I might just want to list out the DepotObject, the group path where it exists, the DepotObject type, etc. All of that information seems to be available in commands in SDepotObjectHeader. In that case I want to load the SDepotObjectHeader object and run some commands against it.
blcli_execute SmartDepotGroup groupNameToId "/Workspace/All Depot Objects" # or DepotGroup.groupNameToId with a Static Depot Group blcli_storelocal objGroupId blcli_execute DepotObject findAllHeadersByGroup ${objGroupId} blcli_execute Utility storeTargetObject objHeaders blcli_execute Utility listLength blcli_storelocal listLength for i in {0..$((${listLength}-1))} do blcli_execute Utility setTargetObject objHeaders blcli_execute Utility listItemSelect ${i} blcli_execute Utility setTargetObject blcli_execute SDepotObjectHeader getName blcli_storelocal objName blcli_execute SDepotObjectHeader getObjectTypeId blcli_storelocal objTypeId blcli_execute SDepotObjectHeader getDescription blcli_storelocal objDesc blcli_execute SDepotObjectHeader getGroupId blcli_storelocal objGrpId blcli_execute Group getQualifiedGroupName 5001 ${objGrpId} blcli_storelocal groupPath echo "${groupPath}/${objName},${objDesc},${objTypeId}" done
This will echo out the Depot Folder and Name, the description and the object type id for the Depot Object.
This one was not much different than Jobs; a similar set of commands but from a different namespace. Generally that's the case: the commands are the same across namespaces for the same actions. Not always as you'll find out but most of the time. That can make it easy to parameterize your commands to build out script functions like:
getName() { local ns="${1}" local dbKey="${2}" blcli_execute ${ns} findByDBKey ${dbKey} blcli_execute ${ns} getName blcli_storeenv objName blcli_execute ${ns} getType blcli_storeenv objTypeId }
This is nice because it's a single function instead of maintaining separate functions for each object type. Even if the command name varies you can always do some conditionals and parameterize the command name based on the namespace.
Comments