| author | Vincent Tondellier <tonton+hg@team1664.org> |
| Wed, 02 May 2012 21:46:30 +0200 | |
| changeset 3 | 2ff78fe4abda |
| parent 1 | c3726f733704 |
| child 6 | 8dfc7e5dbdc7 |
| 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; |
|
58 |
opendir my ($dh), $data_path; |
|
59 |
while(readdir $dh) {
|
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
60 |
if($_ =~ /(.*)\.json$/) {
|
| 0 | 61 |
my $filename = File::Spec->catfile($data_path, $_); |
62 |
push @files, {
|
|
63 |
file => $filename, |
|
64 |
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
|
65 |
signature => $1, |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
66 |
product => "", |
| 0 | 67 |
date => (stat $filename)[9], |
68 |
}; |
|
69 |
} |
|
70 |
} |
|
71 |
closedir $dh; |
|
72 |
||
73 |
my @sorted_files = ( sort { $b->{date} <=> $a->{date} } @files );
|
|
74 |
@sorted_files = @sorted_files[0..19] if scalar(@sorted_files) > 20; |
|
75 |
||
76 |
$self->stash(files => \@sorted_files); |
|
77 |
||
78 |
$self->render('index');
|
|
79 |
} => 'index'; |
|
80 |
||
81 |
get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
|
|
82 |
my $self = shift; |
|
83 |
||
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
84 |
open JSON, '<', File::Spec->catfile($data_path, $self->param('uuid') . '.json') or die $!;
|
| 0 | 85 |
my @json_content_lines = <JSON>; |
86 |
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
|
87 |
close JSON; |
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
88 |
|
| 0 | 89 |
my $json = Mojo::JSON->new; |
90 |
my $processed_data = $json->decode($json_content); |
|
91 |
||
92 |
$self->stash(processed_data => $processed_data); |
|
93 |
||
94 |
$self->render('report/crash');
|
|
95 |
} => 'report'; |
|
96 |
||
97 |
post '/submit' => sub {
|
|
98 |
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
|
99 |
|
| 0 | 100 |
# save the dump in a file |
101 |
my $file = $self->req->upload('upload_file_minidump');
|
|
102 |
my ($uuid, $uuidstr); |
|
103 |
UUID::generate($uuid); |
|
104 |
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
|
105 |
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
|
106 |
$file->move_to($dmp_file); |
| 0 | 107 |
|
108 |
# Create json for the params |
|
|
1
c3726f733704
Use minimal bootstrap css and js
Vincent Tondellier <tonton+hg@team1664.org>
parents:
0
diff
changeset
|
109 |
my %paramshash = map { $_ => $self->req->param($_) } $self->req->param;
|
| 0 | 110 |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
111 |
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
|
112 |
|
| 0 | 113 |
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
|
114 |
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
|
115 |
$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
|
116 |
|
|
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
117 |
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
|
118 |
open JSON, '>', File::Spec->catfile($data_path, "$uuidstr.json") or die $!; |
| 0 | 119 |
print JSON $j; |
120 |
close JSON; |
|
121 |
||
122 |
# reply |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
123 |
$self->render_text($pjson->{status});
|
| 0 | 124 |
}; |
125 |
||
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
126 |
app->secret('My secret passphrase here');
|
| 0 | 127 |
app->start; |