bin/fs_to_db.pl
author Vincent Tondellier <tonton+hg@team1664.org>
Sun, 08 Feb 2015 14:14:15 +0100
changeset 58 a3e856c4d161
parent 55 8d9daa16ccad
child 60 7ad91b3d5562
permissions -rwxr-xr-x
Fix frame trust warnings with the latest Mojolicious

#!/usr/bin/env perl

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use Mojo::Base -strict;
use lib 'lib';

use Mojo::JSON qw/decode_json/;
use Mojo::Util qw/decode slurp/;
use Mojo::Loader;
use File::Basename;
use Mojolicious;
use Mojo::Home;

if(scalar @ARGV == 0) {
    say "Usage: $0 <processed json files>";
    exit 1;
}

sub load_config {
    my $app = Mojolicious->new;
    $app->home(Mojo::Home->new("$FindBin::Bin/../"));
    $app->moniker("CrashTest");
    return $app->plugin('Config');
}

my $config = load_config();

my $loader = Mojo::Loader->new;

my $storage_class = $config->{Storage}->{Type};
if (my $e = $loader->load($storage_class)) {
    die ref $e ? "Exception: $e" : 'Not found!';
}

my $storage = $storage_class->new(config => $config->{Storage});

foreach my $arg (@ARGV) {
    my $pjson = decode_json(slurp $arg);

    my($filename, $dirs, $suffix) = fileparse($arg, qr/\.[^.]*/);

    my $uuid = $filename;
    $storage->_db_insert_processed_data($uuid, $pjson);
}