|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +################################################################################################### |
| 4 | +# |
| 5 | +# statecounts - for a given artifact_type within a workspace/project environment, |
| 6 | +# return the count of said artifact_type for each State/ScheduleState value. |
| 7 | +# |
| 8 | +USAGE = """ |
| 9 | +Usage: python statecounts.py <artifact_type> |
| 10 | +""" |
| 11 | +################################################################################################### |
| 12 | + |
| 13 | +import sys |
| 14 | +import time |
| 15 | + |
| 16 | +from pyral import rallySettings, Rally |
| 17 | + |
| 18 | +################################################################################################### |
| 19 | + |
| 20 | +errout = sys.stderr.write |
| 21 | + |
| 22 | +VALID_ARTIFACT_TYPES = ['Story', 'UserStory', 'HierarchicalRequirement', 'Defect', 'Task', 'TestCase'] |
| 23 | + |
| 24 | +################################################################################################### |
| 25 | + |
| 26 | +def main(args): |
| 27 | + options = [opt for opt in args if opt.startswith('--')] |
| 28 | + args = [arg for arg in args if arg not in options] |
| 29 | + server, user, password, workspace, project = rallySettings(options) |
| 30 | + print " ".join(["|%s|" % item for item in [server, user, '********', workspace, project]]) |
| 31 | + rally = Rally(server, user, password, workspace=workspace, project=project) |
| 32 | + rally.enableLogging('rally.hist.statecount') # name of file you want logging to go to |
| 33 | + |
| 34 | + if not args: |
| 35 | + errout(USAGE) |
| 36 | + sys.exit(1) |
| 37 | + |
| 38 | + rally.setWorkspace(workspace) |
| 39 | + rally.setProject(project) |
| 40 | + |
| 41 | + artifact_type = args[0] |
| 42 | + if artifact_type not in VALID_ARTIFACT_TYPES: |
| 43 | + errout(USAGE) |
| 44 | + errout('The artifact_type argument must be one of: %s' % ", ".join(VALID_ARTIFACT_TYPES)) |
| 45 | + sys.exit(1) |
| 46 | + |
| 47 | + art_type = artifact_type[:] |
| 48 | + state = 'State' # default to this and change below if necessary |
| 49 | + if artifact_type in ['Story', 'UserStory', 'HierarchicalRequirement']: |
| 50 | + artifact_type = 'HierarchicalRequirement' |
| 51 | + state = 'ScheduleState' |
| 52 | + |
| 53 | + t_zero = time.time() |
| 54 | + state_values = rally.getAllowedValues(artifact_type, state).keys() |
| 55 | + t_one = time.time() |
| 56 | + av_time = t_one - t_zero |
| 57 | + |
| 58 | + show_counts(rally, artifact_type, state, state_values, av_time) |
| 59 | + |
| 60 | +################################################################################################### |
| 61 | + |
| 62 | +def show_counts(rally, artifact_type, state, state_values, av_time): |
| 63 | + """ |
| 64 | + Given a Rally connection instance, the name of the artifact type you want |
| 65 | + counts for, the name of the relevant state field (State or ScheduleState), |
| 66 | + the valid state values for which counts will be obtained and an elapsed time |
| 67 | + value representing the time taken to retrieve the allowed values prior to this |
| 68 | + call, query for the counts for each state value and show the results. |
| 69 | + """ |
| 70 | + output = [] |
| 71 | + |
| 72 | + proc_time_start = time.time() |
| 73 | + for state_value in sorted(state_values): |
| 74 | + response = rally.get(artifact_type, fetch="FormattedID", query='%s = %s' % (state, state_value), |
| 75 | + projectScopeUp=False, projectScopeDown=False) |
| 76 | + if response.errors: |
| 77 | + print "Blaarrrgggghhhhh! %s" % response.errors[0] |
| 78 | + continue |
| 79 | + output.append("%16s : %5d" % (state_value, response.resultCount)) |
| 80 | + proc_time_finish = time.time() |
| 81 | + elapsed = (proc_time_finish - proc_time_start) + av_time |
| 82 | + for line in output: |
| 83 | + print line |
| 84 | + |
| 85 | + print "" |
| 86 | + print "querying for all the %s %s item counts took %5.2f secs" % (artifact_type, state, elapsed) |
| 87 | + print "" |
| 88 | + |
| 89 | +################################################################################################### |
| 90 | +################################################################################################### |
| 91 | + |
| 92 | +if __name__ == '__main__': |
| 93 | + main(sys.argv[1:]) |
0 commit comments