| author | Vincent Tondellier <tonton+hg@team1664.org> |
| Wed, 25 Jun 2014 00:16:09 +0200 | |
| changeset 21 | fab315d8c7a8 |
| parent 19 | 300b902b5461 |
| child 23 | e621317229f7 |
| permissions | -rwxr-xr-x |
| 0 | 1 |
#!/usr/bin/env perl |
2 |
||
| 12 | 3 |
# This program is free software: you can redistribute it and/or modify |
4 |
# it under the terms of the GNU General Public License as published by |
|
5 |
# the Free Software Foundation, either version 3 of the License, or |
|
6 |
# (at your option) any later version. |
|
7 |
# |
|
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU General Public License for more details. |
|
12 |
# |
|
13 |
# You should have received a copy of the GNU General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 |
||
| 0 | 16 |
use Mojolicious::Lite; |
17 |
use UUID; |
|
18 |
use Mojo::JSON; |
|
|
16
76a5a48538e4
Use helper instead of using the full class name
Vincent Tondellier <tonton+hg@team1664.org>
parents:
12
diff
changeset
|
19 |
use Mojo::ByteStream 'b'; |
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
20 |
use Mojo::UserAgent; |
|
11
0bef3b8087c1
Move filesystem access to lib/
Vincent Tondellier <tonton+hg@team1664.org>
parents:
6
diff
changeset
|
21 |
use lib 'lib'; |
| 0 | 22 |
|
23 |
my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/; |
|
24 |
my $config = plugin 'Config'; |
|
25 |
||
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
26 |
app->attr(storage => sub {
|
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
27 |
my $self = shift; |
|
19
300b902b5461
Reorganize config
Vincent Tondellier <tonton+hg@team1664.org>
parents:
17
diff
changeset
|
28 |
eval "require $config->{Storage}->{Type}";
|
|
300b902b5461
Reorganize config
Vincent Tondellier <tonton+hg@team1664.org>
parents:
17
diff
changeset
|
29 |
return $config->{Storage}->{Type}->new($config->{Storage});
|
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
30 |
}); |
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
31 |
|
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
32 |
app->attr(decode_queue => sub {
|
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
33 |
my $self = shift; |
|
19
300b902b5461
Reorganize config
Vincent Tondellier <tonton+hg@team1664.org>
parents:
17
diff
changeset
|
34 |
eval "require $config->{DecodeQueue}->{Type}";
|
|
300b902b5461
Reorganize config
Vincent Tondellier <tonton+hg@team1664.org>
parents:
17
diff
changeset
|
35 |
return $config->{DecodeQueue}->{Type}->new($config->{DecodeQueue}, $config->{Dumper}, app->storage);
|
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
36 |
}); |
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
37 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
38 |
helper scm_file_link => sub {
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
39 |
my ($self, $file, $line) = @_; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
40 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
41 |
return "" unless(defined($file)); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
42 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
43 |
if($file =~ qr{([a-z]+):([a-z/.]+):(.+):(\d+)})
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
44 |
{
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
45 |
my ($scm, $repo, $scmpath, $rev) = ($1, $2, $3, $4); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
46 |
my $filename = File::Spec->splitpath($scmpath); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
47 |
my $scmrepo = "$scm:$repo"; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
48 |
if(exists($config->{ScmLinks}->{$scmrepo})) {
|
|
16
76a5a48538e4
Use helper instead of using the full class name
Vincent Tondellier <tonton+hg@team1664.org>
parents:
12
diff
changeset
|
49 |
return b($self->link_to("$filename:$line" =>
|
|
11
0bef3b8087c1
Move filesystem access to lib/
Vincent Tondellier <tonton+hg@team1664.org>
parents:
6
diff
changeset
|
50 |
$self->render(inline => $config->{ScmLinks}->{$scmrepo},
|
|
0bef3b8087c1
Move filesystem access to lib/
Vincent Tondellier <tonton+hg@team1664.org>
parents:
6
diff
changeset
|
51 |
repo => $repo, scmpath => $scmpath, rev => $rev, line => $line, partial => 1) |
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
52 |
)); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
53 |
} |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
54 |
#return $file; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
55 |
} |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
56 |
my $filebase = (File::Spec->splitpath($file))[-1]; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
57 |
if(defined($line) && $line ne "") {
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
58 |
return "$filebase:$line"; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
59 |
} |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
60 |
return $filebase; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
61 |
}; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
62 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
63 |
helper shorten_signature => sub {
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
64 |
my ($self, $signature) = @_; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
65 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
66 |
return "" if(!defined($signature) || $signature eq ""); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
67 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
68 |
my $short_signature = $signature; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
69 |
if($signature =~ qr{([^<]+)<.+>::([^()]+)\(.*\)(.*)}) {
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
70 |
# c++ with template |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
71 |
$short_signature = "$1<>::$2()$3"; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
72 |
} elsif($signature =~ qr{([^()]+)\(.*\)(.*)}) {
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
73 |
# c/c++ |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
74 |
$short_signature = "$1()$2"; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
75 |
} |
|
16
76a5a48538e4
Use helper instead of using the full class name
Vincent Tondellier <tonton+hg@team1664.org>
parents:
12
diff
changeset
|
76 |
return b($self->t(span => (title => $signature, class => "shortened-signature") => $short_signature)); |
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
77 |
}; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
78 |
|
| 0 | 79 |
get '/' => sub {
|
80 |
my $self = shift; |
|
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
81 |
$self->stash(files => $self->app->storage->index()); |
| 0 | 82 |
$self->render('index');
|
83 |
} => 'index'; |
|
84 |
||
85 |
get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
|
|
86 |
my $self = shift; |
|
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
87 |
$self->stash(processed_data => $self->app->storage->get_processed_data($self->param('uuid')));
|
| 0 | 88 |
$self->render('report/crash');
|
89 |
} => 'report'; |
|
90 |
||
91 |
post '/submit' => sub {
|
|
92 |
my $self = shift; |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
93 |
|
| 0 | 94 |
# save the dump in a file |
95 |
my $file = $self->req->upload('upload_file_minidump');
|
|
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
96 |
my %paramshash = map { $_ => $self->req->param($_) } $self->req->param;
|
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
97 |
|
| 0 | 98 |
my ($uuid, $uuidstr); |
99 |
UUID::generate($uuid); |
|
100 |
UUID::unparse($uuid, $uuidstr); |
|
|
19
300b902b5461
Reorganize config
Vincent Tondellier <tonton+hg@team1664.org>
parents:
17
diff
changeset
|
101 |
my $pjson = $self->app->decode_queue->decode($file, \%paramshash, $uuidstr); |
| 0 | 102 |
|
103 |
# reply |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
104 |
$self->render_text($pjson->{status});
|
| 0 | 105 |
}; |
106 |
||
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
107 |
app->secret('My secret passphrase here');
|
| 0 | 108 |
app->start; |