bin/fs_to_db.pl
author Vincent Tondellier <tonton+hg@team1664.org>
Thu, 07 Aug 2014 23:50:08 +0200
changeset 34 e0d6597078a5
parent 31 f77c6719c05c
child 43 6070307efd38
permissions -rwxr-xr-x
Cleanup: Mojo-ize old code, simplifying perl OO code Make Sql Storage inherit Filesystem, since the DB is only used as an index and still stores on disk

#!/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 CrashTest::Storage::Sql;
use Mojo::JSON;
use Mojo::Util qw(decode slurp);
use File::Basename;

sub load_config {
    my ($file) = @_;
    my $code = decode('UTF-8', slurp $file);
    return eval($code);
}

my $config = load_config("CrashTest.conf");

eval "require $config->{Storage}->{Type}";
my $storage = $config->{Storage}->{Type}->new($config->{Storage});


foreach my $arg (@ARGV) {
    my $json = Mojo::JSON->new();
    my $pjson = $json->decode(slurp $arg);

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

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