A customer is reorganizing their project hierarchy and wanted a way to measure progress of child projects that existed under two different project hierarchies.
The following python script was written to provide this data
Usage:
Update credentials array to include username and password
Update workspace_oid to include the object ID for the workspace being reported on
Change source_project_name and dest_project_name to include the names of the top level projects involved in the project migration.
from datetime import datetime, timedelta
import requests
def count_key_occurrences(obj, key_to_count):
"""
Recursively count the number of times a specific key appears in a JSON-like structure.
:param obj: The JSON object (dict or list).
:param key_to_count: The key to search for and count.
:return: The total count of the key.
"""
count = 0
# If the object is a dictionary, check if the key is present, then recurse into its values
if isinstance(obj, dict):
for key, value in obj.items():
if key == key_to_count:
count += 1 # Count if the key matches
count += count_key_occurrences(value, key_to_count) # Recurse into the value
# If the object is a list, recurse into each element
elif isinstance(obj, list):
for item in obj:
count += count_key_occurrences(item, key_to_count)
# Return the total count
return count
def main():
# Credentials
credentials = ['https://rally1.rallydev.com/', '[email protected]','enter_password_here']
workspace_oid = ########
source_project_name = 'Project Node 1'
dest_project_name = 'Project Node 2'
#
#
#
print("[{timestamp}] main()".format(timestamp=datetime.now()))
credentials[0] = '{server}slm/webservice/v2.0/'.format(server = credentials[0])
session = requests.session()
projects = session.get('https://rally1.rallydev.com/slm/pjt/tree.sp?withUUIDs=true&workspaceOid={workspace_oid}'.format(server = credentials[0], workspace_oid=workspace_oid), auth=(credentials[1], credentials[2])).json()
x = 0
for project in projects:
if project['name'] == source_project_name:
source_project_pos = x
if project['name'] == dest_project_name:
dest_project_pos = x
x = x + 1
source_projects = projects[source_project_pos]
dest_projects = projects[dest_project_pos]
source_project_len = count_key_occurrences(source_projects, 'name')
dest_project_len = count_key_occurrences(dest_projects, 'name')
print('{source_project_name}: {source_project_len}'.format(source_project_name=source_project_name,source_project_len=source_project_len))
print('{dest_project_name}: {dest_project_len}'.format(dest_project_name=dest_project_name,dest_project_len=dest_project_len))
print("[{timestamp}] Starting run".format(timestamp=datetime.now()))
main()
Disclaimer:
The script provided is offered "as is," without any guarantees or warranties of any kind. No support, maintenance, or updates will be provided. Use of the script is at your own risk, and the provider assumes no responsibility for any issues or damages that may arise from its use.