CouchDB data can be imported using files which contain full url to CouchDB database
or url to CouchDB view to import. URL's filename should end in *.couchdb
+lsblk .pairs format is basically shell variables in form NAME="value"
+
Start with:
--- /dev/null
+#!/bin/sh -x
+
+cols=`lsblk -h | grep '^ *[A-Z][A-Z][A-Z]*' | sed 's/^ *//' | cut -d" " -f1 | grep -v DISC-ZERO | xargs echo | sed 's/ /,/g'`
+echo $cols
+lsblk --pairs --output $cols > `hostname`.pairs
use MojoFacets::Import::CSV;
use MojoFacets::Import::CouchDB;
use MojoFacets::Import::SQL;
+use MojoFacets::Import::Pairs;
our $loaded;
our $filters;
} elsif ( -d $file && $file =~ m/\.html$/ ) {
$file =~ s/$data_dir\/*//;
push @files, $file;
- } elsif ( -f $file && $file =~ m/\.(csv|storable|couchdb|sql)$/i ) {
+ } elsif ( -f $file && $file =~ m/\.(csv|storable|couchdb|sql|pairs)$/i ) {
$file =~ s/$data_dir\/*//;
push @files, $file;
} else {
$data = MojoFacets::Import::SQL->new( full_path => $full_path )->data;
} elsif ( $full_path =~ m/.couchdb/i ) {
$data = MojoFacets::Import::CouchDB->new( full_path => $full_path )->data;
+ } elsif ( $full_path =~ m/.pairs/i ) {
+ $data = MojoFacets::Import::Pairs->new( full_path => $full_path )->data;
} else {
$data = MojoFacets::Import::File->new( full_path => $full_path, path => $path )->data;
}
--- /dev/null
+package MojoFacets::Import::Pairs;
+
+use warnings;
+use strict;
+
+use base 'Mojo::Base';
+
+use Data::Dump qw(dump);
+
+__PACKAGE__->attr('full_path');
+
+sub data {
+ my $self = shift;
+
+ my $path = $self->full_path;
+
+ my $data = { items => [] };
+ my $need_header = 1;
+
+ open(my $fh, $path) || die "$path: $!";
+ while(<$fh>) {
+ chomp;
+ warn "## $_\n";
+ my @header;
+ my %item = (
+ map {
+ my ($k,$v) = split(/="/,$_,2);
+ push @header, $k if $need_header;
+ ( $k => $v );
+ } split(/"\s/, $_)
+ );
+ push @{ $data->{items} }, \%item;
+
+ if ( $need_header ) {
+ $data->{header} = [ @header ];
+ $need_header = 0;
+ }
+ }
+
+ return $data;
+
+}
+
+1
--- /dev/null
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+use Data::Dump qw(dump);
+
+use lib 'lib';
+
+use_ok('MojoFacets::Import::Pairs');
+
+my $path = $ARGV[0] || (glob 'data/lsblk/*.pairs')[0];
+diag "using $path";
+
+ok( my $o = MojoFacets::Import::Pairs->new( path => $path ), 'new' );
+
+ok( my $data = $o->data, 'data' );
+diag dump($data);