2013-10-10 18:03:07 +00:00
|
|
|
#!/usr/bin/env perl -w
|
2016-11-22 05:17:34 +00:00
|
|
|
# Copyright 2010-2016 Will Scullin <scullin@scullinsteel.com>
|
2016-12-06 05:16:21 +00:00
|
|
|
#
|
2013-10-10 18:03:07 +00:00
|
|
|
# Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
# documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
# the above copyright notice appear in all copies and that both that
|
|
|
|
# copyright notice and this permission notice appear in supporting
|
|
|
|
# documentation. No representations are made about the suitability of this
|
|
|
|
# software for any purpose. It is provided "as is" without express or
|
|
|
|
# implied warranty.
|
|
|
|
|
|
|
|
use MIME::Base64 qw(encode_base64);
|
|
|
|
use JSON qw(from_json);
|
|
|
|
use Data::Dumper;
|
|
|
|
use Getopt::Std;
|
|
|
|
|
|
|
|
my $disk;
|
|
|
|
my @disks = ();
|
|
|
|
|
|
|
|
my %opts;
|
|
|
|
getopts('pe', \%opts);
|
|
|
|
|
|
|
|
while (<json/disks/*.json>) {
|
|
|
|
my $json;
|
|
|
|
my $fn = $_;
|
|
|
|
print STDERR "$fn\n";
|
|
|
|
open(DISK, $fn) or die $!;
|
|
|
|
while (<DISK>) {
|
|
|
|
my $line = $_;
|
2016-12-06 05:16:21 +00:00
|
|
|
|
2013-10-10 18:03:07 +00:00
|
|
|
$json .= $line;
|
|
|
|
}
|
|
|
|
close(DISK);
|
2016-12-06 05:16:21 +00:00
|
|
|
|
2013-10-10 18:03:07 +00:00
|
|
|
$disk = from_json($json);
|
|
|
|
$disk->{'filename'} = $fn;
|
|
|
|
$disk->{'data'} = NULL;
|
|
|
|
|
|
|
|
push(@disks, $disk);
|
|
|
|
}
|
|
|
|
|
|
|
|
@disks = sort { $a->{'category'} . $a->{'name'} cmp $b->{'category'} . $b->{'name'} } @disks;
|
|
|
|
|
|
|
|
my $first = 1;
|
|
|
|
print "disk_index = [\n";
|
|
|
|
foreach $disk (@disks) {
|
|
|
|
next if $disk->{'private'} && !$opts{'p'};
|
|
|
|
next if $disk->{'2e'} && !$opts{'e'};
|
|
|
|
|
|
|
|
print ",\n" unless ($first);
|
|
|
|
print " {\n";
|
|
|
|
print " \"filename\": \"" . $disk->{'filename'} . "\",\n";
|
|
|
|
print " \"name\": \"" . $disk->{'name'} . "\",\n";
|
|
|
|
if ($disk->{'disk'}) {
|
|
|
|
print " \"disk\": \"" . $disk->{'disk'} . "\",\n";
|
|
|
|
}
|
|
|
|
print " \"category\": \"" . $disk->{'category'} . "\"\n";
|
|
|
|
print " }";
|
|
|
|
$first = 0;
|
|
|
|
}
|
|
|
|
print "\n];\n";
|