latency: Dot not override already stored events
[platform/upstream/gstreamer.git] / scripts / five-bugs-a-day.pl
1 #!/usr/bin/env perl
2 #
3 # ----------------------------------------------------------------------------
4 #
5 # five-bugs-a-day.pl
6 #
7 # Little script that outputs a list of N random open bugs from bugzilla
8 # for a certain bugzilla product
9 #
10 # ----------------------------------------------------------------------------
11 #
12 # Copyright (C) 2011-2012 Tim-Philipp Muller <tim centricular net>
13 #
14 # This script is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU Library General Public
16 # License as published by the Free Software Foundation; either
17 # version 2 of the License, or (at your option) any later version.
18 #
19 # This library is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 # Library General Public License for more details.
23 #
24 # You should have received a copy of the GNU Library General Public
25 # License along with this library; if not, write to the
26 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
27 # Boston, MA 02110-1301, USA.
28 #
29 # ----------------------------------------------------------------------------
30 #
31 # You can use it to send yourself an e-mail with a few bugs to check up on
32 # every day, just put it into your crontab on a computer of your choice
33 # (with proper e-mail forwarding configured in some way):
34 #
35 # $ crontab -e
36 #
37 # add:
38 #
39 #   MAILTO=you@nowhere.org
40 #   # send ten random buglinks every day at 16.30
41 #   30 16 * * *  /usr/bin/perl  /path/to/five-bugs-a-day.pl
42 #
43 #
44 # Yes, it's PERL, sorry.
45 #
46 # Yes, I know the default is 10 bugs.
47 #
48 # ----------------------------------------------------------------------------
49
50 # ----------------------------------------------------------------------------
51 #    subroutines
52 # ----------------------------------------------------------------------------
53
54 sub shuffle
55 {
56     my $array = shift;
57     my $i = @$array;
58     while ( --$i )
59     {
60         my $j = int rand( $i+1 );
61         @$array[$i,$j] = @$array[$j,$i];
62     }
63
64     return @$array;
65 }
66
67 # ----------------------------------------------------------------------------
68 #    main
69 # ----------------------------------------------------------------------------
70
71 my $NUM_BUGS = 10;
72
73 my $PRODUCT = "GStreamer";
74
75 # ----- command line options -----
76
77 if (@ARGV) {
78   $NUM_BUGS = shift @ARGV;
79 }
80
81 if (@ARGV) {
82   $PRODUCT = shift @ARGV;
83 }
84
85
86 my $QUERY_URL = "https://bugzilla.gnome.org/buglist.cgi?product=$PRODUCT&" .
87                 'bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&' .
88                 'bug_status=REOPENED&' .
89                 'query_format=advanced&ctype=csv';
90
91 my $COL_ID;
92 my $COL_DESC;
93
94 my %BUGS;
95
96 # for testing/debugging:
97 # unless (@lines = `cat bugs.csv`) {
98 unless (@lines = `wget --no-check-certificate --quiet -O - '$QUERY_URL'`) {
99   die 'Could not download bug list';
100 }
101
102 # ----- parse column headers -----
103
104 my $headers;
105
106 # get first line which contains the field names
107 $headers = shift @lines;
108
109 # get rid of newline at end
110 chop $headers;
111
112 my @fields = split (/,/, $headers);
113 my $num_fields = scalar(@fields);
114
115 for (my $c = 0; $c < $num_fields; $c++) {
116   #print "$c $fields[$c] \n";
117   if ($fields[$c] =~ m/bug_id/) {
118     $COL_ID = $c;
119   } elsif ($fields[$c] =~ m/short_desc/) {
120     $COL_DESC = $c;
121   }
122 }
123
124 die "Could not find bug_id column in CVS file" if not defined ($COL_ID);
125 die "Could not find short_desc column in CVS file" if not defined ($COL_DESC);
126
127 #print "bugid is column $COL_ID\n";
128 #print "desc  is column $COL_DESC\n";
129
130 foreach (@lines) {
131   if (m/,/) {
132     chop;
133
134     # We specify num_fields as limit here, because the short_desc field
135     # might contain commas as well, and we don't want it to get cut off.
136     # This is a hack for the fact that we don't handle quoted fields
137     # (12345,"UNCONFIRMED","foo, bar: errors out") properly. As long as the
138     # short_desc field is the last one, that should be ok. (FIXME)
139     my @vals = split (/,/, $_, $num_fields);
140     my $id = $vals[$COL_ID];
141     my $desc = $vals[$COL_DESC];
142
143     $desc =~ s/^"(.*)"$/$1/;
144     $BUGS{$id} = $desc;
145   }
146 }
147
148 my @all_bugs = keys %BUGS;
149 my @bugs = shuffle (\@all_bugs);
150
151 # only want first NUM_BUGS bugs
152 @bugs = splice (@bugs, 0, $NUM_BUGS);
153
154 print "\n";
155 print "$NUM_BUGS random bugs:\n";
156 print "\n";
157
158 for my $bug_id ( @bugs ) {
159   print "$BUGS{$bug_id}\n";
160   print "https://bugzilla.gnome.org/show_bug.cgi?id=$bug_id\n";
161   print "\n";
162 }
163
164 print "\n";
165 print "More bugs at:\n";
166 print "  - http://gstreamer.freedesktop.org/bugs/\n";
167 print "  - https://bugzilla.gnome.org/browse.cgi?product=GStreamer\n";
168 print "\n";