1

In order to clean up Rally I want to change the parent for projects which are marked as "Closed"

--MyWorkspace
  - Project 1
  - Project 2
    - Child 1 (Status = Closed)
    - Child 2 (Status = Closed)
    - Child 3 (Status = Open)
  - Project 3

I want to update the parent of "Child 1" and "Child 2" to "Project 1" (Want to move those child projects under different parent.

import sys
from pyral import Rally, rallyWorkset
options = [arg for arg in sys.argv[1:] if arg.startswith('--')]
args    = [arg for arg in sys.argv[1:] if arg not in options]
server = <server>
apikey = <api_key>
workspace = <workspace>
project = <project_name>
rally = Rally(server,apikey=apikey, workspace=workspace, project=project)
rally.enableLogging('mypyral.log')

I am using below method to check all the projects under the required workspace

projects = rally.getProjects(workspace=workspace)
for proj in projects:
    print ("    %12.12s  %s  %s" % (proj.oid, proj.Name, proj.State))

This gives me parent level projects only

<id> <Name>  <status>

This logic doesn't return all the child projects though.

Also I am looking for post method to update the parents once I get the list of projects I want to close.

vpd
  • 234
  • 2
  • 10

1 Answers1

2

That's correct - projects = rally.getProjects(workspace=workspace) returns all Parents projects.

In order to get all children Projects you need to ask about it parent:

for proj in projects:
children = proj.Children
for child in children:
    print ("    %12.12s  %s  %s" % (child.oid, child.Name, child.State))

The entire task i would solve in the following way:

#get object for 'New Parent':
target_project = rally.getProject('NewParentForClosedProjects')

projects = rally.getProjects(workspace=workspace)
for proj in projects:

    #get children of project
    children = proj.Children

    for child in children:

        #if project closed:
        if child.State == 'Closed':
            #Then update Parent to new one:
            project_fields = {
                "ObjectID": child.oid,
                "Parent": target_project.ref
            }
            try:
                result = rally.update('Project', project_fields)
                print "Project %s has been successfully updated with new %s parent" % (str(child.Name), str(child.Parent))
            except RallyRESTException, ex:
                print "Update failure for Project %s" % (str(child.Name))
                print ex
user2738882
  • 1,161
  • 1
  • 20
  • 38