forked from hamilton2br/rally-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitertasks
executable file
·181 lines (146 loc) · 4.4 KB
/
itertasks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env ruby
require 'csv'
require 'rally_rest_api'
require 'ostruct'
require 'optparse'
require 'yaml'
#maybe I should make a gem out of this class...
require 'prawn'
require 'prawn/measurement_extensions'
require 'prawn/qrcode'
class TaskBook
def initialize
@card_index = 0
@pdf = Prawn::Document.new(:page_size => "A4",:margin => [5,5])
end
def add_card(story_id,task_id,task_desc)
if @card_index > 0 and @card_index % 10 == 0 then @pdf.start_new_page end
#origin
x = 12.mm + (@card_index % 2) * 94.mm
y = 290.mm - (@card_index / 2 % 5) * 58.mm
#draw the card
@pdf.stroke do
#card border
@pdf.rectangle [x,y],89.mm,55.mm
# horizontal line
@pdf.line [x,y - 21.mm],[x + 89.mm, y - 21.mm]
# vertical line
@pdf.line [x + 34.mm ,y - 21.mm],[x + 34.mm, y ]
end
#put text into the bounding boxes
@pdf.bounding_box([x ,y - 5.mm ], :width=> 34.mm, :height=>21.mm ) do
@pdf.text task_id, :style => :bold, :size => 20 , :align => :center
@pdf.text story_id, :size => 12 , :align => :center
end
@pdf.bounding_box([x + 5.mm, y - 26.mm] ,
#change 89 to 60 when printing QRCODE
:width => 60.mm, :height => 34.mm ) do
@pdf.text task_desc, :size => 16 , :style => :bold
end
@pdf.bounding_box([x + 65.mm, y - 31.mm] ,
:width => 34.mm, :height => 34.mm ) do
@pdf.print_qr_code(task_id, :extent => 25.mm, :stroke => false )
end
@card_index = @card_index + 1
end
def render_file(filename)
@pdf.render_file filename
end
end
options = OpenStruct.new
options.pdffile = "output.pdf"
options.csvfile = "output.csv"
options.csvoutput = false
options.csvoutputpairs = false
options.pdfouput = false
options.iteration = ""
options.story = ""
options.user = nil
options.password = nil
opts = OptionParser.new
opts.banner = "Usage: itertasks <-i Iteration ID| -s StoryID> [options]"
opts.on('-iITERATION','--iteration=ITERATION','Iteration ID') do |iter|
options.iteration << iter
end
opts.on('-sSTORY','--story=STORY','STORY ID (mandatory)') do |story|
options.story << story
end
opts.on('-c[file]','--csv[=file]','Creates a CSV file') do |file|
options.csvfile = file || 'output.csv'
options.csvoutput = true
end
opts.on('-p[=file]','--pdf[=file]','Creates a printable PDF TaskBook') do |file|
options.pdffile = file || 'output.pdf'
options.pdfoutput = true
end
opts.on('-d','--devs','adds the content of the "pairs" custom field to the csv file') do |file|
options.csvoutputpairs = true
end
opts.on('-U username','--user=username','Provides a Rally User') do |user|
options.user = user
end
opts.on('-P password','--password=password','Provides a Rally Password') do |pass|
options.password = pass
end
opts.on_tail( '-h', '--help', 'Displays this screen' ) do
puts opts
exit
end
opts.parse!(ARGV)
begin
config = YAML.load_file("#{Dir.home}/.rallyutils")
rescue
if !options.user and !options.password then
puts opts
puts "\nERROR: #{Dir.home}/.rallyutils not found and no user/password provided"
exit
end
end
rally_user=options.user || config["user"]
rally_pass=options.password || config["password"]
if options.iteration.empty? and options.story.empty? then
puts opts
exit
end
if not options.iteration.empty? then
itername = options.iteration
end
#Queries iteration
rally = RallyRestAPI.new(:username => rally_user, :password => rally_pass)
if itername then
res = rally.find( :iteration ) { equal :object_i_d , itername }
iter = res.first
end
if options.pdfoutput then
tb = TaskBook.new
end
if options.csvoutput then
csv = CSV.open(options.csvfile,"wb", :force_quotes => true )
end
if not options.iteration.empty? then
stories = rally.find( :hierarchical_requirement ) { equal :iteration, iter }
elsif not options.story.empty? then
stories = rally.find( :hierarchical_requirement ) { equal :formatted_i_d, options.story }
end
stories.each do |story|
if !story.tasks.nil? then
story.tasks.each do |task|
if options.pdfoutput then
tb.add_card(story.formatted_i_d,task.formatted_i_d,task.name)
end
if options.csvoutput then
if not options.csvoutputpairs
csv << [story.formatted_i_d,task.formatted_i_d,task.name]
else
csv << [story.formatted_i_d,task.formatted_i_d,task.name,task.pair]
end
end
if !(options.csvoutput or options.pdfoutput) then
puts "#{story.formatted_i_d}, #{task.formatted_i_d}: #{task.name}"
end
end
end
end
if options.pdfoutput then
tb.render_file(options.pdffile)
end