bin/fs_to_db.pl
changeset 78 0ebef32c34af
parent 77 e408da1419cd
child 79 4ae8bb6f8a96
equal deleted inserted replaced
77:e408da1419cd 78:0ebef32c34af
     1 #!/usr/bin/env perl
       
     2 
       
     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 
       
    16 use Mojo::Base -strict;
       
    17 use lib 'lib';
       
    18 
       
    19 use Mojo::JSON qw/decode_json/;
       
    20 use Mojo::Util qw/decode slurp/;
       
    21 use Mojo::Loader qw/load_class/;
       
    22 use File::Basename;
       
    23 use Mojolicious;
       
    24 use Mojo::Home;
       
    25 
       
    26 if(scalar @ARGV == 0) {
       
    27     say "Usage: $0 <processed json files>";
       
    28     exit 1;
       
    29 }
       
    30 
       
    31 sub load_config {
       
    32     my $app = Mojolicious->new;
       
    33     $app->home(Mojo::Home->new("$FindBin::Bin/../"));
       
    34     $app->moniker("CrashTest");
       
    35     return $app->plugin('Config');
       
    36 }
       
    37 
       
    38 my $config = load_config();
       
    39 
       
    40 my $storage_class = $config->{Storage}->{Type};
       
    41 if (my $e = load_class($storage_class)) {
       
    42     die ref $e ? "Exception: $e" : 'Not found!';
       
    43 }
       
    44 
       
    45 my $storage = $storage_class->new(config => $config->{Storage});
       
    46 
       
    47 foreach my $arg (@ARGV) {
       
    48     eval {
       
    49         my $pjson = decode_json(slurp $arg);
       
    50 
       
    51         my($filename, $dirs, $suffix) = fileparse($arg, qr/\.[^.]*/);
       
    52 
       
    53         my $uuid = $filename;
       
    54         $storage->_db_insert_processed_data($uuid, $pjson);
       
    55     };
       
    56     warn $@ if $@;
       
    57 }