bin/fs_to_db.pl
author Vincent Tondellier <tonton+hg@team1664.org>
Fri, 11 Sep 2015 23:52:21 +0200
changeset 70 dfc2f094a04f
parent 60 7ad91b3d5562
permissions -rwxr-xr-x
Fix compatibility with Mojolicious > 6 (Removed deprecated object-oriented Mojo::Loader API)

#!/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 qw/load_class/;
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 $storage_class = $config->{Storage}->{Type};
if (my $e = load_class($storage_class)) {
    die ref $e ? "Exception: $e" : 'Not found!';
}

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

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

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

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