| author | Vincent Tondellier <tonton+hg@team1664.org> |
| Mon, 28 May 2012 00:23:21 +0200 | |
| changeset 10 | 4668386ec082 |
| parent 6 | 8dfc7e5dbdc7 |
| child 11 | 0bef3b8087c1 |
| permissions | -rwxr-xr-x |
| 0 | 1 |
#!/usr/bin/env perl |
2 |
||
3 |
use Mojolicious::Lite; |
|
4 |
use UUID; |
|
5 |
use Mojo::JSON; |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
6 |
use Mojo::UserAgent; |
| 0 | 7 |
|
8 |
my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/; |
|
9 |
my $config = plugin 'Config'; |
|
10 |
my $data_path = $config->{DataDir};
|
|
11 |
||
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
12 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
13 |
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
|
14 |
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
|
15 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
16 |
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
|
17 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
18 |
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
|
19 |
{
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
20 |
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
|
21 |
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
|
22 |
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
|
23 |
if(exists($config->{ScmLinks}->{$scmrepo})) {
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
24 |
return Mojo::ByteStream->new($self->link_to("$filename:$line" =>
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
25 |
$self->render(inline => $config->{ScmLinks}->{$scmrepo}, repo => $repo, scmpath => $scmpath, rev => $rev, line => $line, partial => 1)
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
26 |
)); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
27 |
} |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
28 |
#return $file; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
29 |
} |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
} |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
34 |
return $filebase; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
35 |
}; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
36 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
37 |
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
|
38 |
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
|
39 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
40 |
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
|
41 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
42 |
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
|
43 |
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
|
44 |
# 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
|
45 |
$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
|
46 |
} 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
|
47 |
# c/c++ |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
48 |
$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
|
49 |
} |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
50 |
return Mojo::ByteStream->new($self->t(span => (title => $signature, class => "shortened-signature") => $short_signature)); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
51 |
}; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
52 |
|
| 0 | 53 |
# Upload form in DATA section |
54 |
get '/' => sub {
|
|
55 |
my $self = shift; |
|
56 |
||
57 |
my @files; |
|
|
6
8dfc7e5dbdc7
Fix compatibility with perl < 5.11
Vincent Tondellier <tonton+hg@team1664.org>
parents:
3
diff
changeset
|
58 |
opendir my ($dh), $data_path or die $!; |
|
8dfc7e5dbdc7
Fix compatibility with perl < 5.11
Vincent Tondellier <tonton+hg@team1664.org>
parents:
3
diff
changeset
|
59 |
my @allfiles = readdir $dh; |
|
8dfc7e5dbdc7
Fix compatibility with perl < 5.11
Vincent Tondellier <tonton+hg@team1664.org>
parents:
3
diff
changeset
|
60 |
foreach(@allfiles) |
|
8dfc7e5dbdc7
Fix compatibility with perl < 5.11
Vincent Tondellier <tonton+hg@team1664.org>
parents:
3
diff
changeset
|
61 |
{
|
|
8dfc7e5dbdc7
Fix compatibility with perl < 5.11
Vincent Tondellier <tonton+hg@team1664.org>
parents:
3
diff
changeset
|
62 |
if($_ =~ /(.*)\.json$/) |
|
8dfc7e5dbdc7
Fix compatibility with perl < 5.11
Vincent Tondellier <tonton+hg@team1664.org>
parents:
3
diff
changeset
|
63 |
{
|
| 0 | 64 |
my $filename = File::Spec->catfile($data_path, $_); |
65 |
push @files, {
|
|
66 |
file => $filename, |
|
67 |
uuid => $1, |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
68 |
signature => $1, |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
69 |
product => "", |
| 0 | 70 |
date => (stat $filename)[9], |
71 |
}; |
|
72 |
} |
|
73 |
} |
|
74 |
closedir $dh; |
|
75 |
||
76 |
my @sorted_files = ( sort { $b->{date} <=> $a->{date} } @files );
|
|
77 |
@sorted_files = @sorted_files[0..19] if scalar(@sorted_files) > 20; |
|
78 |
||
79 |
$self->stash(files => \@sorted_files); |
|
80 |
||
81 |
$self->render('index');
|
|
82 |
} => 'index'; |
|
83 |
||
84 |
get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
|
|
85 |
my $self = shift; |
|
86 |
||
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
87 |
open JSON, '<', File::Spec->catfile($data_path, $self->param('uuid') . '.json') or die $!;
|
| 0 | 88 |
my @json_content_lines = <JSON>; |
89 |
my $json_content = join('', @json_content_lines);
|
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
90 |
close JSON; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
91 |
|
| 0 | 92 |
my $json = Mojo::JSON->new; |
93 |
my $processed_data = $json->decode($json_content); |
|
94 |
||
95 |
$self->stash(processed_data => $processed_data); |
|
96 |
||
97 |
$self->render('report/crash');
|
|
98 |
} => 'report'; |
|
99 |
||
100 |
post '/submit' => sub {
|
|
101 |
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
|
102 |
|
| 0 | 103 |
# save the dump in a file |
104 |
my $file = $self->req->upload('upload_file_minidump');
|
|
105 |
my ($uuid, $uuidstr); |
|
106 |
UUID::generate($uuid); |
|
107 |
UUID::unparse($uuid, $uuidstr); |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
108 |
my $dmp_file = File::Spec->catfile($data_path, "$uuidstr.dmp"); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
109 |
$file->move_to($dmp_file); |
| 0 | 110 |
|
111 |
# Create json for the params |
|
|
1
c3726f733704
Use minimal bootstrap css and js
Vincent Tondellier <tonton+hg@team1664.org>
parents:
0
diff
changeset
|
112 |
my %paramshash = map { $_ => $self->req->param($_) } $self->req->param;
|
| 0 | 113 |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
114 |
my $out = qx($config->{MinidumpStackwalkJSON} "$dmp_file" $config->{SymbolsPath} 2>/dev/null) or die $!;
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
115 |
|
| 0 | 116 |
my $json = Mojo::JSON->new; |
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
117 |
my $pjson = $json->decode($out); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
118 |
$pjson->{client_info} = \%paramshash;
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
119 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
120 |
my $j = $json->encode($pjson); |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
121 |
open JSON, '>', File::Spec->catfile($data_path, "$uuidstr.json") or die $!; |
| 0 | 122 |
print JSON $j; |
123 |
close JSON; |
|
124 |
||
125 |
# reply |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
126 |
$self->render_text($pjson->{status});
|
| 0 | 127 |
}; |
128 |
||
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
129 |
app->secret('My secret passphrase here');
|
| 0 | 130 |
app->start; |